GLUT

The OpenGL Utility Toolkit (GLUT) handles most of the system dependent actions required to display a window, put OpenGL graphics in it, and accept mouse and keyboard input. It is used to create the skeleton for all the assignments that hides Windows programming issues from you so you can concentrate on programming graphics.

The GLUT web site

...has links to the GLUT documentation and more information than you'll ever need about it. The documentation is good and reasonably understandable. Reading the first few pages of it will give you a good picture of how GLUT works.

Installing GLUT on your home workstation

To install GLUT on your home workstation, refer to http://www.students.uwosh.edu/%7Ebradfj23/visualstudio/. Use the file locations in Step 1 except note that the header file is glut.h, not glut32.h as listed in the table.

Header (.h) files

#include <GL/glut.h>

glut.h includes gl.h and glu.h, so they shouldn't be included in your source file if glut.h is included.

There is an incompatibility between glut.h and Visual Studio .NET. that results in compile errors:

error C2381: 'exit' : redefinition; __declspec(noreturn) differs
error C3861: 'exit': identifier not found, even with argument-dependent lookup

To fix the error, right click on the project name in the Solution Explorer tab and select Properties -> C/C++ -> Preprocessor -> Preprocessor definitions and append GLUT_BUILDING_LIB to the existing definitions, seperated by semicolons. 

Library files

GLUT has only one link library:

It must be included as an additional dependency in a project that uses GLUT. To do this, right click on the project name in the Solution Explorer tab and select Properties -> Linker -> Input -> Additional Dependencies and enter the library file name, separating by spaces from other library names (like opengl32 and glu32). The symptom of not doing this is unresolved external errors referring to GLUT functions. See Link errors.

Programming paradigms

Callbacks: Programming with GLUT is event driven rather than procedural. This is different from the "main() runs, do your processing, then exit" style you may be accustomed to. In a GLUT program you call a bunch of initialization functions that set your window characteristics and register your callback functions, then call a GLUT function that starts an "infinite loop". When events like keystrokes, mouse clicks, mouse movements, or window size changes occur, the loop calls the appropriate callback functions you registered. These callback functions are equivalent to event handlers in Java and C#. Some callback function, usually the Q or X key handler, eventually calls the standard library exit() function to terminate the loop and end the program.

GLUT in the homework: The skeleton code supplied with each homework assignment is a complete GLUT application. The assignment typically requires you to fill in a callback named "display()" or one or more functions called by it.

Errors: GLUT is not particularly good at trapping or indicating runtime errors. If your pogrom crashes inexplicably during a GLUT call, some initialization was probably not done properly in an earlier GLUT call.

  Tip: Use glutSetWindowTitle() to display text in the window title. This is a convenient way to show useful status information like "Green triangle rotated 90 degrees", or the current scene file name, or the current number of curve subdivisions without cluttering up your drawing window. You can create any text you want with sprintf().

  Tip: You can easily add custom key event processing code to the supplied keyboard callback function to change the value of some program variable at runtime. This could be useful for debugging or avoiding having to rebuild frequently when trying things out.