   GRRR, More Land Problems
  Alright, I was reluctant to make a new thread so shortly after the last one, but again I am stumped (happens a lot when I work late at night).I'm trying to generate a map from a greyscale height map, something that's not supposed to be too difficult, right? The problem is, as unable as I am to find anything wrong with this, the land will not display. Here's my entire "land.cpp" file that all the land functions and all is stored in (I'm pretty sure the error is in the render function, but I don't know where):// Include. Lots and lots of includes#include <windows.h>#include <stdlib.h>#include <stdio.h>#include <gl/gl.h>#include <gl/glu.h>#include <gl/glaux.h>#include <math.h>#include "GLTex.h"#include "GLLandHM.h"#include "GLTex.h"// Constants#define BITMAP_ID 0x4D42// Universal bitmap header#define MAP_X 32// X size of the map#define MAP_Z 32// Z size fo the map#define MAP_SCALE 20.0f// The scale of the terrain map#define PI 3.14159// Constant value for Pi.// Prototypesunsigned char *LoadBMPForData(char *filename, BITMAPINFOHEADER *bitmapInfoHeader);// Globalsfloat radians = 0.0f;// Camera angle in radiansfloat waterheight = 154.0f;// Sea levelbool  waterDir = TRUE;// TRUE = up, FALSE = down// Mouse / Camera variablesfloat cameraX, cameraY, cameraZ; // Camera coordinatesfloat lookX, lookY, lookZ; // Camera look-at coordinates// Texture InfoBITMAPINFOHEADER bitmapInfoHeader;// Temporary info headerBITMAPINFOHEADER landInfo;// Land info headerBITMAPINFOHEADER waterInfo;// Water texture info headerunsigned char *landTexture;// Land texture dataunsigned char *waterTexture;// Water texture dataunsigned int   land;// Land texture objectunsigned int   water;// Water texture objectunsigned char *imgData = LoadBMPForData("Data/Land/Land1.bmp", &bitmapInfoHeader);// Terrain datafloat terrain[MAP_X][MAP_Z][3];// Heightfield terrain data// Initialize the terrain by looping through all heightfield pointsvoid InitTerrain(){for (int z = 0; z < MAP_Z; z++){for (int x = 0; x < MAP_X; x++){terrain[x][z][0] = float(x) * MAP_SCALE;terrain[x][z][1] = (float)imgData[(z * MAP_Z + x) * 3];terrain[x][z][2] = -float(z) * MAP_SCALE;}}}bool LoadTextures(){// Load Land Texture DatalandTexture = LoadBMPForData("Data/Land/LanTex.bmp", &landInfo);if (!landTexture){return FALSE;}// Load Water Texture DatawaterTexture = LoadBMPForData("Data/Land/WaterTex.bmp", &waterInfo);if (!waterTexture){return FALSE;}//Generate the land texture as a mipmapglGenTextures(1, &land;glBindTexture(GL_TEXTURE_2D, land);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, landInfo.biWidth, landInfo.biHeight, GL_RGB, GL_UNSIGNED_BYTE, landTexture);// Do the same for the water textureglGenTextures(1, &water);glBindTexture(GL_TEXTURE_2D, water);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, waterInfo.biWidth, waterInfo.biHeight, GL_RGB, GL_UNSIGNED_BYTE, waterTexture);return TRUE;}void RenderMap(int mouseX, int mouseY, float angle){radians = float(PI * (angle - 90.0f)/180.0f);// Calculate the camera's positioncameraX = lookX + sin(radians) * mouseY;// Moves camera incameraZ = lookZ + cos(radians) * mouseY;// Moves camera outcameraY = lookY + mouseY / 2.0f;// Calculate the camera look at coordinates (center of map)lookX = (MAP_X * MAP_SCALE) / 2.0f;lookY = 150.0f;lookZ = -(MAP_Z * MAP_SCALE) / 2.0f;// Clear the screen and depth bufferglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();// Set the camera position//gluLookAt (cameraX, cameraY, cameraZ, lookX, lookY, lookZ, 0.0, 1.0, 0.0);// Set texture as land textureglBindTexture(GL_TEXTURE_2D, land);// Loop through all terrain data points, draw one TSTRIP for each set on X axisglTranslatef (0.0f, 0.0f, -6.0f);for (int z = 0; z < MAP_Z - 1; z++){glBegin(GL_TRIANGLE_STRIP);for (int x = 0; x < MAP_X - 1; x++){// For each vertex, calculate the greyscale shade of the pixel, set the coordinate, and draw the vertex/*For reference, all vertexes are drawn in this order:0 ---> 1/ //    /  2 ---> 3*/// Draw vertex 0glColor3f(terrain[x][z][1] / 255.0f, terrain[x][z][1] / 255.0f, terrain[x][z][1] / 255.0f);glTexCoord2f(0.0f, 0.0f);glVertex3f(terrain[x][z][0], terrain[x][z][1], terrain[x][z][2]);// Draw vertex 1glTexCoord2f(1.0f, 0.0f);glColor3f(terrain[x + 1][z][1] / 255.0f, terrain[x + 1][z][1] / 255.0f, terrain[x + 1][z][1] / 255.0f);glVertex3f(terrain[x + 1][z][0], terrain[x+ 1][z][1], terrain[x + 1][z][2]);// Draw vertex 2glTexCoord2f(0.0f, 1.0f);glColor3f(terrain[x][z + 1][1] / 255.0f, terrain[x][z + 1][1] / 255.0f, terrain[x + 1][z][1] / 255.0f);glVertex3f(terrain[x][z + 1][0], terrain[x][z + 1][1], terrain[x][z + 1][2]);// Draw vertex 3glColor3f(terrain[x + 1][z + 1][1] / 255.0f, terrain[x + 1][z + 1][1] / 255.0f, terrain[x + 1][z + 1][1] / 255.0f);glTexCoord2f(1.0f, 1.0f);glVertex3f(terrain[x + 1][z + 1][0], terrain[x + 1][z + 1][1], terrain[x + 1][z + 1][2]);}glEnd();}// Enable blending for the waterglEnable(GL_BLEND);// Enable a read only depth bufferglDepthMask(GL_FALSE);// Set the blend function to what WE use for transparencyglBlendFunc(GL_SRC_ALPHA, GL_ONE);glColor4f(0.5f, 0.5f, 1.0f, 0.7f);glBindTexture(GL_TEXTURE_2D, water);// Draw the water as one big quad surfaceglBegin(GL_QUADS);glTexCoord2f(0.0f, 0.0f);glVertex3f(terrain[0][0][0], waterheight, terrain[0][0][2]);glTexCoord2f(10.0f, 0.0f);glVertex3f(terrain[MAP_X - 1][0][0], waterheight, terrain[0][0][2]);glTexCoord2f(10.0f, 10.0f);glVertex3f(terrain[MAP_X - 1][MAP_Z - 1][0], waterheight, terrain[MAP_X - 1][MAP_Z - 1][2]);glTexCoord2f(0.0f, 10.0f);glVertex3f(terrain[0][MAP_Z - 1][0], waterheight, terrain[0][MAP_Z - 1][2]);glEnd();glDepthMask(GL_TRUE);glDisable(GL_BLEND);// Animate the waterif (waterheight > 155.0f){waterDir = FALSE;}else if (waterheight < 154.0f){waterDir = TRUE;}if (waterDir){waterheight += 0.01f;}else{waterheight -= 0.01f;}glFlush();}I call the initializer once during my init function, and then call the render function from within the glRenderScene() function. In order not to confuse matters with the camera code, I commented it out and just translated into the screen 6 units. Help is very, VERY appreciated, I don't know why I'm having so much trouble with land (everything else was a relative piece of cake for me). Thanks.   -- Joe Teague[edited by - jtmoney55589 on August 2, 2003 11:25:46 PM]
