PDA

View Full Version : Transferring textures to GLUT Game Mode?



Matthew4693434
03-15-2010, 09:57 AM
I have a game which does a lot of rendering to textures, highly nested in one another. I can't reload and re-render everything after entering the game mode. It's just stupid.

I need to transfer the textures with all the rendering made onto them (Done by FBOs).

How is it done if it can be done?

Thank you.

ZbuffeR
03-15-2010, 10:01 AM
What about :
http://www.opengl.org/sdk/docs/man/xhtml/glGetTexImage.xml

Matthew4693434
03-15-2010, 10:21 AM
I've tried that already (This is python):

if self.enter_fullscreen or self.exit_fullscreen:
for surface in Surface.texture_ready:
if surface.texture != None:
glBindTexture(GL_TEXTURE_2D, surface.texture)
glGetTexImage(GL_TEXTURE_2D,0,GL_RGBA,GL_UNSIGNED_ BYTE,surface.data)
surface.texture = None
Surface.texture_ready = []

"Surface" objects with textures that have been made are put into the texture_ready list and when it switches screen modes the program is supposed to loop through that list and copy the texture data to the object's data attribute, which stores pixel data before textures are rendered (Else used for loading images and things like that.). When surface.texture is None, when the data needs to be rendered to anything, the texture will then be created from the data attribute. The texture attribute then carries the texture ID.

I've tested and found out that these "Surface" objects are being processed after if surface.texture != None: That is the problem. I suppose the way they are being processed is.

Matthew4693434
03-21-2010, 06:26 AM
I've done a test

surf = Surface((50,50))
surf.fill((255,100,50))
self.blit(surf,(10,500))
glBindTexture(GL_TEXTURE_2D, surf.texture)
surf2 = Surface((50,50))
glGetTexImage(GL_TEXTURE_2D,0,GL_RGBA,GL_UNSIGNED_ BYTE,surf2.data)
self.blit(surf2,(100,500))

The first rendered surface shows as orange, as it should but the second doesn't contain the copied texture data from the first and is black. :(

surf2.data is None before and after the glGetTexImage call. Why?

What? I read you have to use the function that way but instead the data is returned from the function. :( Well I have it working now.

if self.enter_fullscreen or self.exit_fullscreen:
for surface in Surface.texture_ready:
glBindTexture(GL_TEXTURE_2D, surface.texture)
surface.data = glGetTexImage(GL_TEXTURE_2D,0,GL_RGBA,GL_UNSIGNED_ BYTE)
surface.texture = None
Surface.texture_ready = []