tri-strips problem

I have an array 5 x 5 which holds heightmap values. I’m using this to draw a terrain 4 x 4 using triangle strips. (25 vertices)

This is what it looks like just now: http://vault101.tripod.com/images/tristrips1.jpg

The trouble is, there are some extra lines/triangles being drawn, which causes the terrain to look corrupt.

It supposed to look like this: (played about with it in photoshop!) http://vault101.tripod.com/images/tristrips2.jpg

Is there a simple answer to this? Has anyone come across this before? I’m drawing the tri-strips like you would mow the lawn - down, turn, up, turn, down, etc

Thanks in advance!

This problem is easily overcome. What you need to do is at the end of each row of triangles, you will need to have proxy triangles which are 0 in width, so that they are invisible. This will allow you to go onto the next row without having to start a new glBegin(GL_TRIANGLE_STRIP); and you will not have the artefact triangle stretching across the entire terrain.

Basically, by proxy triangles, I mean you will have to repeat the last index of each row twice, and repeat the first index of each row twice, this way you will move onto the next row with a triangle which is 0 in widtgh and thus invisible. I hope I explained it well enough, if you dont understand, say so and ill see if i can do better :slight_smile:

Well, I’m not sure if it is worth the pain to have only one strip… Adding invisible triangles is not likely to improve performance.

Why not do several strips ?

MrShoe, I’m not starting a new Triangle strip at every row:

glBegin ( GL_TRIANGLE_STRIP );
for (all values along the X axis)
{
if (switchSide)
{
for (all values of Y in reverse)
{
draw 1st triangle
draw 2nd triangle
}
}else{
for (all values of Y)
{
draw 1st triangle
draw 2nd triangle
}
}
switchSide = !switchSide;
}
glEnd();

The curious thing is, if I draw a heightmap 256*256, this problem doesn’t occur.

I’m basically implementing a PVS system (potentially visible sets) to break the terrain into smaller chunks.

==PVS Code==

for (each PVS ‘chunk’ of terrain)
{

glBegin ( GL_TRIANGLE_STRIP );
for (all values along the X axis)
{
if (switchSide)
{
for (all values of Y in reverse)
{
draw 1st triangle
draw 2nd triangle
}
}else{
for (all values of Y)
{
draw 1st triangle
draw 2nd triangle
}
}

switchSide = !switchSide;
}
glEnd();

}

The smaller chunks render fine, together or separately, but some of the chunks have this problem. ? stumped! ?

[This message has been edited by targe (edited 02-08-2004).]

To illustrate the PVS part in action, below is a 16x16 terrain (17x17 verts) split into 16 PVS
chunks of 4x4 (5x5 verts) each:
http://vault101.tripod.com/images/tristrips3.jpg

Looks ok, but on closer inspection, there are some triangle artifacts on some of the ‘seams’:
http://vault101.tripod.com/images/tristrips4.jpg

The original pic I posted was of PVS chunk 7 alone: http://vault101.tripod.com/images/tristrips1.jpg

ok, i don’t think PVS has anything to do with it as I’ve noticed the same can happen when rendering a single large section where adjacent strips are at different heights.

I thought the vertex drawing order might have something to do with it:

(sorry about the poor ascii!)
2–1 1112
\
\
\
\
4–3 9-10
\
\
\
\
6–5 7–8

So i changed it to draw the strips ending/starting on the same vertex. (i.e. strip 1 - new vert 6 becomes vert 5’s position in the above diagram, and then when strip2 starts from vert 7, it hasn’t moved)

Anyway, this didn’t resolve the issue! :- http://vault101.tripod.com/images/tristrips5.jpg

If anyone can help with this I’d be very grateful!

[This message has been edited by targe (edited 02-08-2004).]

The reason why you wouldnt want to start a new strip every row is because if you do you cant use vertex buffers, which speed up performance ALOT. a few invisible triangles is nothing compared to the speed boost from VBO’s
Anyway, here is a better fuller explanation, note also that I couldnt actually look at the pics of the problem in action, so im not sure if im going on about the right thing, but i suspect i am :slight_smile:

Ok, lets remember how triangle strips work. when you specify a new vertex, it will
make a triangle whose verteces are that vertex and the last two specified verteces.

Now, lets have a look at a terrain grid:

. . . .

. . . .

. . . .

number the verteces 1 throught to 12 from left to right top to bottom.
Now, say your rendering the terrain like this:
Enable triangle strips, look through the verteces like this:
1, 5, 2, 6, 3, 7, 4, 8, // end of first row of verteces, onto the next row
5, 9, 6, 10, 7, 11, 8, 12 // finished

I expect that this is kind of what you have been doing. This method will however
produce 1 long triangle stretching across the mesh. This is because, once at the end
of the first row we call verteces 4 and 8, we then call vertex 5, so this forms a
triangle, then there will be another triangle with verteces 8, 5, 9, since 9 is the
next vertex called.
To get rid of this you will have to insert incisivible triangles at the end of each row,
so your vertex calls will look like this:
1, 5, 2, 6, 3, 7, 4, 8, 8
5, 5, 9, 6, 10, 7, 11, 8, 12
Now, you still will be drawing 2 triangles across the entire mesh, but they will be invisible
since their width will be 0

Id like to caution you however that you might have problems with this and back face culling,
since doing this will make the 2nd row ccw if the first row is cw. To fix this, just do:
1, 5, 2, 6, 3, 7, 4, 8, 8, 8
5, 5, 9, 6, 10, 7, 11, 8, 12
Dont worry if you dont understand that last bit about backface culling, jsut i had that same
problem only recently.