PDA

View Full Version : Cube Mapping



Joseph T
11-28-2008, 07:28 PM
I'm trying to setup basic cube mapping on a spinning cube in the center of a room. I know that my images are being loaded into memory correctly and in my initialize function I'm setting up each face like this:


glBindTexture( GL_TEXTURE_CUBE_MAP, cubeTextures[0] );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, brick_wall->width, brick_wall->height, 0, GL_RGB, GL_UNSIGNED_BYTE, brick_wall->data );

Where cubeTextures is an array that holds the 6 cube map textures. This is done for each of the 6 cube faces, negative x, positive y, etc. In my display function, I have this:


glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glEnable( GL_TEXTURE_GEN_R );
glEnable( GL_TEXTURE_CUBE_MAP );

glPushMatrix();

glRotatef( xrot, 1.0, 0.0, 0.0 );
glRotatef( zrot, 0.0, 0.0, 1.0 );

renderCubeMapCube();

glPopMatrix();

glDisable( GL_TEXTURE_GEN_S );
glDisable( GL_TEXTURE_GEN_T );
glDisable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_CUBE_MAP );

Where renderCubeMapCube() simply draws a cube centered around the origin. The problem is that the cube map doesn't use the textures I specified; it instead always uses the last texture that I've used in the program. I've kind of gotten around it by using glBindTexture to bind the texture that I want to be used the most as the last thing that the display function does before it flushes the buffer, but I really want to use the cube texture's I've specified. Can anyone give me some help here?