Archived

This topic is now archived and is closed to further replies.

ade-the-heat

Cube normals and textures

Recommended Posts

ade-the-heat    163
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 }

Share this post


Link to post
Share on other sites
ade-the-heat    163
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 ...

Share this post


Link to post
Share on other sites
dslprog    122
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.

Share this post


Link to post
Share on other sites