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

Re: [pygame] Re: BOUNCE pygame-users@seul.org: Non-member submission from ["David Keeney" <dkeeney@travelbyroad.net>]



On Jun 24, 2004, at 10:21 AM, Federico Di Gregorio wrote:

Lì giovedì, 2004/06/24 alle 08:06, -0700, Pete Shinners ha scritto:
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?

If you need speed, you need to go the textured quad route.  However,
if you just need to put text on the screen, the following code works for
me:

import OpenGL.GL as ogl

def drawText(position, textString):
    font = pygame.font.Font (None, 64)

    # Sigh.  pygame colors are 0-255 integers
    textSurface = font.render(textString, True,
                              (255, 255, 255, 255),
                              (0, 0, 0, 255))
    textData = pygame.image.tostring(textSurface,
                                     "RGBA", True)
    ogl.glRasterPos3d(*position)
    ogl.glDrawPixels(textSurface.get_width(),
                     textSurface.get_height(),
                     ogl.GL_RGBA, ogl.GL_UNSIGNED_BYTE, textData)

Hope this helps,
-a