• Advertisement

Archived

This topic is now archived and is closed to further replies.

Rendering to a texture (How ?)

This topic is 5994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
u can copy a part or all the screen to a texture with glCopyTexSubImage2D(..)
to update an already existing texture with pixels (from any source) use glTexSubImage2D(..)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
That''s slooooowwwww... Almost all newer 3D hardware use shared framebuffer and texture memory. That means, that you could *directly* render to a texture, without having to copy data around. I think there is a function in D3D that supports this, but I''m not sure (i don''t use D3D). There must be a way to do this under OpenGL ? Some extension perhaps ?

- JL

Share this post


Link to post
Share on other sites
Ok this works for me (and ISNT slow, for me anyway), and should work for you ok:


int teximgnum = 0;

void InitRenderTexture()
{
glGenTextures(1, teximgnum);
glBindTexture(GL_TEXTURE_2D, teximgnum);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 512, 512, 0);
}

void RenderScene()
{
RenderTextureScene(); // render scene to be displayed on a texture
glBindTexture(GL_TEXTURE_2D, teximgnum);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 512, 512);

RenderView(); // render real scene
}

Share this post


Link to post
Share on other sites
glCopyTexSubImage2D(..) shouldnt be slow at all, but u need the same data formats in the screen as with the texture (so theres no expensive converting)

btw theres an arb_render_to_texture extension on the horizon

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
> glCopyTexSubImage2D(..) shouldnt be slow at all,

Ofcourse it is slow, even with the same data formats. The frambuffer data has to be transfered over the AGP bus down to host memory and back to the 3D card as a texture. Even if this is done as a simple block transfer (no processing, same data format) it still needs the data to be transfered over the AGP bus twice per texture each frame.

> btw theres an arb_render_to_texture extension on the horizon

This would be the ultimate solution. Do you have any more detailed info on this one ?

- JL

Share this post


Link to post
Share on other sites

  • Advertisement