PDA

View Full Version : FBO + Cubemapping



Count Duckula
10-11-2006, 02:08 PM
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

10-11-2006, 02:24 PM
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).

Count Duckula
10-11-2006, 02:45 PM
@flavious:
Thanks for the quick response :) , 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.

10-11-2006, 02:55 PM
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 :p

10-11-2006, 03:04 PM
You could also look at glGetTexImage to get the RTT cubemap data, with each face substituted for the <target> parameter (probably slow).

10-11-2006, 03:14 PM
Oh wait, that is an easy one ;)

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:

Count Duckula
10-11-2006, 03:51 PM
Ahh that's interesting, what do you mean by appropriate texture coords? every side of the cubemap can be accessed with special tex coords?? :)

10-11-2006, 04:39 PM
I'll give you a concrete example ;)

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?

k_szczech
10-11-2006, 11:37 PM
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.

Count Duckula
10-12-2006, 07:06 AM
@<flavious>
@k_szczech

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

arekkusu
10-12-2006, 07:41 AM
This sample (http://developer.apple.com/samplecode/FBOBunnies/index.html) 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.