Loading an MD2 without DrawPrimitiveUP

Started by
11 comments, last by Fuzztrek 21 years, 5 months ago
-
  pro_lpGMain->GetDevice()->CreateVertexBuffer(sizeof(SMesh), D3DUSAGE_WRITEONLY, D3DFVF_MODELVERTEX, D3DPOOL_MANAGED, &pro_VB);  

The 1st parameter should be the size of the WHOLE buffer in bytes. When you use sizeof( SMesh ), it'll typically return 16 bytes, which is the size of the vector object.

You should use : sizeof( MODELVERTEX ) * pro_date.vertex.size()

-

  memcpy(vb_verts, pro_data, sizeof(pro_data));  


pro_data - as far as I see - is an array ( dynamic? ) that contains vertex data for ALL frames. The data for each frame is stored in another vector, so this memcpy definitely won't work.
Additionally, the sizeof( pro_data ) will not get you the total size, it'll get you the size of an empty pro_data struct/class.

-
  pro_lpGMain->GetDevice()->SetStreamSource(0, pro_VB, sizeof(SMesh));  


sizeof( SMesh ) returns the size of std::vector ( 16 bytes ), not your vertex type.
The 3rd parameter here is called the stride, which is the size of each vertex in bytes.
You should use sizeof( MODELVERTEX ) instead.

- When you're loading the vertices, you didn't take into account that the quake2's coordinate system is very different.
Its y axis increases to the right ( == D3D's x axis )
Its x axis increases out of the screen ( == -ve D3D's z axis )
Its z axis increases upwards ( == D3D's y axis )


-
  pro_lpGMain->GetDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, GetNumTriangles())  


If we assumed the memcpy above worked, your buffer would contain all the animation frames of the md2, and then this call should've rendered them ( all the frames at once, which is wrong. You should render one frame at once ).

Additionally, the vertices are NOT stored as triangle strips, they're plain triangle lists.
In fact, the md2 format stores vertices in 2 ways : unoptimized and optimized.
The unoptimized vertex storage is the one you typically loaded. The optimized way of storing vertices is done through the usage of the glCommands, but that's a bit advanced.
By the way, By optmized I mean it's optimized for GL not D3D.


It seems you need to study the md2 format a little more, search for some reference ( I can find you one or two, only if you fail to find one yourself )

I have some source code that USED TO load md2 files, I have no idea if it's currently operational; I attempted to update it sometime ago and then I just abandoned it ( before finishing the update ).
If you fail to find any decent source, tell me and I'll post it here or mail it to you ( mail would be better )

[edited by - Coder on November 2, 2002 2:36:55 PM]

Advertisement
Hi there,

Thanks for replying coder, but I already know it doesn''t work I don''t really know what else to say, some of the info you gave me was helpful, and I''ll look into MD2 a little more.

thanks again!

fuzztrek

¬_¬
I have not followed the discussion, but you couldn''t use the indicies given by the MD2 model for vertex-buffering <- just an note

I was trying this because I thought I could use multiple streams for my texture-coordinates, texture-indicies, vertex-coordinates and the vertex-indicies...

This topic is closed to new replies.

Advertisement