Problem with Drawing the same primitive twice.

Started by
3 comments, last by DXnut 18 years ago
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
Advertisement
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 );
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.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
nope, it didnt help at all.
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.


--------------------------Most of what I know came from Frank D. Luna's DirectX books

This topic is closed to new replies.

Advertisement