Render to Texture?

Member
Posts: 156
Joined: 2002.10
Post: #1
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
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
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+).
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #3
4) CopyTexImage.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #4
If you want FBO example code there is some here.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
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.
Quote this message in a reply
Member
Posts: 156
Joined: 2002.10
Post: #6
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
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Render to Texture behaves weirdly ardowz 2 1,475 Feb 17, 2014 04:50 PM
Last Post: ardowz
  Render video (e.g. QuickTime) to buffer or texture? Ingemar 14 13,322 Jun 8, 2011 04:09 PM
Last Post: mdejong1024
  PBuffer & Render to Texture (read & write) habicht 4 4,176 Feb 7, 2005 05:33 PM
Last Post: habicht
  Render to texture and Blending reubert 3 4,242 Oct 30, 2004 04:48 AM
Last Post: arekkusu
  Render-To-Texture? MacFiend 11 5,222 May 30, 2003 04:46 AM
Last Post: OneSadCookie