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

Re: [pygame] PyGame / PyOpenGL Example



On Tue, 12 Feb 2008 23:23:49 +1030, fragged <my.old.email.sucked@xxxxxxxxx>
wrote:
> Hey guys,
> 
> I've been searching for some decent examples of PyOpenGL to help me port
> my current application to OpenGL to speed things up on my perty new
> 1920x1200 LCD (Getting about 20fps, using no acceleration whatsoever),
> however I've been unable to find any decent guides on the net that
> simply show me how to do the equivalent of loading an image and some
> text - the small fragments I have found have still been using PyGame to
> render text and this seems to break on my gentoo system whilist working
> on another and I'm not really sure if this is the /propper/ way to do it.
> 
> would somebody have one of these laying about, know of one or be able to
> hack one up for me? It'd be a great help and I'd also love to see it go
> in the examples directory on PyGame.org as there seems to be very few
> extreme beguinners guides.


Hey.

I'll look again at my old code later, but for now: Loading images and
displaying those and text is a royal pain in OpenGL, even in Python. For
images you basically need to load a texture and convert it, and I think
there's a restriction on the size or proportion of textures. Drawing stuff
in 2D, as for a GUI, involves switching to an "ortho" mode and either
manually drawing shaded rectangles, or drawing rectangles textured with a
pre-loaded texture. Drawing the text can be done in several ways:
finding/creating a bitmap of a font, or making a bunch of textures out of
an image, or using a stand-alone module like PyGlyph (with which I've had
some success). It's easier to draw a spinning translucent textured cube in
OpenGL than to write "Hello World!" The "ortho" switch is not that hard, at
least; I've got code for that. After much fiddling every so often, I've
been reverting to 2D. Still, I'd like to get a simple 3D landscape with a
sky and "billboarded" sprites, plus the ability to use my GUI with it.

For the moment, try looking up the "NeHe OpenGL" tutorials, the first few
of which are available in Python. (The key parts are pretty much the same
in any language too.) Also look up the "OpenGL RedBook," a version of which
is available free online. I think I put the crude OpenGL code I was using
into the ZIP at <http://kschnee.xepher.net/code/070801cubeland.zip>, so you
might look at that for ideas.

A(nother) good basic demo of images and text would be great, yeah.

Kris