Skip to main content
gamedev.net
🔒 Locked

Vertex Declarations?

Started by shaqdx 4 replies 1.1k views
Original Post
shaqdx
shaqdx
I'm having problems with declaring my vertex declarations. If I want to send 2 texture coordinates to my vertex shader how would I declare them. The code below is not working correctly (I'm not sure about the first 2 parameters for each). const D3DVERTEXELEMENT9 declQuad[4] = { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, {0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1}, D3DDECL_END() }; Also, would I need to specify more stream sources? At the moment I have, pd3dDevice->SetStreamSource(0, pVertexBuffer, 0, sizeof(QUADCUSTOMVERTEX)); My QUADCUSTOMVERTEX looks like this: struct QUADCUSTOMVERTEX { D3DXVECTOR3 position; float tu, tv; float col; }; QuadFVF = D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_TEX2; Thanks
circlesoft
circlesoft
Everything is correct with that declaration, except for the offset of the third element. Since a float2 is 8 bytes, it should be 12 + 8 = 20, not 24.
JohnBolton
JohnBolton
Also your third entry is D3DDECLTYPE_FLOAT2, but there is only 1 float.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Armadon
Armadon
Good morning Shaqdx,
How are you doing?

The Problem
Just to reiterate the previous poster's point. Circlesoft and JohnBolton.
Vertex Declaration: Offsets and size of floats.

The Solution
The Size of a float:
a float is 4 bytes in size.
2 floats is 2 x 4 bytes.
so float2 is 8 bytes.

The second parameter of a vertex declaration: Offset
Offset from the beginning of the vertex data to the data associated with the particular data type.

The offset should be the offset from the beginning of the vertex element to the beginning of the data.

So your vertex declaration should be
e.g.
const D3DVERTEXELEMENT9 declQuad[4] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},

{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},

{0, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},

D3DDECL_END()
};

Custom Vertex Structure
Your structure should reflect the vertex declaration.
You should have 1 set of postitional coordinates and 2 sets of texture coordinates.
struct QUADCUSTOMVERTEX
{
D3DXVECTOR3 position;
float u1, v1;
float u2, v2;
};
QuadFVF = D3DFVF_XYZ|D3DFVF_TEX2;

I hope this helps. Thanks to circlesoft and johnbolton for their quick replies.

EDIT: Fixed the TEX2 vertex format. Sorry about that guys, I wasn't paying attention.

[Edited by - Armadon on September 27, 2005 12:01:23 PM]
shaqdx
shaqdx
That's brilliant!

Thanks everyone.
Namethatnobodyelsetook
Namethatnobodyelsetook
Quote:
Original post by Armadon
QuadFVF = D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_TEX2;

This should just be D3DFVF_XYZ|D3DFVF_TEX2. The way it works out you've specified the equivilent of TEX3.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.