[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Re: BOUNCE pygame-users@seul.org: Non-member submissionfrom ["David Keeney" <dkeeney@travelbyroad.net>]
Pete Shinners wrote:
I am looking at converting some code from GLUT to PyGame. Does the
font functionality work in OpenGL display mode, or is there a
workaround way to display text to an OpenGL display using PyGame?
The code in question uses GLUT raster text, and would need an
alternate method of displaying text.
David, Pygame itself has nothing for fonts in opengl. The only direct
solution I can think of is to render the text, convert it to a
texture, and have opengl draw it with a textured quad.
But that can be a bit awkward, especially with the "square, powers of
2" size restrictions.
It sounds like several opengl projects are starting to take off, has
anyone found a reasonable text solution?
I don't know if people will consider it "reasonable", but
OpenGLContext's scenegraph includes TrueType font rendering using
TTFQuery & FontTools to load arbitrary .ttf fonts and render them as 3D
geometry (including extrusion). It also supports/demos use of Win32,
wxPython, PyGame and GLUT bitmap fonts (with varying degrees of success
(mostly because some of the APIs (GLUT and Win32) aren't great at giving
back metadata on font sizes and the like, which often isn't a concern
for games where you're only using one font and can hard-code everything,
but is when you're trying to do VRML-style text nodes)).
I'm not doing the more traditional
render-to-bitmap-and-use-texture-coordinates-on-geometry approach, by
the way, just simple bitmap generation and display (which is
comparatively slow, but makes the code easier to follow for beginning
programmers IMO).
Caveat renderer, 3D glyphs are always *slow*.
Finally, just as a note, you'll notice the inclusion of GLUT in the list
of demoed methods? GLUT raster fonts work perfectly well (or should, at
least) in a PyGame rendering context. If all you want to do is
duplicate code that uses them, using them should work fine.
Have fun,
Mike
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
blog: http://zope.vex.net/~mcfletch/plumbing/