iDevGames Forums
Render to Texture? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Render to Texture? (/thread-3315.html)



Render to Texture? - IBethune - May 1, 2007 01:56 PM

Quick OpenGL question - I have a 'minimap' view of my 3D world which I currently display the contours of the world (by a quad with my heightmap texture on it) and the position of players in the world (using coloured GL_POINTS).

I'd like to also add the fixed geometry objects e.g. buildings, walls, to the minimap. In the 3D view these are loaded OBJ models which are drawn and textures via display lists. I want to draw the objects onto the map, but just as solid blocks of semi-transparent grey, rather than fully textured.

I was thinking I could do this by maybe rendering them in an ortho view with lighting and texturing off but this is a bit wasteful of resources as the objects do not move from frame to frame.

I've heard a bit about render-to-texture, but googling around is a bit confusing, and seems to show up some ATI/NVidia specific extensions are required. I was thinking that it should be possible to render all the static objects once to a texture where the objects would be pure white and any empty space was transparent. Can I make use of the stencil buffer to do this? Then I could just blend this texture over the heightmap and render it each frame.

Anybody got any pointers to if I am thinking along the right lines? Any example code?

Thanks in advance

- Iain


Render to Texture? - OneSadCookie - May 1, 2007 03:06 PM

On Mac OS X you have three options:

1) an off-screen window, using NSOpenGLContext's createTexture:fromView:internalFormat: method (or the AGL equivalent) to create the texture. Supports FSAA. Supports 10.2 and above.

2) a PBuffer. See NSOpenGLPixelBuffer class, or AGL/CGL equivalent. "Nicer" than the off-screen window, and more like what happens on Windows than the other option. Pretty sure it doesn't support FSAA. Supports 10.3+

3) an FBO. See EXT_framebuffer_object OpenGL extension. This is the "right" way to do things. Unfortunately, it doesn't (yet) support FSAA (wait for EXT_framebuffer_multisample and EXT_framebuffer_blit), and is only available on 10.4+. Also, if you need stencil, you need the EXT_packed_depth_stencil extension (10.4.9+).


Render to Texture? - arekkusu - May 1, 2007 04:56 PM

4) CopyTexImage.


Render to Texture? - unknown - May 2, 2007 02:01 AM

If you want FBO example code there is some here.


Render to Texture? - OneSadCookie - May 2, 2007 02:24 AM

arekkusu Wrote:4) CopyTexImage.

Whoops, forgot the simplest of them all Shock

If your requirements fit the limitations of CopyTex[Sub]Image2D, then you can easily use FBOs for a potentially nicer way if they're available, and fall back to CopyTexSubImage2D if they're not. The EXT_fbo spec shows how.


Render to Texture? - IBethune - May 2, 2007 04:25 AM

Looks like CopyTexImage2D() will do what I want (and only requires completely cross-platform code)

So would it be good style to draw the texture to the back buffer as usual, copy to the texture, then clear the buffer and draw the scene as normal, before swapping buffers, or should I really be using a seperate buffer like an AUX buffer?

Cheers

- Iain