# Understanding lighting, bump mapping, texturing

This topic is 3173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I managed to implement DOT3 bump mapping thanks to NeHe's tutorial (http://nehe.gamedev.net/data/articles/article.asp?article=20) on it. It works pretty well, but now I have come across a couple issues I can't track down with a search or by messing with parameter values. 1) The lighting works fine, but always seems to rotate with the users view point, and creates a problem with the angle of the lighting compared to where the texture thinks the light is coming from, resulting in a dark/black/non-textured model when rotated. I have tried applying GL_LIGHT_MODEL_TWO_SIDE and the only effect is had was the same thing, but on the back side of my model instead with the front being dark. 2) I cannot seem to un-bump map my textures so I can switch between normal (non-lighting) textures and bump mapped textures. The NeHe tutorial does not take care of the "clean up" needed after drawing a model that I'm looking for. Here is the code I use for bump mapping, which is basically a direct copy paste from the nehe tut, and also what I tried after drawing the model so I can draw other non-bump mapped models.
//----------------------------------
// to create the bump mapping effect

if (mdl.TexID != NO_TEXTURE)
{
glActiveTextureARB(GL_TEXTURE0);
glEnable(GL_TEXTURE_CUBE_MAP);
glBindTexture(GL_TEXTURE_CUBE_MAP, normCubeMap);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE) ;

glActiveTextureARB(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mdl.normalMapID);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE) ;

glActiveTextureARB(GL_TEXTURE2);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mdl.TexID);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}

glPolygonMode(GL_FRONT_AND_BACK, effectsList.polyFill);
glBegin(GL_TRIANGLES);

//-----------------------------
// and the "clean up" part

glDisable(GL_TEXTURE_CUBE_MAP);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);


I can/will attach pictures to show what I am talking about with the lighting. If any more code is needed let me know. EDIT: Here is an example of the lighting. The ball is the position of the light, and the line is the direction in which it is pointing. light from the front... http://sites.google.com/site/scwizzo/home/files/bump_front.jpg light from the back... http://sites.google.com/site/scwizzo/home/files/bump_back.jpg

##### Share on other sites
I'd really recommend using shaders to do this properly. It'll be a lot more flexible on the long run.

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 32
• 41
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631742
• Total Posts
3001987
×