Archived

This topic is now archived and is closed to further replies.

The_Fallen

Heightmap generation

Recommended Posts

The_Fallen    122
Hi, there is a strange problem with my heightmap generator. Look at this screenies: http://www.husser.de/wireframe.jpg http://www.husser.de/wireframe2.jpg The terrain looks nice, but there are some additional polygons under the terrain. It seems, that there are some polys that have vertices on opposite sides of the terrain. The heightmap loaded is of the size width*height pixels and the resulting vertices are written to a vertex buffer in the same order. Now I create the Index Buffer with the following code:
      
m_IndexCount = (width-1)*(height-1)*6;
m_Indices = new int[m_IndexCount];
int vert=0;
for (x=0; x<height-1; x++)
{
	for (y=0; y<width-1; y++)
	{
		m_Indices[vert++] = x*width+y;
		m_Indices[vert++] = x*width+y+1;
		m_Indices[vert++] = x*width+y+width;
		m_Indices[vert++] = x*width+y+1;
		m_Indices[vert++] = x*width+y+width+1;
		m_Indices[vert++] = x*width+y+width;
	}
}
      
In my current code, the heightmap is of size 257*257. It creates 2 triangles from every quad of 4 vertices. No optimization for triangle strips, cause I use a LOD algorithm, so I can't use it. Any ideas, what's wrong with the code? thx, fallen [edited by - The_Fallen on March 6, 2003 12:26:42 PM] [edited by - The_Fallen on March 6, 2003 12:36:43 PM]

Share this post


Link to post
Share on other sites
GreatOne    122
I''ve see this kind of thing before with my own terrain engine. How are you drawing the terrain, post your rendering code. It could be you aren''t stopping and starting the geometry rendering where you are supposed to (that''s what it was with mine).

-------------------
Realm Games Company

Share this post


Link to post
Share on other sites
The_Fallen    122
Something like this:


  
glEnableClientState(GL_VERTEX_ARRAY_RANGE_WITHOUT_FLUSH_NV);

glVertexPointer(3, GL_FLOAT, sizeof(P3DUtility::CVertex), m_AGPmemory);
glColorPointer (4, GL_FLOAT, sizeof(P3DUtility::CVertex), m_AGPmemory + sizeof(P3DMath::CVector3));

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);

glDrawElements(GL_TRIANGLES, m_IndexCount, GL_UNSIGNED_INT, m_Indices);

Share this post


Link to post
Share on other sites
TheZombie    122
If you were using quadstrips, I''d say it looks like you were drawing the entire terrain with one strip. At the end of each row the last vertex connects to the first vertex in the next row. The second picture seems to show the last vertex in the terrain connecting back to the first in the terrain.

Im not sure if you were saying you don''t use quadstrips or they are just not optimized, but when the same thing happened to me I ended up separating each row in the terrain into it''s own strip and drawing them that way.

Hope that helps in some way!

Share this post


Link to post
Share on other sites
GreatOne    122
No strips eh? Well, this is a tough one. Hmmm, it could be that you are drawing another set of triangles from one side of your height map all the way to the other. Try this on your loops (and other variations of subracting more than one):


  
m_IndexCount = (width-2)*(height-1)*6;m_Indices = new int[m_IndexCount];
int vert=0;
for (x=0; x<height-1; x++)
{
for (y=0; y<width-2; y++)
{
}
}


-------------------
Realm Games Company

[edited by - greatone on March 6, 2003 4:29:01 PM]

Share this post


Link to post
Share on other sites
The_Fallen    122
Thx, but I've already tried that... And I don't think, that that could be the problem.
The triangles are completely described within one loop and so the error should be there... I've already drawn a grid on a piece of paper (5x5 grid) and looped all the vertices by hand. No problem...

Ha, I found the problem... I've got 66049 indices and 64k is the limit...

[edited by - The_Fallen on March 6, 2003 5:53:29 PM]

Share this post


Link to post
Share on other sites