hm...i downloaded this sample:
Simple Vertex & Pixel Shader (HLSL)
from here:
http://www.codesampler.com/dx9src/dx9src_8.htm#dx9_hlsl_fx_simplecause it works....i tryed to add it to my code:
void initShader( void )
{
//
// Create a test texture for our effect to use...
//
//D3DXCreateTextureFromFile( g_pd3dDevice, "test.bmp", &g_pTexture );
//
// Create a HLSL based vertex shader.
//
//
// If your program uses explicit binding semantics (like this one),
// you can create a vertex declaration using those semantics.
//
D3DVERTEXELEMENT9 declaration[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
{ 0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};
g_pd3dDevice->CreateVertexDeclaration( declaration, &g_pVertexDeclaration );
HRESULT hr;
LPD3DXBUFFER pCode;
DWORD dwShaderFlags = 0;
LPD3DXBUFFER pBufferErrors = NULL;
// Assemble the vertex shader from the file
hr = D3DXCompileShaderFromFile( "vertex_shader.vsh", NULL, NULL, "main",
"vs_2_0", dwShaderFlags, &pCode,
&pBufferErrors, &g_pConstantTableVS );
if( FAILED(hr) )
{
LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();
MessageBox(NULL, (const char*)pCompilErrors, "Vertex Shader Compile Error",
MB_OK|MB_ICONEXCLAMATION);
}
// Create the vertex shader
g_pd3dDevice->CreateVertexShader( (DWORD*)pCode->GetBufferPointer(),
&g_pVertexShader );
pCode->Release();
//
// Create a HLSL based pixel shader.
//
// Assemble the vertex shader from the file
hr = D3DXCompileShaderFromFile( "pixel_shader.psh", NULL, NULL, "main",
"ps_2_0", dwShaderFlags, &pCode,
&pBufferErrors, &g_pConstantTablePS );
if( FAILED(hr) )
{
LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();
MessageBox(NULL, (const char*)pCompilErrors, "Pixel Shader Compile Error",
MB_OK|MB_ICONEXCLAMATION);
}
// Create the vertex shader
g_pd3dDevice->CreatePixelShader( (DWORD*)pCode->GetBufferPointer(),
&g_pPixelShader );
pCode->Release();
}than to render:
for(int b =1;b<MeshCount+1;b++)
{
for( DWORD i = 0; i < g_dwNumMaterials[b]; i++ )
{
if( g_bUseShaders == true )
{
//
// Use vertex and pixel shaders...
//
D3DXMATRIX worldViewProjection = matWorld * matView * g_matProj;
g_pConstantTableVS->SetMatrix( g_pd3dDevice, "worldViewProj", &worldViewProjection );
g_pd3dDevice->SetVertexDeclaration( g_pVertexDeclaration );
g_pd3dDevice->SetVertexShader( g_pVertexShader );
// Set the material and texture for this subset
// shiftTextureCoordinates(g_pMesh[b]);
// Draw the mesh subset
//g_pd3dDevice->SetTexture(0, g_baseTexture);
g_pd3dDevice->SetPixelShader( g_pPixelShader );
g_pd3dDevice->SetMaterial( &entity[b].g_pMeshMaterials[i] );
g_pd3dDevice->SetTexture( 0,entity[b].g_pMeshTextures[i] );
g_pMesh[b]->DrawSubset( i );
}
}
in sample everything works, in my program mesh doesn't draw. I don't think that i'll find better code than this one...what i missed?