Both are passed to graphics hardware via function calls
To draw something, the necessary state attributes (e.g. color) are set first
Then, the geometry (e.g. triangle data) is passed
State is retained until changed
State changes do not affect any geometry already drawn
glColor3f(1, 1, 0) # Set current color glBegin(GL_TRIANGLES) glVertex2f(0.0, 0.0) # This triangle is yellow glVertex2f(0.4, 0.0) glVertex2f(0.8, 0.8) glColor3f(1, 0, 1) # Change current color glVertex2f(0.0, 0.0) # This triangle is magenta glVertex2f(-0.4, 0.0) glVertex2f(-0.8, -0.8) glEnd()
Illusion of motion produced by rapidly displaying still frames that change
Traditional animation often works at 12 frames per second.
Below ~ 10 fps, animation looks like a slide show, rather than motion
def update(v):
glutTimerFunc(16, update, 0) # Schedule a new call in 16 ms,
# yielding 60 fps
newposition = moveObject()
# etc.
glutPostRedisplay()
glutTimerFunc(0, update, 0) # Schedule the first "update" call
Like an image, but for each pixel there can be additional data besides color - depth, masking, etc.
OpenGL renders shapes, images, etc. into pixels of the frame buffer. rasterizing it - converting it into raster form in the frame buffer.
The previously completed image is displayed while the new one is drawn.
The frame buffer is split into two buffers - front buffer (displayed) and back buffer (drawn into).
Useful for smooth animation.
Pass GLUT_DOUBLE flag to glutInitDisplayMode, instead of GLUT_SINGLE
Call glutSwapBuffers() at end of frame (replaces glFlush())
def draw():
glClear(GL_COLOR_BUFFER_BIT)
...
glutSwapBuffers()
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
If you have time, enhance it - add multiple triangles, allow the user to
change the speed by hitting keys, etc.
