PDA

View Full Version : render to texture with texture



enist
10-23-2003, 03:34 AM
Hi,
I'm rendering a cube to a texture with glCopyTexImage2D, and it works fine if I disable texture mapping when drawing the cube. If I apply a texture to the cube, I can't get the texture to be rendered anymore. Maybe it's the different pixelformat of the framebuffer? I just cant figure it out! Anyone know what could it be?
thanks

enist
10-23-2003, 03:41 AM
this is the code i use :

glViewport(0, 0, 128, 128);
// --- texture applyed to cube
// if i disable texture mapping here
// and enable it after rendering to texture
// it works
glBindTexture(GL_TEXTURE_2D,texture[0]);
drawCube(0.5f);

//texture for rendering
glBindTexture(GL_TEXTURE_2D,texture[1]);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 128, 128, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glViewport(0, 0, WIN_WIDTH, WIN_HEIGHT);

glBindTexture(GL_TEXTURE_2D,texture[1]);
drawCube(1.0f);

enist
10-23-2003, 04:17 AM
ok, im running this thread all by my self...!
glCopyTexSubImage2D is working fine http://www.opengl.org/discussion_boards/ubb/smile.gif
still wondering why glCopyTexImage2D didn't work though

AdrianD
10-23-2003, 04:58 AM
try using a glFinish() before you copy the framebuffer into a texture.

roffe
10-25-2003, 08:33 PM
Originally posted by enist:
ok, im running this thread all by my self...!
glCopyTexSubImage2D is working fine http://www.opengl.org/discussion_boards/ubb/smile.gif
still wondering why glCopyTexImage2D didn't work though

The difference between CopyTexImage2D and CopyTexSubImage2D is that CopyTexImage2D acts like TexImage2D but instead of getting the texture data from system ram it grabs it from the frame buffer. Try to specify the exact internal format you need(GL_RGB8??) instead of the general GL_RGB. Maybe CopyTexImage2D and TexImage2D handles unspecified texture formats differently. Just a thought.