//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();
}
heightmap with triangle strips
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.
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.
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.
//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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement