PDA

View Full Version : cuebmapping problem, need help



991060
08-12-2004, 05:36 AM
Hi all:
This is the first time I do cubemapping, and I'm having some weird problems, one of which is like this:
If I dont draw the environment, the sphere in my demo is quite weird, it does have reflective mapping component, but it looks like the result is modulated by other color: http://img.photobucket.com/albums/v438/991060/Snap2.png
But if I draw the surrounding, the result becomes correct:
http://img.photobucket.com/albums/v438/991060/Snap1.png



void drawSkyBox(void) // this function draws the surrounding
{

glActiveTextureARB(GL_TEXTURE3_ARB);
cubemap.bind();
cubemap.enable();

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
GLfloat s_plane[] = { 1.0, 0.0, 0.0, 0.0 };
GLfloat t_plane[] = { 0.0, 1.0, 0.0, 0.0 };
GLfloat r_plane[] = { 0.0, 0.0, 1.0, 0.0 };
glTexGenfv(GL_S, GL_OBJECT_PLANE, s_plane);
glTexGenfv(GL_T, GL_OBJECT_PLANE, t_plane);
glTexGenfv(GL_R, GL_OBJECT_PLANE, r_plane);
glPopMatrix();
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
camera.trackball.apply_inverse_transform();

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glScalef(10.0, 10.0, 10.0);
glutSolidCube(1.0);
glPopMatrix();

glMatrixMode(GL_TEXTURE);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

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

cubemap.disable();
}


void drawCubeMapping() // this function draws the reflective sphere
{
glEnable(GL_VERTEX_PROGRAM_ARB);
glEnable(GL_TEXTURE_SHADER_NV);
glActiveTextureARB(GL_TEXTURE0_ARB);
normalmap.bind();
normalmap.enable();
glActiveTextureARB(GL_TEXTURE3_ARB);
cubemap.bind();
cubemap.enable();
g_ARBVP_EnvMap.bind();

environment_mapping.call_list();

glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 0, eyePos.v);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
camera.apply_inverse_transform();
object.apply_transform();

sphere.call_list();

glDisable(GL_VERTEX_PROGRAM_ARB);
glDisable(GL_TEXTURE_SHADER_NV);
glActiveTextureARB(GL_TEXTURE0_ARB);
normalmap.disable();
glActiveTextureARB(GL_TEXTURE3_ARB);
cubemap.disable();

}

991060
08-12-2004, 05:42 AM
I was using arb vertex program and nvidia's texture shader for the cubemapping effect, and it looks like if I dont draw the skybox, the shpere's vertex color will modulate with the final result. Because if I dont output its color in the vertex program, I got black screen. But once again, if I draw the skybox, even if I don't output vertex color, it's still correct result, any idea why?

rgpc
08-12-2004, 02:29 PM
Looking at your code I can't see anything obviously wrong. Perhaps the problem is in your Vertex Program. Can you post the code for that?

I'm not sure if you are trying to say this but the output you are getting looks like it is the Reflection from the smooth sphere modulated by the colour of the normal map - which is why I think it is your VP.

991060
08-12-2004, 05:21 PM
Yes, you're right, it is modulated by the normal map. The vertex program is correct, I just forgot to set the correct texture environment for the cubemap. It's defaulted to GL_MODULATE, and if I change it to GL_REPLACE, everything is correct. :)

SeskaPeel
08-16-2004, 08:09 AM
Actually, the "colored" result looks like you used a default cube map. These cube maps can be considered as GL white texture when you do glBindTexture(GL_TEXTURE_2D, 0) ;

When you bind a 0 cube map, some driver implementation subsitute a white texture by a colored texture (with eight corners being black, white, cyan, yellow, purple, red, green and blue, and then interpolates on the faces).

You should check if your cube map is correctly unbound or correctly bound when you enable or disable your background.

SeskaPeel.

rgpc
08-16-2004, 03:21 PM
Actually looking at the first image, which shows the problem, it's apparent that the correct cubemap has been bound (you can see it reflected on the object).

And looking at the post prior to yours, Seskapeel, it's apparent that the solution has been found.

SeskaPeel
08-17-2004, 02:15 AM
rpgc you're right, I was exhausted. Looks like I annoyed you (else you wouldn't have posted), sorry for that.

SeskaPeel.

rgpc
08-17-2004, 08:24 PM
We all do it...

Get some sleep. :D