Dynamic Cube Map Problem?

Howdy all, I’ve been having trouble with my dynamic cube map creation. When i render the 6 sides of the cube, the images come out as though the camera were shifted about 1000 units closer in that direction, So that the cube map images don’t align when placed back on a cube. Almost like it’s only rendering 256x256 of a 512x512 view.

I’ve tried shifting the camera, resizing my scene, and even playing around with the projection matricies. does anyone have any suggestions? And for reference, here is my code.

GVector3 dirs[6] = {GVector3(-1.0f,0.f,0.0f),GVector3(1.f,0.0f,0.0f),
GVector3(0.0f,1.f,0.01f),GVector3(0.0f,-1.f,0.01f),
GVector3(0.0f,0.0f,1.f),GVector3(0.0f,0.0f,-1.f)};

bool RenderCubeMap(int texID, float x, float y, float z)
{
int size=256;
glViewport(0,0,size,size);

gluPerspective(90.f,1.f,10.f,20000.f);

for(int i=0;i<6;i++)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
glLoadIdentity();

  //glTranslatef(x,y,z);
  gluLookAt(x , y, z, dirs[i].x,dirs[i].y,dirs[i].z, 0.0,-1.0, 0.0);
            
  RenderWorld();

  glEnable(GL_TEXTURE_CUBE_MAP_ARB);
  glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, texID);

  glTexParameterf(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_ARB);
  glTexParameterf(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_ARB);
  glTexParameterf(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameterf(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

  glCopyTexImage2D(texs[i], 0, GL_RGB, 0, 0, size,size, 0);
  glDisable(GL_TEXTURE_CUBE_MAP_ARB);

}

ReSizeGLScene(800,600);

return true;
}

[This message has been edited by duhroach (edited 05-15-2003).]

Why is your projection matrix on your modelview stack ?

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(…);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(…);
etc.

and

int size=256;

is that what you meant ?

newt, i don’t follow with regards to the projection on the modelview stack?

and yes, size=256 is what i planned

Originally posted by duhroach:
[b]newt, i don’t follow with regards to the projection on the modelview stack?

and yes, size=256 is what i planned[/b]

What newt is correctly pointing out is that you are setting up your projection frustum (glViewport & gluPerspective) but you haven’t switched to your matrix to the Projection matrix.

You can probably get away with…

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glViewport(0,0,size,size);
gluPerspective(90.f,1.f,10.f,20000.f);
glMatrixMode(GL_MODELVIEW);

// Rest of code in here…

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

And a performance tip (if you are using nVidia) - only update one side of your cube map per frame…

Hey, that fixed the problem. Thanks for the help! As a general rule, can we only set the perspsective/viewport while in Projection mode?

~Main

Originally posted by duhroach:
As a general rule, can we only set the perspsective/viewport while in Projection mode?

As you have found out you can set the perspective/view port at any time (in fact I think you really can set the viewport at any time). But you should set the frustum (gluPerspective etc.) when the Projection matrix is current.

[This message has been edited by rgpc (edited 05-16-2003).]