Hi,
I am working on a heightfield/heightmap. I have it so that It loads a RAW file and displays the appropriate points in 3D space using GL_POINTS, the problem now is that I cannot get it to show correctly as TRIANGLE_STRIPS. It does the height and the position on the Z axis, but it does not work on the X axis. My code is:
x = X;
y = Height(pHeightMap, X, Y );
z = Y;
glVertex3f(x, y, z);
x = X;
y = Height(pHeightMap, X, Y );
z = Y;
glVertex3f(x, y + STEP_SIZE, z);
x = X;
y = Height(pHeightMap, X, Y );
z = Y;
glVertex3f(x, y + STEP_SIZE, z + STEP_SIZE);
x = X;
y = Height(pHeightMap, X, Y );
z = Y;
glVertex3f(x , y, z + STEP_SIZE);
Like from the NEHE tuts, but they used QUADS and the effect was jagged. I have tried to arrange the vertices as they should be in a triangle strip, but it turns out as seen in the image:
With, hopefully, the x/z coordinates of the strips coinciding with eachother.
The thing is, the y coordinates, which you look up from the heightmap, are all the same, per quad.
(edit: just to clarify, you’re adding constants to the Y and Z coordinates in the glVertex call, but you should be adding constants in the heightmap lookup instead)
So you won’t get any interpolation between the strips. Either you’ll want to render an additional strip between neighbours, with different Y coordinates on the even and odd vertices, or you’ll want to do that for the individual strips. (in which case you probably should also send just two vertices per grid point - for symmetry).
There are two main possibilities: whether you create an algorithm that is capable to create directly strip triangles (that can be done with some maths), or whether you create an algorithm that is capable to transform all your NORMAL triangles into strip ones.
Both of them CANNOT be perfect, thus cannot produce one single array of strips. Some give a big strip array with several ‘dumb’ triangles, other give several little strips.
I’d like to add that Nvidia provided some stripifier. It also seems it’s totally free. Also have some researches on the net.
for(int z=0; z<m_iSize-1; z++ )
{
glBegin( GL_TRIANGLE_STRIP );
//loop through terrain X values
for( int x=0; x<m_iSize; x++ )
{
glVertex3f(x,Height(pHeightMap,x,z),z);
glVertex3f(x,Height(pHeightMap,x,x+1),z+1);
}
glEnd( );
}
i would put this in a display list if i where you,for static terain like this it will be faster than any other method
m_iSize is just the width/height of your heightmap
also i would like to add, if you are only rendering static terrain like above, don’t even waste your time trying to use indexed geometry …if you are using some sort of LOD than yeah u will be better of with indexed geometry
OK, I have done it, but I cannot see if it worked, I try rotating it but as you say I need display lists (it is a tad slow).
This is the function called to make the heightmap:
void RenderHeightMap(BYTE pHeightMap[])
I want to call this in my ‘Init’ function as a display list. I cannot get it to work. I have tried running the same function for the heightmap from within ‘Init’ with the glNewList(heightmap,GL_COMPILE);
and
glEndList();
around it.
I have tried putting those lines in the actual RenderHeightMap function. But it still comes up as nothing in my window. And yes I am calling it in my ‘Display’ Function.
The error I get is:
error C2065: ‘pHeightMap’ : undeclared identifier
And when I put the:
BYTE pHeightMap[]
above the glNewList it says that pHeightMap is an unknown value.