LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;
struct CUSTOMVERTEXRHW {FLOAT X, Y, Z, RHW; DWORD COLOR;};
#define CUSTOMFVFRHW (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
[code]
CUSTOMVERTEXRHW vertices[] =
{
{ 400.0f, 62.5f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
{ 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
{ 150.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
};
// create a vertex buffer interface called v_buffer
d3ddev->CreateVertexBuffer(3*sizeof(CUSTOMVERTEXRHW),
0,
CUSTOMFVFRHW,
D3DPOOL_MANAGED,
&v_buffer,
NULL);
VOID* pVoid; // a void pointer
// lock v_buffer and load the vertices into it
v_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, vertices, sizeof(vertices));
v_buffer->Unlock();
D3DXCreateEffectFromFile(d3ddev, "simple.fx", 0, 0, 0, 0, &g_effect, &errorlog);
g_effect->FindNextValidTechnique(NULL, &technique);
[/code]
[code]
in rendering
D3DXMATRIX matWorld;
D3DXMatrixIdentity(&matWorld);
p_effect->SetMatrix("Projection", &matProjection);
p_effect->SetMatrix("View", &matView);
p_effect->SetMatrix("World", &(matWorld));
d3ddev->SetFVF(CUSTOMFVFRHW);
d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEXRHW));
d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
p_effect->EndPass(); // end the pass
p_effect->End(); // end the effect
//shader .fx
float4x4 World;
float4x4 View;
float4x4 Projection;
struct VertexOut
{
float4 Pos : POSITION;
float4 Color : COLOR;
};
VertexOut VShader(float4 Pos : POSITION)
{
VertexOut Vert = (VertexOut)0;
float4x4 Transform;
Transform = mul(World, View);
Transform = mul(Transform, Projection);
Vert.Pos = mul(Pos, Transform);
Vert.Color = float4(1, 0, 0, 0); //returns red
return Vert;
}
technique FirstTechnique
{
pass FirstPass
{
VertexShader = compile vs_2_0 VShader();
}
}
what am i doing wrong?







