Sign in to follow this  
sunrisefe

how to guarantee the right vertex-buffer?

Recommended Posts

I create a teapot through:D3DXCreateTeapot(Device, &Teapot, 0);. I want to change the vertex format through Flexible Vertex Format which is:
 struct sBlendVertex
{
	D3DXVECTOR3 pos;
	float	    blend;
	D3DXVECTOR3 normal;


};
#define BLEND_VERTEX_FVF (D3DFVF_XYZB1 | D3DFVF_NORMAL)
Then I use the BLEND_VERTEX_FVF to clone the teapot mesh to vertextBlendTeapot mesh and set according blend value for vertextBlendTeapot. Now my problem is: how to let the Device know that my current vertex buffer is vertextBlendTeapot's?

Share this post


Link to post
Share on other sites
When you call ID3DXMesh::DrawSubset, it'll set the vertex buffer as current. If you want to explicitly do that yourself (For if you're not calling DrawSubset()), you can call ID3DXMesh::GetVertexBuffer(), then IDirect3DDevice9::SetStreamSource() (Then Release() the vertex buffer).

Share this post


Link to post
Share on other sites
Thank you Evil Steve.
when call D3DXCreateCylinder() or D3DXCreateTeapot(), what 's the vertex format of the generated mesh?
BTW, is my vertex shader right when used to do vertex-blending(just one blending weight and two blend matrix).

matrix ViewProjMatrix;

matrix blend_matrix_1;
matrix blend_matrix_2;
vector Color;


//
// Input and Output structures.
//

struct VS_INPUT
{
vector position : POSITION;
float bendWeights : BLENDWEIGHT;
vector normal : NORMAL;
};

struct VS_OUTPUT
{
vector position : POSITION;
vector color : COLOR;
};

//
// Main
//

VS_OUTPUT Main(VS_INPUT input)
{
VS_OUTPUT output = (VS_OUTPUT)0;

vector tempPos;

tempPos=mul(input.position, blend_matrix_1)*input.bendWeights +
mul(input.position, blend_matrix_2)*(1-input.bendWeights);

tempPos.w=1;

output.position = mul(tempPos, ViewProjMatrix);
output.color = Color;

return output;
}



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