Degenerate triangle strips and glDrawElements

Hi, I’m having a problem with glDrawElements. I’m trying to render some triangle strips, which are stitched together with degenerate triangles into one very big strip. That is, if I have a strip ABCD and another strip EFGH, they become ABCDDEEFEFGH which creates the degenerate triangles CDD, DDE, DEE, EEF, EFE, FEF. Using the loop below, I get tiny filaments where the degenerate triangles are positioned and they flicker as the scene is animated:

gl.glCullFace( GL.GL_FRONT );
gl.glBegin( GL.GL_TRIANGLE_STRIP );
for ( int i = 0; i < iCount; i++ ){
vInd = indices.get( i );
nx = normalCoords.get( vInd + 0 );
ny = normalCoords.get( vInd + 1 );
nz = normalCoords.get( vInd + 2 );
vx = vertexCoords.get( vInd + 0 );
vy = vertexCoords.get( vInd + 1 );
vz = vertexCoords.get( vInd + 2 );
gl.glNormal3d( nx, ny, nz );
gl.glVertex3d( vx, vy, vz );
}
gl.glEnd();

When I try to render exactly the same buffer with glDrawElements (which I’d rather use), I get large triangles drawn where there should be only degenerate triangles:

gl.glEnableClientState( GL.GL_VERTEX_ARRAY );
gl.glVertexPointer( 3, GL.GL_FLOAT, 0, vertexCoords );
gl.glEnableClientState( GL.GL_NORMAL_ARRAY );
gl.glNormalPointer( GL.GL_FLOAT, 0, normalCoords );
gl.glDrawElements( GL.GL_TRIANGLE_STRIP, iCount, GL.GL_UNSIGNED_INT, indices );

Why are the two methods producing different results; shouldn’t they be equivalent?

How should I set up my buffers to stitch together multiple triangle strips so that it can be used with glDrawElements? And out of curiosity, why are the filaments being produced in the first code example (shouldn’t degenerates just get culled straight away)?

Thanks for any light at all you can shed.

Hi
I might have missunderstod what you are trying to do, but to stich 2 triangle strips together, you only duplicate the last vertex from the first strip and the first vertex from the second strip. with the strips ABCD and EFGH that goes: ABCDDEEFGH. and that would produce 4 degenerate triangles: CDD, DDE, DEE and EEF (if i got it right :slight_smile: )

Hope that helps //
Gregof

Thanks Gregof; I think the extra two vertices in my ‘strip stitch’ are used for maintaining the correct winding order across strips.

The vertex array problem was a simple bug, and I fixed my filament problem by only smoothing polygons conditionally:

if ( GL_MULTISAMPLE_ARB is supported )
gl.glEnable( GL.GL_POLYGON_SMOOTH );

I advise you not to use triangle strips (just use GL_TRIANGLES), and hence not to bother with degenerate triangles. Save yourself a load of effort, and marvel at the complete lack of any difference in performance :slight_smile:

Cas :slight_smile:

I’m so glad you said that! I’ve been trying to figure out how to stripify on the fly from a z-sorted buffer. Don’t go there.

On a related note, any idea what’s the best way to apply a different texture to each side of a triangle - do all of the triangle’s vertices have to be specified twice with different texture coordinates each time? Surely there’s some way to cut down on that overhead?

Thanks.

Yes. However you won’t need to actually fill up the coordinate buffers twice; you can simply point the texture coordinates pointer at a different array and leave the vertex coordinate pointer where it is.

Cas :slight_smile:

Excellent. Thankyou.