"Skybox"-style cube map?

I get nice metal refractions using a cube map with glGenTexCoords/GL_REFLECTION_MAP, but how do you get a “sky” cube map? These are useful if you want to show a skybox, but only want it appearing in one little place in the ceiling, instead of being drawn behind the whole scene and causing little specks of white in the seams in the map.

If you want to view an environment in a cubemap, then all you need is an identity mapping for the texture coordinates. For texgen, you could load the standard axes into the object linear planes.

… little specks of white in the seams in the map.
Hmmm, sounds like you have a nasty case of t-junctions.

…all you need is an identity mapping for the texture coordinates.
How do I do this?

What I mean is an identity mapping from the vertex position to the texture coordinate. That is, texture coordinate == vertex coordinate.

In code, it might go something like this:

float X[4] = { 1,0,0,0 };
float Y[4] = { 0,1,0,0 };
float Z[4] = { 0,0,1,0 };
glTexGenfv( GL_S, GL_OBJECT_PLANE, X );
glTexGenfv( GL_T, GL_OBJECT_PLANE, Y );
glTexGenfv( GL_R, GL_OBJECT_PLANE, Z );
glEnable( GL_TEXTURE_GEN_S ); 
glEnable( GL_TEXTURE_GEN_T ); 
glEnable( GL_TEXTURE_GEN_R ); 

Of course, this assumes you plan to render your cube at the origin, not translated off into the blue somewhere. Were that the case, though, you could shift the object planes accordingly.

Have you actually tried this in real life? Or did you pull this out of your ass? Explanations with a lot of “mights” and “tries” sound kind of like BS.

Easy there, Napoleon Dynamite, THAT’s not proper etiquette! Graham is helping you out and he certainly does know what he’s talking about.

Have you actually tried this in real life? Or did you pull this out of your ass? Explanations with a lot of “mights” and “tries” sound kind of like BS.
Am I to take it that you’re having some difficulty, Halo? If so, I’d be more than happy to answer your questions.

Haha, yeah you could say that.

Are you actually talking about cube mapping, or just rendering a cube? See my “Cube map reflections - texture matrix” thread for a more detailed explanation of what I am after, and a demo(!).

I see. So you are after plain old-fashioned reflection mapping then? I was under the impression that you wanted to view a skybox.

Well actually, I want to do both.

Blitz3D has two cube map modes. One makes it look like you are viewing a skybox through a “window”. The other is a reflection-map distorted thing. I updated the demo, you can see what I mean:

All you have here is 2 different texture coordinate generation modes. For viewing the skybox, you could use the object texgen given above. For reflecting the same skybox in world geometry, use the reflection texgen, along with the inverse (transpose) of the camera rotation on the texture matrix stack.

That is, if you want mirror-like reflections on the geometry. The distorted stuff you mentioned is probably a result of using sphere-mapping.

No, wait, the cube map does not move based on camera rotation. Check the demo and see.

What do you mean? For the fixed-function pipe it’s perfectly acceptable and convenient to do it this way. For the programmable pipe, there’s no need to dance around the bush like this.

If you rotate the camera, in that demo I posted, the cube map does not move. The cube map only moves when you move the position of the camera.

That’s why you push the INVERSE of the camera rotation: It cancels the effect of any camera rotation. Try it, you’ll like it :slight_smile:

Ohhhh…now we are getting somewhere.

I assume I have to use glMultMatrix here? Or are you saying to just rotate the texture matrix the opposite of the camera rotation?

I tried rotating the texture matrix the opposite of the camera rotation, and it looks like the cube map is sort of staying in front of me, but this isn’t the same behavior as the demo I posted.

I’ll make a movie of it right now.

A simple way to do this is to grab the current modelview matrix with

glGetFloatv(GL_MODELVIEW_MATRIX, mat);

transpose mat, then load that onto the texture matrix stack with


Everything else is business as usual. Initialize your texgen stuff, and so on.

You might want to keep track of the modelview matrix yourself, but that’s up to you.

Note that it’s important to grab the modelview right after the camera transformations, since that’s all we want.

I will try what you said. Meanwhile, here is a movie showing the cube behavior if I just rotate the texture matrix by the opposite of the camera rotation:
http://www.leadwerks.com/post/cubemovie.zip (like 5 mb)

The effect this shows is not what I want. I showed how it rotates with the camera, and doesn’t move when I move the camera. I don’t know if that is the same thing you are describing.

Won’t be replying any more tonight…need to sleep. Thanks for helping with this.

Halo, what I have described here is nothing new. If you set this up right, it will work. I’ve used this technique to great effect, as have countless others. It’s important to understand the principals at work here. Even in the programmable pipeline, there’s no escaping the math. This is all just a bunch of math in disguise. The API is good at hidding that fact.

If you have trouble, feel free to ask.

Is the effect you’re describing what is seen in the video I posted? Can you please watch it and confirm one way or another?

This morning, I was able to get something similar to the demo I posted by translating the texture matrix the opposite of the camera position. The only caveat is I had to divide the camera position components by about 1024. (My texture is 128x128 each face, so I have no idea why it has to be divided by ~1100):
glTranslatef -x/1024.0,-y/1024.0,-z/1024.0

However, it still isn’t behaving quite right.