Skip to main content
gamedev.net
🔒 Locked

Render to a Texture

Started by rotalever 4 replies 1k views
Original Post
rotalever
rotalever
Hi, I am creating a GUI library with Custom rendering backends. I will provide one rendering backend: OpenGL. I want to use rendering to a texture. How can I do that in a save/portable way (system independent)? One approach would be to use the main render target, render the big texture to it, render some polygons/textures to it and use glCopyTexSubImage*() to render those parts back to the big texture, which were changed. But this can be a problem, because the main render target must be empty to do that. The user then must use the library like this:
[SOURCE]
clearbuffers ();
GUI.RENDER_STUFF_TO_TEXTURES (...);
clearbuffers ();
MAIN_PROGRAM_RENDER_3D_GRAPHICS (...);
...
GUI.RENDER_TEXTURES_TO_SCREEN (...);
[/SOURCE]
Another drawback with this is, that I have to first render (subimages of) the big texture to the main rendering target which costs additional fillrate. Nvidias paper on render to texture: http://developer.nvidia.com/object/gdc_oglrtt.html says that some extensions exist to directly render to textures. In addition they mention, that this feature is available since the release of their first GeForce. I guess that most ATI/AMD cards also support this extension? It would be OK for me to use it, but how? Remember, it must me system independent. I would like to see a simple code example. Thanks in advance.
rotalever
rotalever
Maybe I can use the pbuffer with some #ifdef, in Windows through WGL and in Linux through SGIX_pbuffer (?).
I found those SGIX_* when I used "glxinfo | grep pbuffer" in Linux. Is this a way I can handle it?

something like:
[SOURCE lang=c]#ifdef WINDOWS#define my_p_buffer_ext_function blabala...#else#define my_p_buffer_ext_function blublub...#endif[/SOURCE]
[/source]

The last thing I must work out is howto use the extensions... Any tutorial available which covers both? I am not very familar with those OpenGL extensions.
V-man
V-man
If you really need p-buffer, then go ahead and use it. The nVidia SDK has examples.
FBO is easier to use but is only available on GL 2.0 hw
FBO is currently an extension defined by

http://www.opengl.org/registry/specs/EXT/framebuffer_object.txt

It's very long but at the bottom, there are some examples.
Go down to Usage Examples.

rotalever
rotalever
Thank you for information in the framebuffer extension. But I think it is too "new" and I want to be as compatible as possible. But pbuffer is old enough...
I will search the nvidia SDK..
Found some examples in the SDK, they look overcomplicated... Hundreds of lines to use a simple extension? I thought it would be easier..

[Edited by - rotalever on June 29, 2007 3:07:22 AM]
rotalever
rotalever
I've read that tutorial some time ago. But it uses the "old" method, which works good, but has the downside for the user as I said in my fist post (the user has to call the rendering function twice, one time before doing his own rendering to render into the textures and one time after doing his own rendering to render the textures finally to screen.).

from the tutorial:
Quote:

// Copy Our ViewPort To The Blur Texture (From 0,0 To 128,128... No Border)
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 0, 0, 128, 128, 0);


But pbuffer is not so easy to handle. I think it would be best (for me ;-)) to use the old method in my reference renderer and if people want to create their own render class, they can use more complicated methods.

[Edited by - rotalever on June 30, 2007 11:51:17 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.