0
votes

I'm using pyglet: http://www.pyglet.org/ to work with opengl. However, i have some problems.

My vanishing point appears in the corner of the screen (0,0) the lower left corner. The following image should show illustrate this: http://i.imgdiode.com/0wu5E0.png

On the left is a cube as i view it now. On the right is how it should (how i want it to) look. How can i make it that way?

Also, I read a bit about matrix modes and it seems as if GL_PROJECTION is supposed to be used with gluPerspective. When i use them together, however, the perspective effect goes away. Only in GL_MODELVIEW will gluPerspective work. I am puzzled as to why this is the case.

The following is the code i use to display the object.

glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluPerspective(60,1,0,10)
2
Looks like you're multiplying a perspective matrix on top of a translation matrix. Make sure you apply gluPerspective only (and only) to the GL_PROJECTION matrix and that you initialized that to identity right before that.datenwolf

2 Answers

4
votes
gluPerspective(60,1,0,10)
                    ^ stop that

zNear must be greater than zero and less than zFar. Try something like 0.1.

Try this sequence instead:

glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(60,1,0.1,10)

glMatrixMode(GL_MODELVIEW)
glLoadIdentity()

# draw stuff
2
votes

The origin (0,0) is based in the lower left corner of the screen. This gives parity between 2D and 3D; pyglet's 2D coordinates start from the bottom-left corner.

To sort this out, you just need to add a translation before your projection matrix:

window = pyglet.window.Window()
glLoadIdentity()
pyglet.graphics.glTranslatef(window.width / 2.0, window.height / 2.0, 0.0)
gluPerspective(60,1,0,10)

This will move the origin point to the centre of the screen (or move the 'camera' to look at the origin point; these are practically identical)