[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: Re: [pygame] Using PyOpenGL for 2D graphics



Simon Wittber <simonwittber@xxxxxxxxx> wrote:
> If you're after brain dead simple 2D OpenGL functions only, try gfx.gl
> in the GFX package. (http://cheeseshop.python.org/pypi/GFX).

Yep, and pyglet is intended to provide windowing, input, music, sound, video, etc. It has some "extensions" already that are in various states of completion (none of them quite ;) which do "sprite and tilemap" graphics, XHTML layout, GUI, etc. The emphasis is on pure-python implementations (as it is with pyglet itself) so if you could (ie. you can compile or ship binaries for your target platforms) you'd use something like GFX for faster-than-pyglet graphics.

Except, of course, that pyglet's not actually officially released yet ;)

But fundamentally, GFX* is just using a GL context, and pygame and pyglet both provide one of
those.

Quick, untested translation of Simon's example to pyglet:


 1  from pyglet import window, image
 2  from gfx import gl
 3 
 4  w = window.Window(800, 600)
 5  gl.init((800,600))       # I assume this is just setting up a projection :)
 6 
 7  im = image.load('ball.png')
 8  texture_id = im.texture.id
 9  w,h = im.width, im.height
10  while not w.has_exit:
11      w.dispatch_events()
12      gl.draw_quad((0,0),((0,0),(0,h),(w,h),(w,0)), texture_id=texture_id)
13      w.flip()


Note that the gl.draw_quad could be done with "im.blit(0, 0)". A speed comparison
would be interesting :)


      Richard

*: I've also noticed http://cheeseshop.python.org/pypi/Rabbyt which has just popped up recently...