Hi all!
I’ve a problem. You all know the Tutorial with Heightfield Terrain while using a Bitmap-File.
I want to make this code better while taking no triangles. I want to bulit the terrain by using Surfaces. I always take 3x3 points which describe my Surface.
So, now my problem: When I’m using GL_AUTO_NORMAL the lightning isn’t correct because of all some points use other tangents.
How can I make the lightning here correct? I tried it by using my own normals but it didn’t work!
Thanks for every help!!
greets, Corrail
Here my code I’m using:
(If you want the whole Source-Code pls Mail me! corrail@gmx.at)
///////////////////////
// Terrain Variables //
///////////////////////
#define MAPX 31
#define MAPZ 31
#define BitMAPX 32
#define BitMAPZ 32
#define MAPScale 20.0f
float terPkt[MAPX][MAPZ][3];
float terAktPkt[3][3][3];
///////////////////////
// InitializeTerrain //
///////////////////////
// ImageData is the black-white Image
void InitializeTerrain()
{
for (int i = 0; i < MAPZ; i++)
{
for (int j = 0; j < MAPX; j++)
{
terPkt[j][0] = float(i)MAPScale;
terPkt[j][i][1] = (float)imageData[(jBitMAPZ+i)*3];
terPkt[j][i][2] = -float(j)*MAPScale;
terNorm[j][i][0] = 0.0f;
terNorm[j][i][1] = 0.0f;
terNorm[j][i][2] = 0.0f;
}
}
}
///////////////////////
// Rendering Terrain //
///////////////////////
glFrontFace(GL_CW);
for (int a = 0; a < (int)((MAPX-1)/2); a++)
{
for (int b = 0; b < (int)((MAPZ-1)/2); b++)
{
for (int c = 0; c < 3; c++)
{
for (int d = 0; d < 3; d++)
{
terAktPkt[c][d][0] = terPkt[2a+c][2b+d][0];
terAktPkt[c][d][1] = terPkt[2a+c][2b+d][1];
terAktPkt[c][d][2] = terPkt[2a+c][2b+d][2];
}
}
glColor3f(1.0,1.0,1.0);
glMap2f(GL_MAP2_VERTEX_3, 0.0, count, 3, 3, 0.0, count, 9, 3, &terAktPkt[0][0][0]);
glEnable(GL_MAP2_VERTEX_3);
glMapGrid2f((int)count, 0.0f, count, (int)count, 0.0f, count);
glEvalMesh2(GL_FILL, 0, (int)count, 0, (int)count);
}
}
glFrontFace(GL_CCW);