FBO + Cubemapping

Hello all,
I’m using a FBO to render to texture the six faces of a cubemap every x frames. It seems to work fine but I’d like to access each face to display some small billboards to make sure the sides are being rendered correctly.

During rendering to texture I set each cubemap face like this:

 
glFramebufferTexture2DEXT( 
GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, 
GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT+face, 
m_nCubeMapTexture, 
0 );
 

To render the billboards I’ve tried with something like:

  glEnable( GL_TEXTURE_CUBE_MAP );
glBindTexture( GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT, m_nCubeMapTexture );
...
glBegin(GL_TRIANGLE_STRIP);
...
glEnd();

or

  glEnable( GL_TEXTURE_CUBE_MAP );
glBindTexture( GL_TEXTURE_CUBE_MAP, m_nCubeMapTexture );
...
glBegin(GL_TRIANGLE_STRIP);
...
glEnd();

or

 
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, m_nCubeMapTexture );
...
glBegin(GL_TRIANGLE_STRIP);
...
glEnd();
 

But it doesn’t seem to work. I only get a half white/half pink quad haha. So I was wondering if somebody knows if it’s actually possible to access each cube side

Thanks for any help!
J

Initialization:
Allocate and bind FBO
Allocate each cubemap face with glTexImage2D
Allocate each cubemap face with glFramebufferTexture2DEXT

Render:
<Bind FBO>
<Bind Texture>
<Select Cube Face>
glFramebufferTexture2DEXT(
GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT+face,
m_nCubeMapTexture,
0 );
<Draw To Cube Face>

GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT is not to be used with glBindTexture.

Check for errors (glGetError).
Check FBO status (glCheckFramebufferStatusEXT).

@flavious:
Thanks for the quick response :slight_smile: , the rendering looks good, the FBO status is ok and I don’t get any error. But after rendering to texture and unbinding the FBO, I’d like to access each rendered face to display a billboard with that texture, only to see what’s actually being rendered to each face.

Ah, my bad :rolleyes:

For that I’d probably use 6 separate RTTs, but then I have to ask why you want your cubemap sides on billboards :stuck_out_tongue:

You could also look at glGetTexImage to get the RTT cubemap data, with each face substituted for the <target> parameter (probably slow).

Oh wait, that is an easy one :wink:

Just render quads arranged in any fashion you like with the appropriate texture coords. There is no need to do anything special for that.

I don’t know what I was thinking :rolleyes:

Ahh that’s interesting, what do you mean by appropriate texture coords? every side of the cubemap can be accessed with special tex coords?? :slight_smile:

I’ll give you a concrete example :wink:

Let’s say you want to layout your cubemap in a 2D overlay as an unfolded box, for debugging purposes.

For each of the 6 quads in 2D:
<set quad’s 3D cubemap texcoords>
(corners of corresponding cube face in 3D)
<set quad’s 2D vertex positions on screen>
(these correspond to the cube positions in 3D)

Make sense?

every side of the cubemap can be accessed with special tex coords??
Imagine that you have a cube (of any size) with point (0, 0, 0) exactly in it’s center.
Now imagine a vector from (0,0,0) pointing in any direction, having any length - this vector is the texture coordinate, and GPU will use it to sample the cubemap (it just points towards some texel on the cubemap).
So, for example, texture coordinate (x, y, 1.0) for any -1 <= x <= 1 and any -1 <= y <= 1 will point to the positive Z side.
Simply put - the coordinate with the biggest absolute value will select the side.

@<flavious>
@k_szczech

Ahhhhhhh yep, it makes sense :slight_smile:
Thanks for your replies, I’ll try it this afternoon when I get home!

This sample does exactly what you want-- render to FBO cubemap, then unfold and show each face on screen. It is just a matter of using the correct texcoords.