PDA

View Full Version : Dynamic Cube Reflection Mapping Help



Falcon-
02-12-2007, 12:54 PM
Hey Guys, I could really use some help. I've tried all I can think of, but whenever I use glCopyTexSubImage2D() to grab a side of my cube map it always seems to copy the stuff that was rendered before-hand without regard for any rotations that I make before the glCopyTexSubImage2D. Here is the main parts of the rendering process:


void applyCubeFaceMatrix(int face, float x, float y, float z)
{

switch(face)
{
case 0: glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);
glRotatef(180.0f, 0.0f, 0.0f, 1.0f); break;
case 1: glRotatef( 90.0f, 0.0f, 1.0f, 0.0f);
glRotatef(180.0f, 0.0f, 0.0f, 1.0f); break;
case 2: glRotatef(-90.0f, 1.0f, 0.0f, 0.0f); break;
case 3: glRotatef( 90.0f, 1.0f, 0.0f, 0.0f); break;
case 4: glRotatef(180.0f, 1.0f, 0.0f, 0.0f); break;
case 5: glRotatef(180.0f, 0.0f, 0.0f, 1.0f); break;
}

glTranslatef(-x, -y, -z);
}
void generateTextureMap()
{ glPushMatrix();

// glReadBuffer(GL_BACK);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_CUBE_MAP);

glLoadIdentity();
// gluLookAt(0,0,0, 1,0,0, 0,1,0);
applyCubeFaceMatrix(0,0,0,0);

glCopyTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X , 0, 0,0, 0,0, texSize,texSize);

glLoadIdentity();
applyCubeFaceMatrix(1,0,0,0);
// gluLookAt(0,0,0, -1,0,0, 0,1,0);

glCopyTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X , 0, 0,0, 0,0, texSize,texSize);

glLoadIdentity();
applyCubeFaceMatrix(2,0,0,0);
// gluLookAt(0,0,0, 0,0,1, 0,1,0);

glCopyTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z , 0, 0,0, 0,0, texSize,texSize);

glLoadIdentity();
applyCubeFaceMatrix(3,0,0,0);
// gluLookAt(0,0,0, 0,0,-1, 0,1,0);

glCopyTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z , 0, 0,0, 0,0, texSize,texSize);

glLoadIdentity();
applyCubeFaceMatrix(4,0,0,0);
// gluLookAt(0,0,0, 0,1,0, 0,0,1);

glCopyTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y , 0, 0,0, 0,0, texSize,texSize);

glLoadIdentity();
applyCubeFaceMatrix(5,0,0,0);
// gluLookAt(0,0,0, 0,-1,0, 0,0,1);

glCopyTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y , 0, 0,0, 0,0, texSize,texSize);

glDisable(GL_TEXTURE_CUBE_MAP);

glPopMatrix();
} And the display loop:


void display(){

//move camera ..
//draw skybox ..
//draw test reflection object ..

// Bind Cube Map Texture, and generate if it is updated based on user movement
glBindTexture(GL_TEXTURE_CUBE_MAP, gltexCubeMap);

generateTextureMap();

// Draw main object
//-------------------------------------------------------------
glPushMatrix();
userspin(); // Rotate main object continually

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);


gluSphere(glSphere, 5, 40, 40);

glDisable(GL_TEXTURE_CUBE_MAP );

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

glPopMatrix();
//------------------------------------------------------------
glFlush();
glutSwapBuffers();
}

knackered
02-12-2007, 01:35 PM
please god may you not be trying to do what I think you're trying to do.

Falcon-
02-12-2007, 01:59 PM
Wow... thanks. If you would like me to repost on the basic forums I will. I'd just like some help.

Edit:
Here is a screen capture of the result.

http://www.csce.uark.edu/~smbarne/ex.jpg

PfhorSlayer
02-12-2007, 03:11 PM
You aren't drawing anything after you set up the transform for each face?

The idea is that you set up the transform, render the scene from that position/orientation, and THEN copy the backbuffer into your cube map texture's individual faces.

How are you expecting that something different appear in your cube map, if you're not changing what you're copying into each cube map face?

Falcon-
02-12-2007, 04:03 PM
Thanks PfhorSlayer - I was under the impression that I could render before hand and adjust the matrix to be able to 'view' the previous items that had been rendered - and was quite wrong :].

Edit - 3 min later - fixed. Thanks again, I won't mistakenly post in the advance forum again.

knackered
02-13-2007, 12:22 AM
I was only winding you up, don't be offended. You were trying to do what I thought you were trying to do, after all...mmm, never seen anyone make that mistake before, but I suppose it's kind of understandable. The fact that you didn't do a glMatrixMode(GL_TEXTURE) is actually more worrying.

k_szczech
02-13-2007, 05:17 AM
The fact that you didn't do a glMatrixMode(GL_TEXTURE) is actually more worrying.What for? You don't need to manipulate this matrix when rendering to cubemap, neither when using this cubemap.

knackered
02-13-2007, 07:00 AM
yes szczech, I know that and you know that, but falcon was visualising the cubemap in another way and manipulating it using matrix functions expecting that they would affect the source of copytex functions. The fact that he wasn't using the texture matrix for these matrix functions (he was using modelview) suggests an even deeper misunderstanding of what's going in, in my opinion.

Brolingstanz
02-13-2007, 07:39 AM
Don't get the wrong idea, Falcon. We get some posts that, quite frankly, strain believability; and as such, there's an occasional effort to separate the wheat from the chaff (the mistaken from the conspicuously incorrect).