My DirectX C++ engine works fine with Sprites, Textures, etc. And this call to DrawPrimitiveUP works fine too:
device->DrawPrimitiveUP(D3DPT_LINESTRIP, 3, vertices, sizeof(Vertex));
So my next step is to use a shader, which I got out of a book:
const char * strShader =
"vs_1_1 \n"
"dcl_position v0 \n"
"dcl_color v1 \n"
"m4x4 oPos, v0, c0 \n"
"mov oD0, v1 \n"
"";
Here are my vertices:
Vertex vertices[] =
{
{20, 40, 0, D3DCOLOR_RGBA(0, 255, 255, 255)},
{40, 20, 0, D3DCOLOR_RGBA(255, 0, 0, 255)},
{60, 60, 0, D3DCOLOR_RGBA(0, 255, 255, 255)},
{20, 40, 0, D3DCOLOR_RGBA(0, 255, 255, 255)},
};
Using that Shader I attempt this code:
result = device->CreateVertexBuffer(
4 * sizeof(Vertex), 0, 0, D3DPOOL_DEFAULT, &mVertexBuffer, 0);
// lock the buffer to prepare for copying info into shader
mVertexBuffer->Lock(0, sizeof(vertices), (void**)&pVertices, 0);
memcpy(pVertices, vertices, sizeof(vertices));
mVertexBuffer->Unlock();
// Create the vertex declaration
D3DVERTEXELEMENT9 decl[]=
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
D3DDECL_END()
};
result = device->CreateVertexDeclaration(
decl, &mVertexDeclaration);
// ready to assemble the shader
result = D3DXAssembleShader(
strShader, (UINT)strlen(strShader), 0, 0, D3DXSHADER_DEBUG, &mShader, 0 );
// create a vertex shader
result = device->CreateVertexShader(
(DWORD*) mShader->GetBufferPointer(), &mVertexShader );
D3DXMatrixIdentity( &mMatWorld );
result = device->SetVertexShaderConstantF( 0, (float *)&mMatWorld, 4 );
result = device->SetVertexDeclaration( mVertexDeclaration );
result = device->SetVertexShader( mVertexShader );
result = device->SetStreamSource(0, mVertexBuffer, 0, sizeof(Vertex));
// now we get the magic list of triangles back from the shader!
result = device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
device->SetVertexShader( 0 );
device->SetTexture(0, NULL);
I check the result and it's fine all the way through, but my screen is empty!
Any clues?