Oh wow, I forgot about this thread, well gonna continue anyway…
Here’s my scene draw code:
void DrawGLScene()
{
GLfloat position[] = { 50.0f,1.0f,50.0f,1.0f };
glLightfv(GL_LIGHT0, GL_POSITION, position);
GLfloat diffuseLight[] = { 2.0f, 2.0f, 2.0f, 1.0f };
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
GLfloat ambient[] = { 0.05f, 0.05f, 0.05f };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
glEnable(GL_LIGHT0);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
GLfloat x_m, y_m, z_m, u_m, v_m;
GLfloat xtrans, ztrans, ytrans;
GLfloat sceneroty;
int numtriangles;
// calculate translations and rotations.
xtrans = -xpos;
ztrans = -zpos;
ytrans = -walkbias-0.5f;
sceneroty = 360.0f - yrot;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity();
glRotatef(lookupdown, 1.0f, 0, 0);
glRotatef(sceneroty, 0, 1.0f, 0);
glTranslatef(xtrans, ytrans+0.025f, ztrans);
glBegin(GL_QUADS);
glMateriali(GL_FRONT, GL_SHININESS, 50);
float mcolor[] = {0.5,0.5,0.5,1.0f};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mcolor);
glNormal3f(0,0,1.0f);
glVertex3f(35,5,52);
glVertex3f(35,0,52);
glVertex3f(65,0,52);
glVertex3f(65,5,52);
glEnd();
for(int z = 1; z<99; z++)
{
for(int x = 1; x<99; x++)
{
glBegin(GL_QUADS); // start drawing the cube.
glMateriali(GL_FRONT, GL_SHININESS, 50);
if(terrainmap[x][z] == 0)
{
float mcolor[] = {0.419,0.556,0.137,1.0f};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mcolor);
}
else
{
float mcolor[] = {0.96,0.815,0.686,1.0f};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mcolor);
}
glNormal3f(0,1.0f,0);
glVertex3f(x,heightmap[x][z],z); // Top Right Of The Quad (Top)
glVertex3f(x+1,heightmap[x+1][z],z); // Top Left Of The Quad (Top)
glVertex3f(x+1,heightmap[x+1][z+1],z+1); // Bottom Left Of The Quad (Top)
glVertex3f(x,heightmap[x][z+1],z+1); // Bottom Right Of The Quad (Top)
glEnd();
}
}
// swap buffers to display, since we’re double buffered.
SDL_GL_SwapBuffers();
}
And that’s the draw scene code.
All heightmap values are zero currently.