Hi Steven,

You're pushing the hanlders in a wrong way, here's your class modified to work as expected (see attach) you can read more about using the event handlers at http://www.pyglet.org/doc/programming_guide/the_pyglet_event_framework.html

basically you are doing this in the __init__

@self.window.event
def on_draw():
    self.on_draw()

while you should be doing:

self.window.push_handlers(self.on_draw)

Regards,
Alex Verstraeten

On 7/5/2010 10:08 PM, Steven Clark wrote:
Hi all-

I'm scratching my head over this one.
I have a working pyglet script that was written in a
non-object-oriented fashion (gfx_test_1.py).
I then attempted to "object-orientify" this script by converting it
into a class (gfx_test_2.py).

Both files should be rendering a square using a 3d perspective
projection and then placing some text over top of the screen using a
2d ortho projection.
 From the first script, I see the expected output. From the second
script, I see the text but not the 3d square underneath.

Any idea why? Is my use of decorators in second file incorrect?

Please take a look, the files are pretty short.

-Steven

PS: should my on_draw event return pyglet.event.EVENT_HANDLED (like
on_resize), or no?


--
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.

import pyglet
from pyglet.gl import *


class MyApp(object):
    def __init__(self):
        self.window = pyglet.window.Window(resizable=True)
        self.window.push_handlers(self.on_resize)
        self.window.push_handlers(self.on_draw)
        
        self.label = pyglet.text.Label('Centered Text',
                                        font_name='Times New Roman',
                                        font_size=12,
                                        x=self.window.width/2, 
y=self.window.height/2,
                                        anchor_x='center', anchor_y='center')

    def on_resize(self, width, height):
        glViewport(0, 0, width, height)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(60.0, width / float(height), .1, 1000.0)
        glMatrixMode(GL_MODELVIEW)
        return pyglet.event.EVENT_HANDLED
    
    def on_draw(self):
        self.draw_world()
        
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        glOrtho(0, self.window.width, 0, self.window.height, -1, 1)
        glMatrixMode(GL_MODELVIEW)
        
        self.draw_overlay()
        
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        
        return pyglet.event.EVENT_HANDLED
        
        
    def draw_world(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        
        gluLookAt(1.0, 2.0, 3.0,
                    0.0, 0.0, 0.0,
                    0.0, 0.0, 1.0)
                    
        glBegin(GL_LINE_LOOP)
        glVertex3f(0,0,0)
        glVertex3f(0,1,0)
        glVertex3f(1,1,0)
        glVertex3f(1,0,0)
        glEnd()
        
    
    def draw_overlay(self):
        glLoadIdentity()
        self.label.draw()
        
    def run(self):
        pyglet.app.run()


app = MyApp()
app.run()

Reply via email to