Help Wanted

Python, Pygame and Pyopengl text-need help – PFC

PFC

Member

Posts: 29
From: Canada
Registered: 10-16-2007
well... so far I've been able to build an mmorpg game engine (3D) using python, Pygame(SDL) and PyOpenGL(OpenGL)... and it worked... only one little problem... I can't seem to figure out how to display text on the screen...
I have been researching how to use multiple layers in pygame, but I can't seem to get it to work and I don't want to render 3d text in GL.

does anyone know how to use multiple layers with an alpha colour set so that I can place text on top of the OpenGL rendered graphics?
also does anyone know if it is possible to only let OpenGL render to a part of the screen and use the other parts from another layer? (like a sub-window rendered in GL and other sub-windows using pygame)

Note: I can't use screen.blit(source,rect) since an OpenGL enabled screen can't be blited... instead I use pygame.display.flip()

here is the basic code I use:
---------------------------
import OpenGL, pygame
from pygame.locals import * # used for variables
from pygame.display import flip # put the GL buffer to screen
from OpenGL.GL import *
from OpenGL.GLU import *

pygame.init() # init pygame

win_size =(640,480)
flags=OPENGL|DOUBLEBUF
screen = pygame.display.set_mode(win_size, flags) # set up for OpenGL

glEnable(GL_DEPTH_TEST) #GL related functions, nothing to do with pygame
glMatrixMode(GL_PROJECTION)
gluPerspective(45.0,float(win_size[0])/win_size[1],0.1,100.0)
glClearColor(1.0,0.0,0.0,0.0) # set background as red

while 1: #THE FOLLOWING MUST BE INDENTED,THE BOARD DOEST SHOW SPACES
pygame.event.poll() # clear the input buffer, stops it from overloading
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) # set buffer to red
flip() # switch buffers... or blit buffer to screen
---------------------------

------------------
Heart of a Warrior

[This message has been edited by PFC (edited October 23, 2007).]

CPUFreak91

Member

Posts: 2337
From:
Registered: 02-01-2005
quote:
Originally posted by PFC:
I have been researching how to use multiple layers in pygame, but I can't seem to get it to work and I don't want to render 3d text in GL.


As far as I know, Pygame doesn't support layers. You have to blit items on top of each other with no special layer properties (you could create "layers" with some functions). To set something with an alpha you might want to use surfarray: http://www.pygame.org/docs/ref/surfarray.html

I haven't played with surfarray myself so I don't know how well it works with text.

PS> You can use tabs and spaces in your code by putting your source code in

[ code ] [ / code ] UBB code tags (remove spaces)

def foo(bar):
print bar
foo()
#As you can see, spaces are not removed

------------------
All Your Base Are Belong To Us!!! chown -r us ./base
"After three days without programming, life becomes meaningless.'' -- Tao of Programming Book 2

"Oh, bother," said the Borg. "We've assimilated Pooh."

Any fool can know, the point is to understand. -- Albert Einstein

My Programming and Hacker/Geek related Blog

PFC

Member

Posts: 29
From: Canada
Registered: 10-16-2007
Update
thanks for the hint about posting code
I can't use the layers in pygame since I can't blit the screen when in OpenGL mode and the SDL OpenGLBlit doesn't work...(so therefor pygame can't do it)

I got text semi-working in PyOpenGL and PyGame.....

turns out that there is no documentation for this and that the only way to draw text on the screen is to render an image from text and then place this image as texture on an object in OpenGL

if anyone wants the code, just ask

------------------
Heart of a Warrior

[This message has been edited by PFC (edited October 24, 2007).]