🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Using index buffers

Started by
2 comments, last by d_rappo 22 years, 7 months ago
Hi, I''m having some problems using index buffers in my app. I modified the Matrices tutorial supplied with the DX8 SDK to use an index buffer in conjunction with the vertex buffer, but nothing appears on the screen when I run the app. I''ve gone over all of my function calls related to the index buffer (CreateIndexBuffer, LockIndexBuffer, Unlock, etc.), and I just can''t see where I have gone wrong. HRESULT InitGeometry() { ... int indices[3]; indices[0] = 0; indices[1] = 1; indices[2] = 2; // create the index buffer HRESULT hr = g_pd3dDevice->CreateIndexBuffer(sizeof(indices), D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_DEFAULT, & g_pIIndexBuffer); VOID * pData = NULL; hr = g_pIIndexBuffer->Lock(0, sizeof(int) * 3, (BYTE**) & pData, 0); memcpy(pData, indices, sizeof(indices)); hr = g_pIIndexBuffer->Unlock(); return S_OK; } void Render() { ... g_pd3dDevice->SetIndices(g_pIIndexBuffer, 0); g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, // min index in vertex buffer 3, // no. vertices 0, // start index in index buffer 1); // primitive count ... } If I comment out SetIndices and replace DrawIndexedPrimitive with the original DrawPrimitive function, the app works properly (the rotating triangle appears on the screen). If anybody can assist me I''d appreciate it. Many thanks David
Advertisement
are you sure you are indexing the correct vertices in order ?

try

SetRenderTarget (D3DRS_CULLMODE, D3DCULL_NONE);

if something shows up, then its an ordering error.
Hi,

Thanks for the advice. However, I don''t think that it is an ordering problem because I am only trying to render a single triangle (three vertices) - whichever way D3D connects the points it should end up with a triangle.

When the program tries to execute the IDirect3DDevice8::SetIndices() function in Render() it fails, returning D3DERR_INVALIDCALL, which according to the DirectX help files means that one of the methods paramaters contains an invalid value.

hr = g_pIDevice->SetIndices(g_pIIndexBuffer, 0);

I am not sure how this could be the case since the calls to IDirect3DDevice8::CreateIndexBuffer, IDirect3DIndexBuffer8::Lock, and IDirect3DIndexBuffer8::Unlock all succeed. Furthermore, I have checked that the indices have been copied into the index buffer.

I''ve read a couple of tutorials on using index buffers (including one that I got of gamedev called "DX8 Graphics & Video - A Fresh Start"), and none of them mention this problem.

If you (or anybody) can suggest anything, I''d really appreciate it - this thing is driving me nuts!

Thanks

David




Changing my indices from DWORD''s to WORD''s fixed things (D3DFMT_INDEX16).

Thanks again though

David

This topic is closed to new replies.

Advertisement