cube maps abc

I am trying to implement environment cube maps for the first time using the Nvidia EXT. Some questions :

I first render my scene as seen through the six faces of the cube and “save” them through

glBindTexture(GL_TEXTURE_2D,cube_text[i]);
glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,tx,ty,tex_size,tex_size,0);

Then to “load” them I do

glEnable(GL_TEXTURE_CUBE_MAP_EXT);
for (int i=0;i<6;i++) glBindTexture(GL_TEXTURE_CUBE_MAP_EXT,cube_text[i]);

Is this right or do I need to use the NVIDIA cube face targets when I am rendering the six faces?

Thanks

A cubemap is a single texture object so you would only have one texture id (instead of an array of them like you have).

For the render step you would do something like this:

glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubeTex);
for(int i = 0; i < 6; i++)
glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB+i,…);

Then when rendering you would do this:

glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubeTex);

[This message has been edited by jra101 (edited 11-21-2002).]

I see. Thanks

My (NVIDIA) cube map is not looking right and I believe it is because I am rendering the six faces wrong.

If the reflector is at “reflector_center” thats how I move the camera to render each of the six faces

glFrustum(-0.1,0.1,-0.1,0.1,0.1,1000);
glRotatef(90,0,1,0);//left face
glRotatef(-90.0,0,1,0);//right face
glRotatef(-90.0,1.0,0,0);//top face
glRotatef(90.0,1.0,0,0);//bottom face
glRotatef(180,0,1,0);//back face
gluLookAt(reflector_center[0],reflector_center[1],reflector_center[2],eye[0],eye[1],eye[2],up[0],up[1],up[2]);

Does anybody see anything wrong with these?
Thanks

Eh?

Dunno if you’re this confused but try this.

You may want to play with the signs on the rotates, I haven’t tried this and can never figure these things out without a little bit of experimentation. Also you may want to arrange these into single reads.

glFrustum(-0.1,0.1,-0.1,0.1,0.1,1000);

glPushMatrix();
glRotatef(90,0,1,0);//left face
//draw & read here
glPopMatrix();
glPushMatrix();
glRotatef(-90.0,0,1,0);//right face
//draw & read here
glPopMatrix();
glPushMatrix();
glRotatef(-90.0,1.0,0,0);//top face
//draw & read here
glPopMatrix();
glPushMatrix();
glRotatef(90.0,1.0,0,0);//bottom face
//draw & read here
glPopMatrix();
glPushMatrix();
glRotatef(180,0,1,0);//back face
//draw & read here
glPopMatrix();

Also you don’t need the lookat for a cubemap. You only need a translate if you get the reflection set up correctly, the eye should be translated to the reflecting object.

Also check this out, but it does use coordinate space where z is up, not y:
http://www.dorbie.com/envmap.html

[This message has been edited by dorbie (edited 11-22-2002).]

I noticed that there is a GL_REFLECTION_MAP_ARB and a GL_NORMAL_MAP_ARB. Whats the difference between these two?

one generates reflection vector (reflect eye at normal) and uses this as texcoord, one takes the normal and uses this as texcoord… that simple

I have looked at past posts on dynamic cube map and noticed that if the viewpoint change I am supposed to change the texture matrix to get it right. Can anybody explain why is that needed? And what exactly must be that transformation?
Thanks

I need help. I am stuck at this point. Here it is the problem:
In my main display function I translate and rotate the camera in my program through

glTranslatef(—)
gluLookAt(…)
glTranslatef(…)
glRotatef(…)
glTranslate(…)
render_Scene

How can I have this turning out correctly when producing the six views of the cube map? I guess I have also to translate and rotate the camera, but since the camera is now at the position of the reflector I dont know how to do rotations.

Any help would be appreciated

From my understanding of cubemapping…

You can ignore the glTranslate calls as they don’t affect the cube mapping.

You need to do the inverse of the “camera” rotations on your texture matrix because the generation of the texture coords is based on world(?) coords, not on the object coords.

Because you NEVER rotate the view point (ie. you apply the inverse rotation of your camera to your MODELVIEW matrix) the coords that are automatically generated will be aligned with the viewpoint. So as you rotate the “camera” it’ll appear that the reflection is stationary to the viewpoint while the object is rotating.

So just before you draw your object(s) you do a call like…

glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glRotatef(<camera rotation> );
glMatrixMode(GL_MODELVIEW);

When you are done rendering with the cube map you do…

glMatrixMode(GL_TEXTURE);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

Hope this helps…

Sorry, you don’t do the inverse of your “camera” rotations on your texture matrix. You do the actual camera rotations (the inverse is applied to the object and the inverse of the inverse is applied to the texture - ie. the actual rotations).

Thanks. I tried it but it doesnt work (get some twisted cube map).

Let me post again what I am doing in the main display: I am rotating the camera about a given point through

gluLookAt(…);
//Then rotate camera
glTranslatef(-eye[0]+ctrans_xy[0],-eye[1]+ctrans_xy[1],-eye[2]+ctrans_z);
glMultMatrixf(rot_inverse); glTranslatef(eye[0]-ctrans_xy[0],eye[1]-ctrans_xy[1],eye[2]-ctrans_z);
render_scene;

and I would like this rotation to show up correctly in the environment map. I am generating the cube map dynamically (every frame) so I could as well apply a transformation at the time I am rendering the cube map. But what should that transformation be?
Thanks