Jump to content
  • Advertisement
Sign in to follow this  

D3D9 Is not rendering the whole mesh

This topic is 2216 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Right after I post it I found my mistake. I was not setting proper size of the index buffer... Didn't notice it take size instead of count. After whole day debugging.

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[] =
}; // 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->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
void Renderer9::VSetDeclaration(D3DVERTEXELEMENT9 * vd)
IDirect3DVertexDeclaration9 * vdp;
DXUTGetD3D9Device()->CreateVertexDeclaration(vd, &vdp);
void Renderer9::VBeginScene()
void Renderer9::VEndScene()

void Renderer9::VDrawMesh(RE_Mesh * mesh)
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)
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);
void Renderer9::VUpdateVertexBuffer(RE_Mesh * mesh)
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);

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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!