PDA

View Full Version : cube maps



demonoid
12-07-2003, 12:07 PM
hi,
i want to have a sphere which reflects the environment. im generate the cubemaps and try to use them as a secondary texture for the sphere (sphere also has a 2d-texture). however, the sphere turns completely black. maybe someone can tell me where my mistake is?

here's what id do:

//init cubemap (once)
glGenTextures(1,&g_uiCubemap);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,g_uiCubemap) ;
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE _MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE _MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE _WRAP_S,GL_MIRRORED_REPEAT_ARB);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE _WRAP_T,GL_MIRRORED_REPEAT_ARB);
for (int p=0; p<6; p++)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB+p, 0, GL_RGB8,g_CubeMapSize, g_CubeMapSize, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);


//generate cubemap (once each frame)
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,g_uiCubemap) ;
glViewport(0,0,g_CubeMapSize,g_CubeMapSize);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0,1,0.2,4000.0);
glMatrixMode(GL_MODELVIEW);
for (int p=0; p<6; p++)
{
glLoadIdentity();
gluLookAt(/*one of six directions startiong from origin*/);
DrawScene();
glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_AR B+p,0,GL_RGB8,0,0,g_CubeMapSize,g_CubeMapSize,0);

}


//render the sphere:
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, theTextures[0]); //the normal 2d texture
glEnable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MO DULATE);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,cubeMap);
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_REFLECTION_M AP_ARB);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_REFLECTION_M AP_ARB);
glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_REFLECTION_M AP_ARB);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);

gluSphere(...);


thanks a lot for the help!

sebh
12-07-2003, 01:33 PM
Are you sure that it isn't the GL_TEXTURE0 texture who is black?(because you use GL_MODULATE for GL_TEXTURE1)

demonoid
12-07-2003, 09:29 PM
no, the 2d texture is white (and the sphere appears white if i remove all that stuf concerning the 2nd texture)
i also tried GL_ADD instead of modulate, but it still remains black.

demonoid
12-07-2003, 10:04 PM
i also noticed the following strange effect: if i use the cubemap as the 2D-texture (and dont use the old one anymore), eg sth like:


glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,cubeMap);
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_REFLECTION_M AP_ARB);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_REFLECTION_M AP_ARB);
glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_REFLECTION_M AP_ARB);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);

gluSphere(...);

then the following happens:
the sphere casts a shadow (using the stencil buffer and a shadow volume).
the upper (lighted) half of the sphere remains black, the lower (shadowed) one has some texture on it (though it doesnt look like what id expect, but i guess that's normal since cubemaps are different from usual textures).
could it have sth to do with the generation of texture-coordinates for quadrics? actually i'm using a display list where i put my sphere + automatically generated texture coordinates and the do a glCallList(..) instead of that gluSphere(..). so the posted code ain't quite accurate in that respect.