pythonopenglpyglet

Pyglet 2d Camera OpenGL


It is not much information out there how to do a 2d camera in Pyglet. I assume its not a good idea to move all sprites so I look for something similar to a Surface in Pygame that I could move instead. But the is no such thing in Pyglet? Is this the way it should be done in openGl? or am I missing something important? I don't know what the gl command do but it is working.

def on_draw(self):
    #camera start

    glMatrixMode(gl.GL_PROJECTION)
    glLoadIdentity()
    glOrtho(self.camera.x, self.camera.x2, self.camera.y, self.camera.y2, -1, 1)

    #camera end
    self.clear()
    self.batch.draw()# draw stuff

Solution

  • There is a camera example in the pyglet/examples folder: https://github.com/pyglet/pyglet/blob/pyglet-1.5-maintenance/examples/window/camera.py

    EDIT: 2.0 was released and requires a slight change to camera. See the master branch instead: https://github.com/pyglet/pyglet/blob/master/examples/window/camera.py