I obviously forgot some code.. First of all I'm using this vertex structure with a correct vertex declaration. CreateVertexDeclaration returns S_OK.
struct vertex
{
float x, y, z, w;
float r, g, b, a;
float u, v;
};
static D3DVERTEXELEMENT9 elements[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, sizeof(float) * 4, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
{ 0, sizeof(float) * 8, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};
On each new frame, I call:
_device->BeginScene();
math::matrix4x4 identity;
identity.identity();
_device->SetTransform( D3DTS_WORLD, reinterpret_cast<D3DMATRIX*>( &identity ) );
_device->SetTransform( D3DTS_VIEW, reinterpret_cast<D3DMATRIX*>( &identity ) );
_device->SetTransform( D3DTS_PROJECTION, reinterpret_cast<D3DMATRIX*>( &identity ) );
_device->SetRenderState( D3DRS_ZENABLE, FALSE );
_device->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
_device->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
_device->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
_device->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
_device->SetRenderState( D3DRS_ALPHAREF, 0x08 );
_device->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
_device->SetRenderState( D3DRS_LIGHTING, FALSE );
_device->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
_device->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
_device->SetRenderState( D3DRS_STENCILENABLE, FALSE );
_device->SetRenderState( D3DRS_CLIPPING, TRUE );
_device->SetRenderState( D3DRS_CLIPPLANEENABLE, FALSE );
_device->SetRenderState( D3DRS_VERTEXBLEND, D3DVBF_DISABLE );
_device->SetRenderState( D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE );
_device->SetRenderState( D3DRS_FOGENABLE, FALSE );
_device->SetRenderState( D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA );
_device->SetRenderState( D3DRS_MULTISAMPLEANTIALIAS, FALSE );
_device->SetRenderState( D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF );
_device->SetRenderState( D3DRS_ANTIALIASEDLINEENABLE, FALSE );
_device->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
_device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
_device->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
_device->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
_device->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
_device->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
_device->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );
_device->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
_device->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
_device->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
_device->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT );
_device->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );
_device->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE );
_device->SetVertexDeclaration( _decl );
And finally execute the command list before calling EndScene() and Present().
void execute_commands(
commandlist* commands ) override
{
auto cl = dynamic_cast<dx9_commandlist*>( commands );
auto pl = cl->pipeline();
_device->SetVertexShader( pl->vertex_shader() );
_device->SetPixelShader( pl->pixel_shader() );
auto pt = pl->type();
auto begin = cl->begin();
auto end = cl->end();
while( begin.base != end.base ) {
switch( begin.base->id ) {
case detail::cmdid::bind_viewports:
_device->SetViewport(&begin.bind_viewport->viewport);
begin.base = &begin.bind_viewport->next;
break;
case detail::cmdid::bind_render_targets:
_device->SetRenderTarget( begin.bind_render_targets->slot, begin.bind_render_targets->rts );
_device->SetDepthStencilSurface( begin.bind_render_targets->dss );
begin.base = &begin.bind_render_targets->next;
break;
// and some more commands but that's not the point I guess
case detail::cmdid::draw:
_device->DrawPrimitive( pt, begin.draw->vertex_offset, begin.draw->vertex_count );
begin.base = &begin.draw->next;
break;
case detail::cmdid::draw_indexed:
_device->DrawIndexedPrimitive(
pt,
begin.draw_indexed->vertex_offset,
0,
begin.draw_indexed->vertex_count,
begin.draw_indexed->index_offset,
begin.draw_indexed->index_count
);
begin.base = &begin.draw_indexed->next;
break;
}
}
}
Regards