How to draw two separate rectangles in DirectX using the primitive type D3DPT_TRIANGLESTRIP

I'm new to DirectX, and I'm trying to draw two rectangles in the same scene using D3DPT_TRIANGLESTRIP. One rectangle is not a problem, but two rectangles is a completely different ball game. Yes, I could draw them using four triangles drawn using a primitive type D3DPT_TRIANGLELIST. My curiosity is about using technology D3DPT_TRIANGLESTRIP. The parts of the code that I use for one rectangle with D3DPT_TRIANGLESTRIPare the following:

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 life 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 this ...

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 by changing the x and y values ​​on the user vertex and creating another vertex buffer, and this will work.

, , 100 - . , . , : D3DPT_TRIANGLESTRIP? ?

+3
4

, DrawPrimitive.

g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 4, 2 );
+1

- , .

.. 0, 1, 2, 3, 3, 4, 4, 5, 6, 7

0, 1, 2 - 1, 2, 3 - 2, 3, 3 - 3, 3, 4 - 3, 4, 4 - 4, 4, 5 - 4, 5, 6 - 5, 6, 7

2, 3, 3 - 3, 3, 4 - 3, 4, 4 4, 4, 5 . , , DrawIndexedPrimitive.

, , 10 . 12 . , , , .

..

0, 1, 2, 3, 0, 2, 4, 5, 6, 7, 4, 6

4 ( , , GeForce 3!), , , . - DX8 (.. DX9 10) , , , .

, ", : D3DPT_TRIANGLESTRIP?" , D3DPT_TRIANGLELIST :)

+3

recVertex 8 . . 3D-, . , .

100 ( , " " ) , meshes.

+1

, . , , /, , . , .

, , .

0

Source: https://habr.com/ru/post/1716272/


All Articles