rendering using a vertexbuffer

Started by
2 comments, last by Locutusborg 15 years, 10 months ago
Hello, I am trying to render a mesh using a vertexbuffer and a stream. However, I get an empty screen after compiling. and also the following errormessage: First-chance exception at 0x7c812a5b in game.exe: Microsoft C++ exception: long at memory location 0x0012fcac.. I use this to get my vertexbuffer g_pMesh->GetVertexBuffer(&pVBuf); int groot = sizeof(pVBuf)/g_pMesh->GetNumVertices(); and this is my part of the renderfunction pD3DDevice9->SetStreamSource( 0, pVBuf, 0, groot ); pD3DDevice9->SetFVF( g_pMesh->GetFVF() ); pD3DDevice9->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, g_pMesh->GetNumVertices(),0, g_pMesh->GetNumVertices()/3 ); does anyone have an idea as to what I am doing wrong? THANK YOU!!!
Advertisement
Well first of all, there's a function that does this for you (ID3DXMesh::DrawSubset). Second, if you wanted to manually draw the vertex buffer yourself you're doing some things wrong.

-sizeof(pVBuf) doesn't give you the size of the vertex buffer. It returns you the size of the type of IDirect3DVertexBuffer9*, which is a pointer to a COM interface. Like all pointers, it will be 4 bytes on a 32-bit system and 8 on a 64-bit system. If you want the size of the vertex buffer, use IDirect3DVertexBuffer9::GetDesc and check the "Size" member of the struct.

-You don't need the size of the vertex buffer anyway, since you can get the vertex stride of a mesh by simply calling ID3DXMesh::GetNumBytesPerVertex.

-If you want to know the number of primitives in a mesh, use ID3DXMesh::GetNumFaces. The number of triangles in an indexed vertex buffer is not simply the number of vertices divided by 3 (the whole point of an indexed VB is that you can share vertices among triangles).
Thanks! This already helps a lot!

I already had the draw subset command working before, but I discarded it because I will need multiple instances of several meshes. To my knowledge that is not possible with drawsubset()

I am now trying to make the program work with a vertexbuffer and a single mesh, so I can expand it later to display more then one instance and eventualy do so for more meshes.

IS this the right way to do it, or is there a better way to it?

Thank you agian for the info
I did find a way to draw multilple instances. I made a structure that contains the position as a D3DVECTOR3. from there I use a pointer with a double array to identify mesh and subset, like this:

pointer[meshnumber][subsetnr]
then for each mesh i get the position and draw them in the render function.

Can anyone tell me if there is a more efficient way to do this?

Thank you!

This topic is closed to new replies.

Advertisement