Hi everyone,
Kudos to the Pyglet developers and contributors. The ability to handle
opengl and different types of media with minimum external dependencies
is great. I programmed a little 3D opengl test for the alpha 1.0
version. One problem I've run into with the alpha 2.0 (as well as the
just release beta 1.0) is that I cannot see 3d cube spinning. Any
advice how to make the code run with the new releases?
Regards,
Ruben
opengl3d.py code:
#!/usr/bin/env python
'''
Displays a rotating cube using OpenGL.
Ruben E. Perez, 2007
[EMAIL PROTECTED]
'''
from pyglet.gl import *
from pyglet import clock
from pyglet import window
#import ctypes
def setup():
#def on_resize(width, height):
#
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(60., 1., 1., 100.)
#gluPerspective(65,width/float(height),1,100)
glMatrixMode(GL_MODELVIEW)
# Background Color
glClearColor(1, 1, 1, 1) # White
#glClearColor(0, 0, 0, 0) # Black
def draw():
# Draw Window Contents
#----------------------------------
# Clear Window And Depth Buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
#
glLoadIdentity()
# Translate
glTranslatef(0.0,0.0,-7.0)
# Rotation
glRotatef(r, 1, 0, 0) # x_ang
glRotatef(r, 0, 1, 0) # y_ang
glRotatef(r, 0, 0, 1) # z_ang
# Cube Coordinates
glBegin(GL_QUADS) # Draw The Cube Using quads
glColor3f(0.0,1.0,0.0) # Color Green
glVertex3f( 1.0, 1.0,-1.0)
glVertex3f(-1.0, 1.0,-1.0)
glVertex3f(-1.0, 1.0, 1.0)
glVertex3f( 1.0, 1.0, 1.0)
glColor3f(1.0,0.5,0.0)
glVertex3f( 1.0,-1.0, 1.0)
glVertex3f(-1.0,-1.0, 1.0)
glVertex3f(-1.0,-1.0,-1.0)
glVertex3f( 1.0,-1.0,-1.0)
glColor3f(1.0,0.0,0.0) # Color Red
glVertex3f( 1.0, 1.0, 1.0)
glVertex3f(-1.0, 1.0, 1.0)
glVertex3f(-1.0,-1.0, 1.0)
glVertex3f( 1.0,-1.0, 1.0)
glColor3f(1.0,1.0,0.0)
glVertex3f( 1.0,-1.0,-1.0)
glVertex3f(-1.0,-1.0,-1.0)
glVertex3f(-1.0, 1.0,-1.0)
glVertex3f( 1.0, 1.0,-1.0)
glColor3f(0.0,0.0,1.0) # Color Blue
glVertex3f(-1.0, 1.0, 1.0)
glVertex3f(-1.0, 1.0,-1.0)
glVertex3f(-1.0,-1.0,-1.0)
glVertex3f(-1.0,-1.0, 1.0)
glColor3f(1.0,0.0,1.0)
glVertex3f( 1.0, 1.0,-1.0)
glVertex3f( 1.0, 1.0, 1.0)
glVertex3f( 1.0,-1.0, 1.0)
glVertex3f( 1.0,-1.0,-1.0)
glEnd() # End Drawing The Cube
# Window Constructors
w1 = window.Window(200, 200, caption='First window', resizable=False)
w1.switch_to()
setup()
w2 = window.Window(300, 300, caption='Second window', resizable=True)
w2.switch_to()
setup()
#
r = 0
clock.set_fps_limit(30)
while not (w1.has_exit or w2.has_exit):
dt = clock.tick()
r += dt*90
if (r > 360):
r = 0
w1.switch_to() # Switch to First Window
w1.dispatch_events() # Update Window Events
draw() # Draw Window Contents
w1.flip() # Perform OpenGL drawing
operations
w2.switch_to() # Switch to First Window
w2.dispatch_events() # Update Window Events
draw() # Draw Window Contents
w2.flip() # Perform OpenGL drawing
operations
#end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---