I have been playing with some opengl examples from the graphics bible Computer graphics Principles and Practice
. The first step is getting hello world to work.
Hello World Link to heading
This example shows polygon by defining 4 points.
#include <GL/glut.h>
void displayMe(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.5, 0.0, 0.0);
glVertex3f(0.5, 0.5, 0.0);
glVertex3f(0.0, 0.5, 0.0);
glEnd();
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(300, 300);
glutInitWindowPosition(100, 100);
glutCreateWindow("Hello world");
glutDisplayFunc(displayMe);
glutMainLoop();
return 0;
}
The generated graphics would be
To compile opengl application, libGL and libglut are linked. libraries are installed by installing libopengl-dev
and freeglut3
g++ main.cpp -lglut -lGL