Stupid cubemap


I tried using cubemaps for environmental mapping.
I load my 6 textures, assign each to one face of the cube, then i do this:


glEnable (GL_TEXTURE_GEN_R);
glEnable (GL_TEXTURE_GEN_S);
glEnable (GL_TEXTURE_GEN_T);

And watch the result.

However it just cannot be physically correct!

I have a simple cube. When i look down at it, i should see the sky, but i see one side of the cubemap. Ok, it might be possible, that i have assign one side wrong.
BUT when i look at it from beneath, i see exactly the same side of the cube! That is absolutely not possible, cause i know that i assigned 6 different images to 6 different sides.

Also when i stay at one point and rotate around the y-axis, of course the reflection rotates, too. BUT it rotates in the opposite direction. That´s not correct (i actually took a mirror, lay it on the floor and checked it!).

Which setting do i have to change to correct this?


Are you sure you have correct normals?

Rotate the texturematrix to the inverse of the camera.

@Humus: Yes, i am sure i have correct normals.

@Mazy: Could you go a bit more into detail. I think i know what you mean, but i don´t know how to accomplish this.


Ok, the thing that it rotates in the wrong direction is solved.
And i found out how i can rotate the texture matrix.

The only missing piece is, that i don´t know how i get the reverse of the camera.
Do you mean to use the forward, up and right vector of the camera to form a matrix, reverse that and rotate the texture matrix with that? Maybe you can tell me exactly in which way i would have to do that.



to inverse the rotation you just take the upper 3x3 matrix and transpose it because its a orthonormal(or orthogonal ??) matrix. So you reverse the rotation. Then set the texture matrix to this transposed and the translation of the texture matrix to (0,0,0).

Its the same way as you have billboards always facing to the camera.


Thanks, it´s working now.

However, after playing a bit with it, i have some questions about it.

  1. On my GF2 i can setup one Cubemap per texture unit. That means 2. When i create a cubemap i have to have the tu enabled, i want to use it later in. When i create two cubemaps in one tu, i can only use the last one. It seems, that bindtexture has no effect. Also i don´t have to bind the cubemap to the texture unit, but when i call glEnable (GL_CUBEMAP…), it is already working.

Why these restrictions? A cubemap is only a texture object, why is it not allowed to create more than one cubemap, and switch between them via glBindTexture?
And why am i forced to use the cubemap in the tu i created it in?

  1. Of course i don´t want all my objects to be environmental mapped. Therefore when i draw my geometry, i have to enable and disable it quite often (i use BSP-trees already, so i cannot sort the objects).
    How heavy is the performance hit of this?

  2. I examined the Splinter Cell Demo. I noticed, that they don´t use a real cubemap for their environment mapping. They seem to use an image with “undefined” content. And they don´t alter that texture, depending on the room, one is in.
    Of course this is a very easy approach to avoid having several cubemaps for every room.
    But i wondered, how such a texture looks like? What kind of texture would you use?

Maybe i will have even more questions. But for now it´s enough :stuck_out_tongue:

Thanks for the help so far.

The GL spec doesn’t distinguish between CUBE_MAP texture objects and 2D texture objects. If you treat them just the same, they should work just the same.

Note that TEXTRE_CUBE_MAP has higher priority than TEXTURE_2D, so if you enable both on the active texture unit, the CUBE_MAP target will “win” and stay enabled until it gets disabled on that same texture unit.

Jan, regarding your point 1,
you sure you did it like this:
1)Create a texture object (glGenTextures blabla)
2)Bind it to target GL_TEXTURE_CUBE_MAP_ARB
3)Upload the six sides

Or did you reverse something, or bind to GL_TEXTURE_2D?

Originally posted by zeckensack:
[b]Jan, regarding your point 1,
you sure you did it like this:
1)Create a texture object (glGenTextures blabla)
2)Bind it to target GL_TEXTURE_CUBE_MAP_ARB
3)Upload the six sides

Or did you reverse something, or bind to GL_TEXTURE_2D?[/b]

Yes, that was it! In my routine, which binds my textures, i forgot to make it compatible with cubemaps.
Now that works, too.

Thanks for the help!