quote:glTranslatef (0.0f, 0.0f, -6.0f); what is this for?quote:for (int z = 0; z < MAP_Z - 1; z++){glBegin(GL_TRIANGLE_STRIP);for (int x = 0; x < MAP_X - 1; x++){...glVertex3f(terrain[x][z][0], terrain[x][z][1], terrain[x][z][2]);...glVertex3f(terrain[x + 1][z][0], terrain[x+ 1][z][1], terrain[x + 1][z][2]);...glVertex3f(terrain[x][z + 1][0], terrain[x][z + 1][1], terrain[x][z + 1][2]);...glVertex3f(terrain[x + 1][z + 1][0], terrain[x + 1][z + 1][1], terrain[x + 1][z + 1][2]);}glEnd();  ...?? why do you set FOUR vertices? using triangle-strips you only need to set two each iteration...for(int z=0; z < MAP_Z; z++) {  glBegin(GL_TRIANGLE_STRIP);  for(int x=0; x < MAP_X-1; x++)   {    ...    glVertex3f( (float)x, terrain[x][z][1], (float)z );    ...    glVertex3f( (float)x, terrain[x][z+1][1], (float)(z+1) );   }  glEnd(); }   [edited by - 666_1337 on August 3, 2003 10:42:03 AM];  Make sure the first triangle in the strip is drawn in a counter-clockwise order. Otherwise you may be looking at the back face which is culled. If you''re looking at the surface from above and iterating from left to right, the order of vertices should be like this (and yes, only two vertices per iteration):1357...2468... ;  Why is your gluLookAt commented out? Try actually pointing the camera at the terrain. 