PDA

View Full Version : again on cubemap problems...



gunslinger
12-17-2003, 01:42 AM
hi everybody:
i have studied lots of cubemap docs, and then i came out with this piece of code:

initstuff:

glGenTextures(1, &global.texID);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

for (int i = 0; i < 6; i++) {
glTexImage2D(
cubefaces[i],
0, // level
GL_RGB, // internal format
128, // width
128, // height
0, // border
GL_RGB, // format
GL_UNSIGNED_BYTE, // type
CubeMap[CUBE_POS_X + i]); // pixel data
}

glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);


cubemap_generation:
glViewport(0,0,128,128);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(90,1.0,1,5000);

glMatrixMode(GL_MATRIX_MODE);

for (int k;k<6;k++)
{
glClear(GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

glRotatef(CubeMapRots[k][0], CubeMapRots[k][1], CubeMapRots[k][2], CubeMapRots[k][3]);
RenderSkyBox();

glEnable(GL_TEXTURE_CUBE_MAP_EXT);

glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, global.texID);
glCopyTexImage2D(cubefaces[k],0,GL_RGB,0,0,128,128,0);
glDisable(GL_TEXTURE_CUBE_MAP_EXT);

}

Reshape(global_width,global_height);

}

cubemapped sphere rendering:
glDisable(GL_TEXTURE_2D);

glEnable(GL_TEXTURE_CUBE_MAP_EXT);



glPushMatrix();

//Enable cube mapping
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);

glMatrixMode(GL_TEXTURE);

glBindTexture(GL_TEXTURE_CUBE_MAP_EXT,global.texID );
//BISOGNA CARICARE LA TEXTURE!!!!
glPushMatrix();

//Render the main sphere! gluSphere(sphere, 6.0f, 64, 64);

glPopMatrix();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();


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


now why my cubemap texture isn't created/displayed?
I thought that calling glCopyTexImage2D would get all the stuff i rendered on the backbuffer and just stick it in the appropriate texture part (one of the GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT cube map partial texture units). Instead nothing is displayed. http://www.opengl.org/discussion_boards/ubb/frown.gif unhappy me

thans everybody the gunslinger