Skip to main content
gamedev.net
🔒 Locked

Height mapping problems.

Started by Mithoric 1 reply 650+ views
Original Post
Mithoric
Mithoric
Ok I've never height mapped beofore .. I've read the NeHe tutorials plus quite a few others and searched the forums a bit but I can't seem to get my height mapper working correctly. I'm trying to load from a raw file and then generate the terrain into a display list.

FILE *pFile = NULL;
	pFile = fopen( filename, "rb" );
    
    this->HeightMap = (float*)malloc( sizeof( float ) * ( width * height ) );
    
    if( this->HeightMap == NULL ) {
        MessageBox( NULL, "Unable to allocate memory!", "Error", MB_OK );
        return false;
    }    
    
	if ( pFile == NULL ) {
		MessageBox(NULL, "Can't Find The Height Map!", "Error", MB_OK);
		return false;
	}

	fread( this->HeightMap, 1, width*height, pFile );

	int result = ferror( pFile );
	if (result)	{
		MessageBox(NULL, "Failed To Get Data!", "Error", MB_OK);
		return false;
	}
	fclose(pFile);
	
	this->List = glGenLists( 1 );
    glNewList( this->List, GL_COMPILE );
    
    for( int z = 0; z < height; z++ ) {
      glBegin( GL_TRIANGLE_STRIP );
      for( int x = 0; x < width; x++ ) {
        glVertex3f( x * step, 1.0f, z * step );
        glVertex3f( x * step, 1.0f/this->HeightMap[ z + ( x * width ) ], z * step + step );
        glVertex3f( x * step + step, 1.0f/this->HeightMap[ z + ( x * width ) ], z * step  + step );
        glVertex3f( x * step + step, 1.0f, z * step );
        glVertex3f( x * step, 1.0f, z * step );
      }
      glEnd();
    }
    
    glEndList();
I'm pretty sure my tstrips are right, but for some reason I am getting massive heights on every strip.
VolkerG
VolkerG
Why are you using the reciprocal of the height value? You get infinity for each height value of 0.
Mithoric
Mithoric
Doh, didn't realise that. I am still not getting the height mapped properly though. I figure I'm just not putting the height values in the right spot.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.