Sign in to follow this  
johnnyBravo

Why won't my vb draw?

Recommended Posts

Hi, I'm trying to draw a triangle, if I use only positions, eg with 3 D3DXVECTOR3, it draws fine, but as soon as I try to add say something like texture coordinates, it just doesn't draw. eg
struct V{D3DXVECTOR3 p;float tu,tv;};
V v[] = {
	{D3DXVECTOR3(1,-1,1),0,0}, 
	{D3DXVECTOR3(1,1,1),0,0},	
	{D3DXVECTOR3(1,-1,-1),0,0},
};

void* pV = 0;
vb->Lock(0, 0, (void**)&pV, D3DLOCK_DISCARD);
memcpy(pV, v, sizeof(v));
vb->Unlock();

D3DVERTEXELEMENT9 meshVe[] = {
	{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
	{0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
	D3DDECL_END()
};

LPDIRECT3DVERTEXDECLARATION9 meshVd;
device->CreateVertexDeclaration(meshVe, &meshVd);
device->SetVertexDeclaration(meshVd);

device->SetStreamSource(0, vb, 0, sizeof(V));
device->SetTexture(0,0);
				
device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);	
meshVd->Release();



Any ideas? thx [Edited by - johnnyBravo on April 30, 2006 4:50:09 AM]

Share this post


Link to post
Share on other sites
Hi there,

I haven't used vertex decl. before. But I am checking the SDK docs right now.


typedef struct D3DVERTEXELEMENT9 {
WORD Stream;
WORD Offset;
BYTE Type;
BYTE Method;
BYTE Usage;
BYTE UsageIndex;
} D3DVERTEXELEMENT9, *LPD3DVERTEXELEMENT9;





I dont think you specified the correct offset for your texture coordinates.

Just a guess, but try doing this instead:


D3DVERTEXELEMENT9 meshVe[] = {
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, sizeof(D3DXVECTOR3), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END()
};





- Pure

Share this post


Link to post
Share on other sites

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