Normal calculations look right,but my scene doesnt

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 --------- <-- Vector and cross product classes and functions <-- Code to calculate normals <-- Rendering code(no VBO)

----------- Image results ----------

Maybe a little explanation of the images. The first image is back lit, the white lines and face represents the position of the light source.

The second image is the scene with specular lighting added, and the yellow hairs are vertex[0][0]; vertex[0][0] + the normal for the top left hand triangle.

and the third shows that lighting does somewhat work.

Do you assume that the vertices are give in counter - clockwise

From my understanding everything is stored in CW coordinates. Am I calculating my normals wrong here? From what I just tried when the light is behind something, it lights up, and when it’s infront, it gets dark. It’s like it’s reveresed

a = v1 - v2;
b = v2 - v3;

n = CrossProduct(a, b);
m_normals[(x + (z * m_size)) * 2 + 0] = n;
// Calc the normals of the second
b = v4-v2;
a = v2-v3;

n = CrossProduct(a, b);
m_normals[(x + (z * m_size)) * 2 + 1] = n;

I think that the accepted way to store vertices is CCW
In the application I write now, not all surfaces have the same ordering of vertices

The Hill`s CG book adcices
to calculate normals by Martin Newell method.And then check the directions…If you know that they are CW/CCW the calculation of directions of normals is trivial.

Try putting -


just after you turn lighting back on.