I am new to DirectX and I am trying to draw two rectangles in one scene using D3DPT_TRIANGLESTRIP
. One Rectangle is no problem but two Rectangles is a whole different ball game. Yes i could draw them using four triangles drawn with the D3DPT_TRIANGLELIST
primitive type. My curiosity is on the technic involved using D3DPT_TRIANGLESTRIP
.
Parts of the code i am using for one Rectangle using D3DPT_TRIANGLESTRIP
is as follows:
CUSTOMVERTEX recVertex[] = {
{ 10.0f, 10.0f, 0.10f, 1.0f, 0xffffffff, }, // x, y, z, rhw, color
{ 220.0f, 10.0f, 0.10f, 1.0f, 0xffffffff, },
{ 10.0f, 440.0f, 0.10f, 1.0f, 0xffffffff, },
{ 220.0f, 440.0f, 0.10f, 1.0f, 0xffffffff, },
};
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 4 * sizeof( CUSTOMVERTEX ),
0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}
More vital code...
VOID* precVertex;
if( FAILED( g_pVB->Lock( 0, sizeof( recVertex ), ( void** )&pGameField, 0 ) ) )
{
return E_FAIL;
}
memcpy( precVertex, recVertex, sizeof( recVertex ) );
then Render like so...
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
Based on this model I could easily duplicate the code change the x and y values on the Custom Vertex and create another vertex buffer and it would work.
Personally i feel this is not the best way to go especially considering a situation when i have to draw say 100 rectangles or something like that. The thing is, I don't have other ideas. So my question is, what is the most efficient way to draw two Rectangles with D3DPT_TRIANGLESTRIP
? Also is there a possible way of duplicating and transforming the current rectangle?