# vertices rendering incorrectly

This topic is 4909 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a problem with rendering the vertices properly. I’m using a vertex buffer with D3DPT_TRIANGLESTRIP for the rendering. My code first initializes a huge grid with two for loops. I believe that the code for the for loops may be inaccurately producing the vertex information also. I use the vertex buffer to render the entire grid. I believe there is some problem with how the vertices are interpreted during rendering. I believe that Direct3D dose not know where the triangle strip begins and ends besides the length of the vertex buffer in size. Do I have to draw each patch incrementally? Meaning, I loop through the mesh and draw 2 rows of vertices in the array at a time. If so, how do I do this? If not, then how do I render the mesh correctly.

##### Share on other sites
Are they rendering at all? Or are only some of them rendering?

You may want to take a look at how you create the vertices. Make sure that all of them are created, and that you don't accidentially overwrite some as they are created. This would occur in the algorithm you use to set each array member; it should be (for a grid; or something of the such):

ZCounter * XBound + XCounter + whatever vertex you're on.

Triangle strips are tricky. If nothing you try seems to work, you may want to consider using a list, then switching when you need more primitives.

For more help post code and/or a screen if you have one.

##### Share on other sites
Triangle Strips. Just pay very close attention to vertex ordering and all will be well.

##### Share on other sites
Here is the code I use to setup the vertices. The vertices are in a 2 dimensional array.

	if ( FAILED( hRet = g_lpD3DDevice->CreateVertexBuffer( 		LEVEL_WIDTH * LEVEL_DEPTH * sizeof( LEVEL_VERTEX ),		0,		D3DFVF_XYZ | D3DFVF_DIFFUSE,		D3DPOOL_DEFAULT,		&g_lpD3DLvlMesh,		NULL ) ) )	{		return hRet;	}	for ( int z = 0; z < LEVEL_DEPTH; z++ )	{		for ( int x = 0; x < LEVEL_WIDTH; x++ )		{			vLvlMesh[ x ][ z ].dwColor = D3DCOLOR_XRGB( 255, 255, 255 );			vLvlMesh[ x ][ z ].fX	   = x * LEVEL_QUAD_SIZE;			vLvlMesh[ x ][ z ].fY	   = LEVEL_HOVER;			vLvlMesh[ x ][ z ].fZ	   = z * LEVEL_QUAD_SIZE;		}	}	if ( FAILED( hRet = g_lpD3DLvlMesh->Lock( 0, sizeof( vLvlMesh ), ( void** )&lpVBMemPtr, 0 ) ) )	{		return hRet;	}	memcpy( lpVBMemPtr, vLvlMesh, sizeof( vLvlMesh ) );	g_lpD3DLvlMesh->Unlock( );

But now the computer is locking up, crashing, and restarting. The vertices were being drawn, but I would see just a little bit of the wire frame off to the side.

##### Share on other sites
I just had a thought. Maybe using a vertex buffer is a poor solution. I should use a 2 dimensional array and render the vertices as I go with IDirect3DDevice9::DrawPrimitiveUp. Then I could render and entire patch of triangle strips for each row in the array.

This solution would work better, correct? Because Direct3D doesn’t know were the triangle strips begin and end, so it will assume that the whole vertex buffer is one giant triangle strip, hence, render the mesh incorrectly.

An even better approach would be to render the mesh, only to a certain point. This way, I’m not forcing all these vertices down the pipeline that may be out of view or range. That vertex buffer is a waste of time.