17th
OpenGL programming on Ubuntu (8.10 Intrepid)
Installing all dependencies
sudo aptitude install mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev libglut3-dev
Mesa is an open-source implementation of the OpenGL spec.
NOTE: freeglut3-dev is only required if you wish to use GLUT for your creating your hosting windows and handling user input.
NOTE: (If you wish to use apt-get instead of aptitude, you will also need to specify freeglut3)
Compiling a simple OpenGL/GLUT test
Mesa uses pkg-config, but if you run pkg-config (pkg-config --cflags --libs gl), you’ll notice that it’s not really worth using as all it outputs is -lGL! So for probably for the first time ever; I have chosen to manually specify the build libraries in our compilation command:
gcc -o bin/program main.c -lGL -lGLU -lglut
Then you can create a file named main.c and use the following test program (obtained from the OpenGL redbook):
#include <GL/gl.h>
#include <GL/glut.h>
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd();
glFlush ();
}
void init (void)
{
glClearColor (0.0, 0.0, 0.0, 1.0); // note this line is incorrect in the red-book
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow ("hello");
init ();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}