Sign in to follow this  

heightmap with triangle strips

This topic is 4591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to render a heightmap using triangle strips and it currently does work sort of... The problem I am having is that I am getting gaps between my rows and I know this due to the way I am rending the heightmap. What I want is one height * width area of triangles. I am sure there is a simple solution I just can't seem to come up with it.
//tga is pointer to a Targa image class
//imageData is a GLubyte array containing the pixel data 
//each pixel is a GLubyte between 0 and 255 (greyscale image)

GLint index = 0;
for( int z = 0; z < tga->height-1; z++)
{
  glBegin( GL_TRIANGLE_STRIP );
    glColor3f(0.0f,0.0f,1.0f );
    for( int x = 0; x < tga->width; x++ )
    {
      // the divide by 10 is just for scaling purposes
      glVertex3f( x,tga->imageData[index]/10.0f,z+1 );
      glVertex3f( x,tga->imageData[index+1]/10.0f,z );
      index++;
    }
  glEnd();	
}

Share this post


Link to post
Share on other sites
No, you really want height*width*2 triangles.
Each section of your square heightmap is made of quads.
each quad is 2 triangles. therefore, the area (in quads) is width*height.
The area(in triangles) is width*height*2.

Work with that a little...I don't have the brainpower left today to fix your code for you.

Another problem I see is that you dont have any way of interpolating or making sure the edges connect.
I would fix this. That should fix your problem. Look up a heightmap article on gamedev..I am sure there are hundreds.

Share this post


Link to post
Share on other sites
//tga is pointer to a Targa image class
//imageData is a GLubyte array containing the pixel data
//each pixel is a GLubyte between 0 and 255 (greyscale image)

GLint index = 0;
for( int z = 0; z < tga->height-1; z++)
{
glBegin( GL_TRIANGLE_STRIP );
glColor3f(0.0f,0.0f,1.0f );
for( int x = 0; x < tga->width; x++ )
{
// the divide by 10 is just for scaling purposes
glVertex3f( x,tga->imageData[index]/10.0f,z+1 );
glVertex3f( x,tga->imageData[index+width]/10.0f,z );
index++;
}
glEnd();
}

Try that.

Enigma

Share this post


Link to post
Share on other sites

This topic is 4591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this