The technique is fine, I didn't post it as it's quite unnecessary. It uses version 3.0.
The HRESULT returns SUCCESS, already been there done that before I made the post.
Here is where I actually render the object
// The technique
technique Tech
{
pass pass1
{
vertexShader = compile vs_3_0 vs();
pixelShader = compile ps_3_0 ps();
CullMode = CCW;
FillMode = Solid;
}
}
// Rendering
IDirect3DDevice9* device = CEngine::getD3D9()->getDevice();
unsigned passes = 0;
pShader->Begin( &passes,0 );
pShader->SetMatrix( "gWorld",&worldMatrix); // Pass the world matrix
pShader->SetMatrix( "viewProj",&(cam * proj) ); // Pass the View and Projection
pShader->CommitChanges();
device->SetVertexDeclaration( _pVertDecl );
device->SetStreamSource( 0,_pVertBuff,0,_nVertStride );
for( unsigned i = 0;i < passes;++i )
{
pShader->BeginPass( i );
device->DrawPrimitive( D3DPT_TRIANGLELIST,0,_nNumVerts/3 );
pShader->EndPass();
}
pShader->End();
Initializing
D3DVERTEXELEMENT9 decl[] =
{
{ 0,0,D3DDECLTYPE_FLOAT3,D3DDECLMETHOD_DEFAULT,D3DDECLUSAGE_POSITION,0 },
{ 0,12,D3DDECLTYPE_FLOAT3,D3DDECLMETHOD_DEFAULT,D3DDECLUSAGE_NORMAL,0 },
D3DDECL_END()
};
unsigned vertSize = nNumVerts * nVertexSize;
device->CreateVertexBuffer( vertSize,0,0,D3DPOOL_DEFAULT,&_pVertBuff,0 );
device->CreateVertexDeclaration( decl,&_pVertDecl );
void* vram = nullptr;
_pVertBuff->Lock( 0,0,&vram,0 );
memcpy( vram,verts,vertSize );
_pVertBuff->Unlock();
// The actual verts in case you want to see that
// CUBE
float size = fWidth/2;
VERTEX_POSNORM verts[] =
{
{ Vector3( -size, size,-size ), Vector3( 0, 0,-1 ) }, // 0 Front Top Left
{ Vector3( size, size,-size ), Vector3( 0, 0,-1 ) }, // 1 Front Top Right
{ Vector3( size,-size,-size ), Vector3( 0, 0,-1 ) }, // 2 Front Bottom Right
{ Vector3( size,-size,-size ), Vector3( 0, 0,-1 ) }, // 2 Front Bottom Right
{ Vector3( -size,-size,-size ), Vector3( 0, 0,-1 ) }, // 3 Front Bottom Left
{ Vector3( -size, size,-size ), Vector3( 0, 0,-1 ) }, // 0 Front Top Left
{ Vector3( -size, size, size ), Vector3( 0, 0, 1 ) }, // 4 Back Top Left
{ Vector3( -size,-size, size ), Vector3( 0, 0, 1 ) }, // 7 Back Bottom Left
{ Vector3( size,-size, size ), Vector3( 0, 0, 1 ) }, // 6 Back Bottom Right
{ Vector3( size,-size, size ), Vector3( 0, 0, 1 ) }, // 6 Back Bottom Right
{ Vector3( size, size, size ), Vector3( 0, 0, 1 ) }, // 5 Back Top Right
{ Vector3( -size, size, size ), Vector3( 0, 0, 1 ) }, // 4 Back Top Left
{ Vector3( -size, size, size ), Vector3( -1, 0, 0 ) }, // 4 Back Top Left
{ Vector3( -size, size,-size ), Vector3( -1, 0, 0 ) }, // 0 Front Top Left
{ Vector3( -size,-size,-size ), Vector3( -1, 0, 0 ) }, // 3 Front Bottom Left
{ Vector3( -size,-size,-size ), Vector3( -1, 0, 0 ) }, // 3 Front Bottom Left
{ Vector3( -size,-size, size ), Vector3( -1, 0, 0 ) }, // 7 Back Bottom Left
{ Vector3( -size, size, size ), Vector3( -1, 0, 0 ) }, // 4 Back Top Left
{ Vector3( size, size,-size ), Vector3( 1, 0, 0 ) }, // 1 Front Top Right
{ Vector3( size, size, size ), Vector3( 1, 0, 0 ) }, // 5 Back Top Right
{ Vector3( size,-size, size ), Vector3( 1, 0, 0 ) }, // 6 Back Bottom Right
{ Vector3( size,-size, size ), Vector3( 1, 0, 0 ) }, // 6 Back Bottom Right
{ Vector3( size,-size,-size ), Vector3( 1, 0, 0 ) }, // 2 Front Bottom Right
{ Vector3( size, size,-size ), Vector3( 1, 0, 0 ) }, // 1 Front Top Right
{ Vector3( -size, size,-size ), Vector3( 0, 1, 0 ) }, // 0 Front Top Left
{ Vector3( -size, size, size ), Vector3( 0, 1, 0 ) }, // 4 Back Top Left
{ Vector3( size, size, size ), Vector3( 0, 1, 0 ) }, // 5 Back Top Right
{ Vector3( size, size, size ), Vector3( 0, 1, 0 ) }, // 5 Back Top Right
{ Vector3( size, size,-size ), Vector3( 0, 1, 0 ) }, // 1 Front Top Right
{ Vector3( -size, size,-size ), Vector3( 0, 1, 0 ) }, // 0 Front Top Left
{ Vector3( -size,-size,-size ), Vector3( 0,-1, 0 ) }, // 3 Front Bottom Left
{ Vector3( size,-size,-size ), Vector3( 0,-1, 0 ) }, // 2 Front Bottom Right
{ Vector3( size,-size, size ), Vector3( 0,-1, 0 ) }, // 6 Back Bottom Right
{ Vector3( size,-size, size ), Vector3( 0,-1, 0 ) }, // 6 Back Bottom Right
{ Vector3( -size,-size, size ), Vector3( 0,-1, 0 ) }, // 7 Back Bottom Left
{ Vector3( -size,-size,-size ), Vector3( 0,-1, 0 ) }, // 3 Front Bottom Left
};