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