On Mon, Jul 5, 2010 at 9:08 PM, Steven Clark <[email protected]> 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?
>


I'll post the second file in the hopes that someone can see something
obviously wrong with it. Again, it's the same gl calls as in
gfx_test_1.py, but this time the GL_LINE_LOOP isn't visible...:

import pyglet
from pyglet.gl import *


class MyApp(object):
    def __init__(self):
        self.window = pyglet.window.Window(resizable=True)

        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')

        @self.window.event
        def on_resize(width, height):
            self.on_resize(width, height)

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

    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()

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

Reply via email to