So this is the result. I'm trying to render a cube.(The cube has 3x3x2 triangles each face, but it is rendering only first row from top. (If culling = none -> it renders also the bottom of the cube, but still half top and walls are missing)
Cube is loaded from .ASE file. (I've made simple level editor loading ASE files a year ago. it could render the cube as it shoud. => file is OK. NOTE: I'm using effects for first time. The shader is just taking matrix(WolrdViewProj) and multiply it to the vertex. Then pixel shader just returns white color)
I've have tripple checked the data I put into the buffers. It is ok.
I think I'm not passing the right parameter somewhere. The whole source code, like always, can be found here: http://code.google.c.../ random-engine
However, I have tried to extract the code which I think is the problem, to make people's life easier:
D3DVERTEXELEMENT9 VertexPosElements[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
D3DDECL_END()
}; // I'm using array of D3DXVECTOR3 for the vertices
void CALLBACK RandomEngineApp::OnRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void *pUserContext )
{
Mat4x4 proj, view, world, rot; static float r = 0; r+= 0.007;
world = Mat4x4::g_Identity;
D3DXMatrixRotationY(&rot, r);
Vec4 v(3,2,3,1);
D3DXVec4Transform(&v, &v, &rot);
D3DXMatrixLookAtLH( &view, &Vec3(v.x,v.y,v.z), &D3DXVECTOR3(0,0,0), &D3DXVECTOR3(0,1,0) );
D3DXMatrixPerspectiveFovLH( &proj, D3DX_PI / 4, 1.33f, 0.01f , 1000.0f);
g_pApp->m_Renderer->VSetProjMatrix(&proj);
g_pApp->m_Renderer->VSetViewMatrix(&view);
g_pApp->m_Renderer->VSetWorldMatrix(&world);
g_pApp->m_Renderer->VClear();
g_pApp->m_Renderer->VBeginScene();
//g_pApp->GetLogic()->VOnRender();//this will be used later when I know what I am doing
g_pApp->GetRenderer()->VSetDeclaration(VertexPosElements); // vertex element declaration, this is something I have no idea if I'm doing it right
AssetDataPtr mesh(AssetManager::Get()->GetAssetData(Resource("box.ase\\box.ase"))->front()); // get the first mesh, found in box.ase, don't worry it is not parsing or loading it here
g_pApp->m_Renderer->VDrawMesh(dynamic_cast<RE_Mesh*>(mesh.get()));
g_pApp->m_Renderer->VEndScene();
}
void Renderer9::VSetDeclaration(D3DVERTEXELEMENT9 * vd)
{
IDirect3DVertexDeclaration9 * vdp;
DXUTGetD3D9Device()->CreateVertexDeclaration(vd, &vdp);
DXUTGetD3D9Device()->SetVertexDeclaration(vdp);
vdp->Release();
}
void Renderer9::VBeginScene()
{
DXUTGetD3D9Device()->BeginScene();
}
void Renderer9::VEndScene()
{
DXUTGetD3D9Device()->EndScene();
}
void Renderer9::VDrawMesh(RE_Mesh * mesh)
{
HRESULT hr;
D3DXMATRIXA16 WorldViewProj = m_World * m_View * m_Proj;
unsigned int passes;
hr = m_pREffect->SetTechnique("SimpleRender");
hr = m_pREffect->SetMatrix("c_WorldViewProj", &WorldViewProj);
hr = DXUTGetD3D9Device()->SetIndices(mesh->m_IB9);
hr = DXUTGetD3D9Device()->SetStreamSource(0, mesh->m_VB9, 0, sizeof(D3DXVECTOR3));
hr = m_pREffect->Begin(&passes, 0);
for(unsigned int iPass = 0; iPass < passes; iPass++)
{
hr = m_pREffect->BeginPass(iPass);
hr = ::DXUTGetD3D9Device()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mesh->m_Vertices.size(), 0, mesh->m_Indeces.size() / 3);
hr = m_pREffect->EndPass();
}
hr = m_pREffect->End();
}
void Renderer9::VUpdateIndexBuffer(RE_Mesh * mesh)
{
HRESULT hr;
if(mesh->m_IB9 == NULL)
{
hr = DXUTGetD3D9Device()->CreateIndexBuffer(mesh->m_Indeces.size(), D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &mesh->m_IB9, 0);
}
unsigned int * indeces = NULL;
mesh->m_IB9->Lock(0, mesh->m_Indeces.size(), (void **)&indeces, 0);
std::copy( mesh->m_Indeces.begin(), mesh->m_Indeces.end(), indeces);
mesh->m_IB9->Unlock();
}
void Renderer9::VUpdateVertexBuffer(RE_Mesh * mesh)
{
HRESULT hr;
if(mesh->m_VB9 == NULL)
{
hr = DXUTGetD3D9Device()->CreateVertexBuffer(mesh->m_Vertices.size() * sizeof(Vec3), D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &mesh->m_VB9, 0);
}
Vec3 * vertices = NULL;
mesh->m_VB9->Lock(0, mesh->m_Vertices.size() * sizeof(Vec3), (void **)&vertices, 0);
std::copy( mesh->m_Vertices.begin(), mesh->m_Vertices.end(), vertices);
mesh->m_VB9->Unlock();
}
also RE_Mesh is keeping the indeces and vertices in std::vector,If someone need more information and do not want to check the source cuz of the mess just ask. Thanks.
Edited by Nickie, 29 August 2012 - 09:00 AM.






