Hybrid View

Opengl Surface normals in Chromadepth terrain

Hi All,

I am creating a chromadepth terrain using Opengl. I am loading a PGM(Portable grey map) file and then I am creating vertices for that. But I am not able to understand how would I get surface normals for the terrain? Here is my code snippet. I am using triangle strip Please help me. I am using VBO to load my buffers.

You have to compute yourself normals using verticesArray[] and computing/averaging dots products between edges AB and AC for alls triangles ABC that share the same vertex A
(I see that you use triangle strips so a lot of computations can be shared between connected triangles for to minimize computations)

Have you please a more complete basis of your code source for that I can test to add the necessary code to it ?
(if not, I think to can complete your code sample for to have a full fonctionnal OpenGL program code source but this can really economize a lot of time ...)

The important functions are loadPGMFile(), getNormalized*(), InitTerrain() and DrawTerrain()
(I have a little modify your source for to can use a variable filename of the .pgm picture and read unsigned bytes instead ints [this is perhaps for this that I have a problem with the format ...])