height map from lesson 34

Hey all,

I’m working on Lesson 34 of the NeHe tutorial which is about heightmaps. I’m trying to adjust it by making the terrain look how I’d like it to look so I’m adding my own data to the data file to be read in.

If I don’t change the code and leave it as is from the tutorial, it works, but if I change the MAP_SIZE to be 8 (instead of 1024) and creat e an ascii file with 8 * 8 ascii characters (instead of the orig 1024 * 1024 size file), the map doesn’t appear.

Anyone have an idea what I’m doing wrong?


private static final int MAP_SIZE = 8;
private byte[] heightMap = new byte[MAP_SIZE * MAP_SIZE];

private void loadTerrainFile(String fileName, byte[] pHeightMap) throws IOException {
    FileInputStream inputStream = new FileInputStream(fileName);
    
    int bytesRead = 0;
    int bytesToRead = pHeightMap.length;
        
    while (bytesToRead > 0) {
        int read = inputStream.read(pHeightMap, bytesRead, bytesToRead);
            
        bytesRead += read;
        bytesToRead -= read;
    }

    inputStream.close();
        
    for (int i = 0; i < pHeightMap.length; i++) {
        pHeightMap[i] &= 0xFF;
    }
}

This is my data file …


aaaaaaaaccccccccggggggggllllllllrrrrrrrrssssssssttttttttzzzzzzzz

It seems like such a simple change, I don’t know why it stopped working.

The nehe example has a STEP_SIZE, and the central rendering loop will abort early if your MAP_SIZE is smaller than your STEP_SIZE. Check the last two lines of code

void RenderHeightMap(byte[] pHeightMap ){              // This Renders The Height Map As Quads

    int X = 0, Y = 0;                                    // Create Some Variables To Walk The Array With.
    int x, y, z;                                         // Create Some Variables For Readability

    if(bRender)                                          // What We Want To Render
      gl.glBegin(gl.GL_QUADS );                          // Render Polygons
    else
      gl.glBegin(gl.GL_LINES );                          // Render Lines Instead

    for( X = 0; X < (MAP_SIZE-STEP_SIZE); X += STEP_SIZE )
      for( Y = 0; Y < (MAP_SIZE-STEP_SIZE); Y += STEP_SIZE ){