Basic GLUT library
Window initialization
- glutInit(int *argc, char **argv)
- glutInitWindowSize(int width, int height)
- glutInitWindowPosition(int x, int y)
- specifies size, position of window to be created by next glutCreateWindow
- glutInitDisplayMode(OR'd bit string args)
- specify display mode: some include...
- GLUT_RGBA, GLUT_INDEX: rgb, color map modes
- GLUT_SINGLE, GLUT_DOUBLE: single, double buffering
- GLUT_DEPTH: depth buffer
- int glutCreateWindow(char *name)
- create window specified by the above
- integer ID for window returned
- glutSetWindow(int), glutGetWindow(int)
- set or get the specified window (via ID number)
Callback registration
- glutDisplayFunc(void (*func)(void))
- assigns function to call when current window must be redisplayed
- glutReshapeFunc(void (*func) (int width, int height))
- function to call when current window is reshaped; the parameters are
the new size of reshaped window
- glutIdleFunc(void (*func)(void))
- function to call when no activity occurring (eg. for animation)
- glutKeyboardFunc(void (*func)(unsigned char key, int x, int y))
- sets key processing routine
- x and y are mouse coordinates when the key 'key' was pressed
- see glutGetModifiers for state of modifier keys (eg. ctrl,...)
- glutMouseFunc(void (*func)(int button, int state, int x, int y))
- mouse function callback
- button: GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_RIGHT_BUTTON
- state: GLUT_UP, GLUT_DOWN
- x, y: mouse coordinates
- glutMotionFunc (void (*func)(int x, int y))
- function to call when mouse is moving in window, when a button is pressed
- glutPassiveMotionFunc(void (*func)(int x, int y))
- function to call when mouse is moving in window, when no buttons
are pressed
- glutMainLoop(void)
- starts GLUT processing; should be called only once in program
Colour Map Management
- glutSetColor(int index, GLfloat red, GLfloat green, GLfloat blue)
- set index to specified colour
- GLfloat glutGetColor(int index, int component)
- gets colour in index, specified by component GLUT_RED, GLUT_GREEN,
GLUT_BLUE
Misc
- glutGet(GLenum state)
- gets a particular GLUT state value
- eg. GLUT_WINDOW_WIDTH, GLUT_WINDOW_BUFFER_SIZE, etc
- glutPostRedisplay(void)
- marks current window as needing redisplay by glutDisplayFunc
- glutSwapBuffers(void)
- Swaps buffers when doing double buffering during animation
Examples
Basic examples.
Advanced examples (local access only)
Online GLUT manual
Glut manual (PDF)
Short Glut article : see how to make multiple windows, menus, etc.
Back
to COSC 3P98 index
COSC 3P98 Computer Graphics
Brock University
Dept of Computer Science
Copyright © 2021 Brian J. Ross
http://www.cosc.brocku.ca/Offerings/3P98/course/lectures/OpenGL/glut_ref.html
Last updated: January 19, 2021