13.016 Introduction to Geometric Modeling and Computation
OpenGL Graphics Library Utility Toolkit (GLUT)
Use of the GLUT library is best illustrated by a short example:
#include <GL/gl.h> /* OpenGL library */
#include <GL/glu.h> /* OpenGL utility library */
#include "glut.h" /* GLUT library */
/**************************************************************
* Main program - Open window with initial window size, title
* bar, RGBA display mode, and handle input events.
*************************************************************/
void main(int argc, char **argv)
{
glutInit(&argc, argv); /* Initialize GLUT */
glutInitDisplayMode(GLUT_RGB); /* Set RGB (not indexed) color mode */
glutCreateWindow("OpenGL Example 2 - Star"); /* Create window */
glutReshapeFunc(reshapeCB); /* Register reshape callback */
glutDisplayFunc(displayCB); /* Register display callback */
glutMainLoop(); /* Enter the event loop */
}
/***************************************************************
* This callback function is automatically called whenever
* the window changes shape.
**************************************************************/
void reshapeCB(int width, int height)
{
glViewport(0, 0, width, height); /* set viewport to fill window */
}
/***************************************************************
* This callback function is automatically called whenever
* the window needs to be redrawn.
**************************************************************/
void displayCB(void)
{
...
}
On to the rest of the example...
Back to window system interaction...
Back to the overview...