Run opengl on Linux

I am working on redhat 9.1. But, I don’t know how to add opengl file on linux.

Originally posted by Iqbal_Hossain:
I am working on redhat 9.1. But, I don’t know how to add opengl file on linux.
Include the files <GL/gl.h>, <GL/glu.h> as usual and link with -lGL and (if you need GLU) -lGLU

if you only want to run an opengl prog, you just need the libraries. to test if the libs are properly installed, try to run glxgears (hopefully installed on your system).

if glxgears doesn’t work, try

ldd /usr/X11R6/bin/glxgears

ldd shows you which libraries you need to run a program.

if you want to develop, you additionally need the header files (gl.h, glx.h, glu.h).

if you have an nvidia card, go to and download the latest linux driver. you’ll find the header files in


when you’ve installed the driver.

an alternative is using MESA, which is a non-accelerated software GL lib. it should be included in your redhat distribution.

is there a hello world example for opengl? i’m an experienced program just wanting to fool with it for fun. thnx

there you are…


Display			*dpy 	= XOpenDisplay(NULL);
Window			root 	= DefaultRootWindow(dpy);
GLint                   att[] 	= {GLX_RGBA, None};
XVisualInfo             *vi   	= glXChooseVisual(dpy, 0, att);
GLXContext              glc   	= glXCreateContext(dpy, vi, NULL, False);
Visual                  *vis  	= DefaultVisual(dpy, 0);
Colormap                cmap  	= XCreateColormap(dpy, root, vis, AllocNone);
unsigned int		w 	= XDisplayWidth(dpy, 0) / 2;
unsigned int		h 	= XDisplayHeight(dpy, 0) / 2;
int                     dep   	= DefaultDepth(dpy, 0);
int                     cmask 	= CWColormap | CWBorderPixel | CWEventMask;
int                     emask 	= ExposureMask;
XEvent			xev;
XSetWindowAttributes	swa;
XWindowAttributes	gwa;
Window			win;

int main(int argc, char *argv[]){

 swa.colormap     	= cmap;
 swa.border_pixel 	= 0;
 swa.event_mask   	= emask;
 win              	= XCreateWindow(dpy, root, 0, 0, 400, 400, 0, dep, InputOutput, vis, cmask, &swa);
 XStoreName(dpy, win, "SIMPLE GL QUAD");
 XMapWindow(dpy, win);

 glXMakeCurrent(dpy, win, glc);
 glClearColor(0.00, 0.00, 0.60, 1.00);

 glOrtho(-1., 1., -1., 1., 1., 100.);

 gluLookAt(0., 0., 10., 0., 0., 0., 0., 1., 0.);

 while(1) {
	XNextEvent(dpy, &xev);
	if(xev.type == Expose) {

		XGetWindowAttributes(dpy, win, &gwa);
		w = gwa.width;
		h = gwa.height;

 		glViewport(0, 0, w, h);

		 glColor3f(1., 0., 0.); glVertex3f(-.75, -.75, 0.);
		 glColor3f(0., 1., 0.); glVertex3f( .75, -.75, 0.);
		 glColor3f(0., 0., 1.); glVertex3f( .75,  .75, 0.);
		 glColor3f(1., 1., 0.); glVertex3f(-.75,  .75, 0.);

		glFlush(); } } }
// gcc -I/usr/X11R6/include/ -L/usr/X11R6/lib -o SimpleQuad -lX11 -lGL -lGLU

The example RigidBody gave doesn’t say ‘hello world’ but that’s it :wink:

Also you can test GLUT to avoid direct interaction with X.

To use glut,


-lgut when linking.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.