Hi there. I’m trying to make a flat shaded heightmap rendering engine, but I can’t seem to get it looking the way it should. I’ve asked around and rechecked but it just refuses to work.
I’ve posted the code I use to calculate my normals and then render the triangles. Maybe someone with an eye for OpenGL rendering can see what’s going on here.
------- Source code ---------
http://utilitybase.com/paste/26026 <– Vector and cross product classes and functions
http://ec.codepad.org/NsxUim61 <– Code to calculate normals
http://ec.codepad.org/l3rUCvUR <– Rendering code(no VBO)
----------- Image results ----------
http://up.mibbit.com/up/06o2n8oG.png <- Specular lighting trashed
http://up.mibbit.com/up/8LkRvtkd.png <- Scene with specular lighting, and the yellow hairs are vertex[0][0]; vertex[0][0] + the normal for the top left hand triangle.
http://up.mibbit.com/up/uxcfl8sS.png <- Lighting does somewhat look correct.
On the images: The white lines and face represent the light source which is defined:
glEnable(GL_LIGHT0);
float specular[] = {1,1,1,1};
float lightPos[] = {(float)testScrollbar1->GetValue() * m_revx, (float)testScrollbar2->GetValue() * m_revy, (float)testScrollbar3->GetValue() * m_revz, -1};
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);