# Problem with Drawing the same primitive twice.

## Recommended Posts

hello all. i'm trying to build 2 squares. i want to use the same veriable for both of them and just to Transform in the 2nd time i mean here is the code:
  g_pd3dDevice->SetStreamSource( 0, g_pTriangleList_VB, 0, sizeof(Vertex) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );

g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

D3DXMatrixTranslation( &mTrans, 2.0f, 0.0f, 0 );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &mTrans );
g_pd3dDevice->SetStreamSource( 0, g_pTriangleList_VB, 0, sizeof(Vertex) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );

g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );


for some reason i see only the first quad. anyone has any idea why this is happenning? thanks in advance

##### Share on other sites
I can't see how you set the transform for the first object, and also resetting stream source and FVF is redundant because they are the same for both objects. Would this help:

D3DXMATRIX mTrans;g_pd3dDevice->SetStreamSource( 0, g_pTriangleList_VB, 0, sizeof(Vertex) );g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );D3DXMatrixTranslation( &mTrans, 0.f, 0.f, 0.f );g_pd3dDevice->SetTransform( D3DTS_WORLD, &mTrans );g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );D3DXMatrixTranslation( &mTrans, 2.0f, 0.0f, 0 );g_pd3dDevice->SetTransform( D3DTS_WORLD, &mTrans );g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

##### Share on other sites
There is no need to set your rendering options again. If you strip out the unneeded code, you are left with:
Set the VB
Set the FVF
Draw 1st poly
Create matrix
Set world matrix
Draw 2nd poly

Assuming d3d doesn't mess up (pretty fair assumption), the only cause of the problem could be your world matrix. What does your world matrix start as? I noticed you simply set the world matrix instead of using device->MultiplyTransform(...). This function will add in the translation instead of replacing the world matrix. If your object is at (100, 0, 0), your way will set the object to (2, 0, 0). Using MultiplyTransform will move the object to (102, 0, 0). If you don't set the world matrix prior to your code, it would be the identity. In that case, I have no idea what could be the problem.

##### Share on other sites
nope, it didnt help at all.

##### Share on other sites
Clb is right. You are in a rendering loop, right? So, although it will default to the identity matrix until you do the "g_pd3dDevice->SetTransform( D3DTS_WORLD, &mTrans );" call, once you make that call both objects will be drawn in the same place. So you need to set the world matrix for each object every time before the DrawPrimitive call.

It is best not put instructions within the rendering loop that do not necessarily change every frame.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627638
• Total Posts
2978327

• 10
• 12
• 22
• 13
• 34