Sign in to follow this  

Problem with Drawing the same primitive twice.

This topic is 4257 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.


Share this post


Link to post
Share on other sites

This topic is 4257 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this