I am trying to mix 2d and 3d in opengl in pyglet, i.e. draw a 3d scene, then switch to the spelling projection and draw the material on top. I draw 3D material, click the projection matrix onto the stack, make the glOrtho projection matrix, draw a 2d material, then pull the previous matrix from the stack. The 3D material is perfectly drawn, but for some reason, part 2d does not draw at all, even by itself. Here is the code:
class Window(pyglet.window.Window):
width, height = 1024, 786
def __init__(self, width, height):
super(Window, self).__init__(width, height)
self.set_caption("OpenGL Doss")
pyglet.clock.schedule_interval(self.update, 1 / 30.0)
glEnable(GL_TEXTURE_2D)
glShadeModel(GL_SMOOTH)
glClearColor(0.0, 0.0, 0.0, 0.0)
glClearDepth(1.0)
glDepthFunc(GL_LEQUAL)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
self.world = World()
self.label = pyglet.text.Label('Hello, world',
font_name='Times New Roman',
font_size=20,
width=10, height=10)
def on_resize(self, width, height):
print 'on resize'
if height == 0:
height = 1
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45, 1.0 * width / height, 0.1, 100.0)
def on_draw(self):
self.set3d()
self.world.draw()
self.set2d()
self.draw2d()
self.unSet2d()
def update(self, dt):
"called at set interval during runtime"
maze_platform = self.world.maze_platform
pacman = maze_platform.maze.pacman
maze_platform.update()
pacman.update(self.world)
def on_key_press(self, symbol, modifiers):
control.press(symbol, modifiers)
def on_key_release(self, symbol, modifiers):
control.release(symbol, modifiers)
def set3d(self):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glEnable(GL_DEPTH_TEST)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
def set2d(self):
glDisable(GL_DEPTH_TEST)
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
far = 8192
glOrtho(-self.width / 2., self.width / 2., -self.height / 2., self.height / 2., 0, far)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
def unSet2d(self):
glMatrixMode(GL_PROJECTION)
glPopMatrix()
def draw2d(self):
z=-6
n=100
glTranslatef(0, 0.0, -z)
glBegin(GL_TRIANGLES)
glVertex3f(0.0, n, 0.0)
glVertex3f(-n, -n, 0)
glVertex3f(n, -n, 0)
glEnd()
def main():
window = Window(Window.width, Window.height)
pyglet.app.run()
print 'framerate:', pyglet.clock.get_fps(), '(error checking = %s)' % pyglet.options['debug_gl']
if __name__ == '__main__': main()