Cube normals and textures

Started by
2 comments, last by ade-the-heat 20 years ago
I had a wonderful scene with directional sun light on a grassy terrain. I enabled the auto normal so I got shading (of a type) depending on which way I was looking on the terrain. I then drew a cube and put in it''s normals and textures (see the end of this mail for code snippet). 1a. If I calculate the cube''s normals then I get no shading effects due to the sun on the terrain. 1b. If I remove the cube''s normals then I get sun shading on the terrain but no shading on the cube !! 2. I can get no texture on the cube at all (I read in a .bmp bricks image) regardless of what I do. Textures work fine elsewhere in the code ! This must be the simplest problem ever but I can''t solve it !! code: =============================== glTranslatef(xPos, yPos, zPos); glScalef(10.0f, 4.0f, 5.0f); glBindTexture(GL_TEXTURE_2D, g_wall); DrawCube(); void DrawCube() { glPushMatrix(); glBegin(GL_QUADS); glNormal3f(0.0, 0.0, 1.0); //front face glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f); glTexCoord2f(0.0f, 10.0f); glVertex3f(1.0f, 0.0f, 0.0f); glTexCoord2f(10.0f, 10.0f); glVertex3f(1.0f, 1.0f, 0.0f); glTexCoord2f(10.0f, 0.0f);glVertex3f(0.0f, 1.0f, 0.0f); glEnd(); .. .. ..like wise for other faces }
Advertisement
Ok, I''ve worked out the Texture problem.
Yes I admit I''m really really stupid on that part of the problem and am prepared to admit to stupidity on the other problem ...
I think the problem comes from the glScale function. It multiplies every vertex (that''s what we want it to do), but it also multiplies the face normals. OpenGL uses those normals to calculate the incident light, but to get a more accurate shadding, every normal must be normalized. Try to enable GL_NORMALIZE, or just avoid using glScale when doing lighting.
AUTO_NORMAL only works for evaluators. Are you using evaluators in your terrain? If not, the normal value used is probably coming from somwhere else (like, whatever was set up last).
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement