This is the code that sets off Chapter 3:
# Example 3-1 : Transformed Cube
from pyglet.gl import *
from pyglet import window
from OpenGL.GLUT import *
win = window.Window()
def init():
glClearColor (0.0, 0.0, 0.0, 0.0)
glShadeModel (GL_FLAT)
def reshape (w, h):
glViewport (0, 0, w, h)
glMatrixMode (GL_PROJECTION)
glLoadIdentity ()
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0)
glMatrixMode (GL_MODELVIEW)
def display():
glClear (GL_COLOR_BUFFER_BIT)
glColor3f (1.0, 1.0, 1.0)
glLoadIdentity () # clear the matrix
# viewing transformation
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
glScalef (1.0, 2.0, 1.0) # modeling transformation
glutWireCube (1.0)
glFlush ()
init()
win.on_resize = reshape
while not win.has_exit:
win.dispatch_events()
win.clear()
display()
win.flip()
As the GLUT library is not being wrapped in pyglet, we'll have to import it from within OpenGL (get it here). Mind that GLUT are but helper libraries (such as the famous teapot), and the pyglet people have good reasons not to include it in their module.
Also, with what has been learned in chapter 2 of the red book, a WireCube() function shouldn't be too hard to write.
No comments:
Post a Comment