[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] PyGame 2D text in OpenGL?
I'm trying to write some 2D text onto the screen using an OpenGL pygame
display. I'm having issues with the texture/raster not updating if the text
is changed. It will draw one correct image, and then not update it
afterwards, however I know the functinos are being updated. This is the
code I'm trying to make work, I've tried rastering(this code) and texturing
to a quad, neither was updating correctly. Any help would be appreciated.
def test(self):
textureSurface = pygame.Surface((512,512))
x,y = pygame.mouse.get_rel()
title_font = pygame.font.Font(None, 25)
mouseText = "MousePos x: %s, y: %s" %(x,y)
print mouseText
text2 = title_font.render(mouseText, 1, (250,250,250))
textureSurface.blit(text2, (200,70))
textureSurface = textureSurface.convert()
#textureData = pygame.image.tostring(textureSurface, "RGBA", 1)
#size = textureSurface.get_size()
#glRasterPos3f(-.2,-.2,-1)
#glDrawPixels(size[0], size[1], GL_RGBA, GL_UNSIGNED_BYTE,
textureData)
textureData = pygame.image.tostring(text2, "RGBA", 1)
size = text2.get_size()
glRasterPos3f(-.2,-.2,-1)
glDrawPixels(size[0], size[1], GL_RGBA, GL_UNSIGNED_BYTE,
textureData)