PDA

View Full Version : About Render2Texture



Krylloan
03-27-2002, 01:26 PM
I'm writing a game that will absolutely require the ability to render to a texture.
I hear everyone saying "it's easy, just render to the backbuffer, then transfer the image to a texture"
The problem is, I need to leave the backbuffer data intact.

This is why. (This is the steps my code takes).

1: Render background.to backbuffer

2: Render model to texture X.
3: Render texture X to backbuffer.
4: Render other miscellaneous objects directly to backbuffer.
5: Repeat steps 2 to 4 between 1 and ~100 times.

6: Render foreground and HUD.
7: Flip Buffers.


I could render each model to a separate texture before rendering the background, then render them all on top of each other.
This, however, would be an excessive waste of texture memory.

I can't seem to find any notes on how to render directly to a texture in OpenGL.
(I haven't looked particularly hard yet, sorry, but I have other bits of code I want to write ...now).

If you can help, you have my thanks.
Simon Hill.

Korval
03-27-2002, 01:40 PM
The only way to pull that one off is to use an extensions called ARB_Render_texture (or something like that). Not all implementations support it.

BTW, I hope you don't expect these operations to be particularly fast. Doing 100 render-to-textures, even without the copy operation, is going to stall your pipeline for a non-insignificant portion of time.

Krylloan
03-29-2002, 09:01 PM
Re: Korval - "I hope you don't expect these operations to be particularly fast."

I was actually hoping for it to be reasonably fast. (Only slightly slower than directly rendering to the backbuffer, but with the advantage of not having to do depth-sorting)

The reason being, I assumed rendering the models to the texture should take the same amount of time as rendering to the depth buffer. (Is this right?)

The only extra operations are:
1: The zeroing of the depth and alpha channels of the texture target before the render2texture. (And possibly the creation/deletion of the texture target)
2: The render/blit of the texture to the backbuffer.

Am I missing something here that is going to slow this process down? Is it slower to render to a texture surface than the backbuffer?

chxfryer
03-31-2002, 09:39 PM
http://www.gametutorials.com has exactly what you need in the opengl tutorial section.