Skip to content | Change text size
 

Using GLUT in Linux

GLUT (GL Utility Toolkit) is a 3-D graphics library which uses the OpenGL API.

This is available in Linux teaching labs. GLUT/OpenGL is required for CSE3313. Course related queries should be directed at your teaching staff, rather than IT Services.

The following material is part of the CSE3313 Computer Graphics course.

Sample OpenGL code: simple.c

/*
* simple.c
* This program draws a white rectangle on a black background.
*/

/* modified by Jon McCormack from: */
/* E. Angel, Interactive Computer Graphics */
/* A Top-Down Approach with OpenGL, Third Edition */
/* Addison-Wesley Longman, 2003 */

#include /* glut.h includes gl.h and glu.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]) */

glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("simple");
glutDisplayFunc(display);
init();
glutMainLoop();
}

To compile the sample code in the Linux labs, use the following command (on one line):

$ gcc simple.c -o simple -I/usr/X11R6/include/ -L/usr/X11R6/lib -lX11 -lXi -lXmu -lglut -lGL -lGLU

Why not freeglut ? There is a problem with the freeglut 1.3 packages for Fedora Core 1.

freeglut 2 is available, and is much improved over freeglut 1. As a course requirement, glut will continue to be deployed in the Linux labs.