Install OpenGL headers in Linux and compile your source files
Konstantinos Egkarchos / October 30, 2010
Particularly in Ubuntu, to be accurate. I’ve spent my whole morning trying to find a way, and I’ve found a lot of nonsense. So here it is. Open Synaptic Package Manager, search for glut, or freeglut, and install the “-dev” version. As simple as that….
Yes, you are ready. Your header files (the one you installed right now, such us stdio.h, or iostream.h, etc.) can be found insinde /usr/include/GL.
You may encounter and another problem during the compile process. Assume you have the following source file as simple.c .
#include <GL/freeglut.h>
void display(void)
{
/* clear window */
glClear(GL_COLOR_BUFFER_BIT);
/* draw unit square polygon */
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
/* flush GL buffers */
glFlush();
}
void init()
{
/* set clear color to black */
/* glClearColor (0.0, 0.0, 0.0, 0.0); */
/* set fill color to white */
/* glColor3f(1.0, 1.0, 1.0); */
/* set up standard orthogonal view with clipping */
/* box as cube of side 2 centered at origin */
/* This is default view and these statement could be removed */
/* glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); */
}
int main(int argc, char** argv)
{
/* Initialize mode and open a window in upper left corner of screen */
/* Window title is name of program (arg[0]) */
/* You must call glutInit before any other OpenGL/GLUT calls */
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("simple");
glutDisplayFunc(display);
init();
glutMainLoop();
}
if you try to ‘gcc simple.c’ errors such as ‘undefined reference’ will pop up. That is because the compiler doesn’t know where to find your library files (yeah, its a bit messy. I have no idea either why this is happening but i found the solution). To link it correctly you will have to manually tell gcc or g++ the name of you library files and this can happen by adding -l and your library file. for example
gcc simple.c -lGL -lGLU -lglut