On 29 March 2010 18:12, George Oliver <[email protected]> wrote:
> Commenting out the resize() and the assignment to window.on_resize shows the
> image as expected, but including the resize gives me a blank window. I've
> modified the gluPerspective slightly from the example I took it from, where
> they had:
>
> gluPerspective(45, 1.0*width/height, .1, 100.0)
>
> I changed 0.1 to -1, guessing maybe that pyglet was drawing the batch at
> z=0? But obviously that doesn't help (nor does keeping it at 0.1 I should
> add).
-1 is an invalid near clip plane for a perspective projection. (You
can't look at something that's in or behind your eye.)
> The nehe example I looked at gives me hope, as it clearly shows the 2D
> texture first in a straight-on view (i.e. like a regular 2D ortho
> projection) but then 'tilting' in perspective when the code rotates the
> cube, though maybe I'm misunderstanding that?
I've changed your script a little so that it shows something on the screen.
Changes:
- Position the sprite at (0, 0) instead of (100, 100).
- Translate 1000 units into the screen before drawing the batch.
- Change the near and far clip planes to to 0.1 and 10000.
The changed script:
import pyglet
from pyglet.gl import *
def resize(width, height):
if height==0:
height=1
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45, 1.0*width/height, 0.1, 10000)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
window = pyglet.window.Window(640, 480)
window.on_resize=resize
batch = pyglet.graphics.Batch()
image = pyglet.image.load('crate.bmp')
crate = pyglet.sprite.Sprite(image, 0, 0, batch=batch)
@window.event
def on_draw():
window.clear()
glPushMatrix()
glTranslatef(0, 0, -1000)
batch.draw()
glPopMatrix()
if __name__ == '__main__':
pyglet.app.run()
--
Mikael Lind
http://elemel.se/
--
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.