CPEN 461/661, Spring 1997 |
OpenGL Tutorial |
A typical program that uses OpenGL begins with calls to open a window into the frame buffer into which the program will draw. Then, calls are made to allocate a GL context and associate it with the window. Once a GL context is allocated, the programmer is free to issue OpenGL commands. Some calls are used to draw simple geometric objects (i.e. points, line segments, and polygons), while others affect the rendering of these primitives including how they are lit or colored and how they are mapped from the user's two- or three-dimensional model space to the two-dimensional screen. There are also calls to effect direct control of the frame buffer, such as reading and writing pixels.
main:find GL visual and create window
initialize GL states (e.g. viewing, color, lighting)
initialize display lists
loop
check for events (and process them)
if window event (window moved, exposed, etc.)
modify viewport, if needed
redraw
else if mouse or keyboard
do something, e.g., change states and redraw
redraw:
clear screen (to background color)
change state(s), if needed
render some graphics
change more states
render some more graphics
.
.
.
swap buffers