Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Draw Two Detached Rectangles in DirectX using the D3DPT_TRIANGLESTRIP Primitive Type
    text
    copied!<p>I am new to DirectX and I am trying to draw two rectangles in one scene using <code>D3DPT_TRIANGLESTRIP</code>. 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 <code>D3DPT_TRIANGLELIST</code> primitive type. My curiosity is on the technic involved using <code>D3DPT_TRIANGLESTRIP</code>. Parts of the code i am using for one Rectangle using <code>D3DPT_TRIANGLESTRIP</code> is as follows:</p> <pre><code>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-&gt;CreateVertexBuffer( 4 * sizeof( CUSTOMVERTEX ), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &amp;g_pVB, NULL ) ) ) { return E_FAIL; } </code></pre> <p>More vital code...</p> <pre><code>VOID* precVertex; if( FAILED( g_pVB-&gt;Lock( 0, sizeof( recVertex ), ( void** )&amp;pGameField, 0 ) ) ) { return E_FAIL; } memcpy( precVertex, recVertex, sizeof( recVertex ) ); </code></pre> <p>then Render like so...</p> <pre><code>g_pd3dDevice-&gt;SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) ); g_pd3dDevice-&gt;SetFVF( D3DFVF_CUSTOMVERTEX ); g_pd3dDevice-&gt;DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 ); </code></pre> <p>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. </p> <p>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 <code>D3DPT_TRIANGLESTRIP</code>? Also is there a possible way of duplicating and transforming the current rectangle?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload