Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.



This topic is 5938 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

I''ve been able to load MD2 files into a D3D program successfully and also load in textures and MD2 style indexed lighting. However, I''ve simply built an array of triangles to render as a Triangle LIST. This works perfectly except that now I want to generate my own light normals. When I generate light normals and render a Triangle LIST, the polygon shading does not interpolate the vertex normals BETWEEN triangles, so each polygon is essentially rendered with flat shading (even if I turn on Gouraud shading). I THINK the only way to get smooth shading is to draw the triangles as a Triangle STRIP or FAN. However, I don''t know how to do this with the MD2 file data. I know it has some to do with the GLCommand structure in the MD2 file, but all of the MD2 loading examples I''ve seen are confusing since all are in OpenGL and the actual rendering part differs from D3D. I can LOAD the GLCommands succesfully, but I don''t know how to USE them. I DID get an example from 3DModelMan in DirectX, but for the LIFE of me, I can''t figure out how he gets texture data in his vertex buffer by JUST loading the GLCommands into it. This does not make sense to me. do { numVertices = (int)m_pdwGlCommands[nextcommand]; nextcommand++; if (numVertices > 0) // render a triangle strip { for (t = 0; t < numVertices; t ++) { //******** CODE IN QUESTION ****** memcpy(&m_pcVertexBuffer[t].tu, &m_pdwGlCommands[nextcommand], 2 * sizeof(float)); //********************************* nextcommand +=2; memcpy(&m_pcVertexBuffer[t].x, &m_pcTransformedVertices[m_pdwGlCommands[nextcommand]].x, 6 * sizeof(float)); nextcommand++; } D3D->lpDevice->DrawPrimitive (D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX , m_pcVertexBuffer,numVertices, NULL); etc.... The m_pcTransformedVertices structure in his code just contains position and normal information for each vertex. So how could this "&m_pdwGlCommands[nextcommand]" load texture coordinates into the Vertex Buffer? Tony

Share this post

Link to post
Share on other sites
Hi Tones2,

For a start I managed to figure out the MD2 format entirely from this. So it may be a useful reference if you haven''t found it already.

When using the glCommands they provide ANOTHER set of texture coords. This time they are of the format 0.0f-1.0f (as we would expect them), in that code I simply copy two floats in one memcpy call, it''s safe to do so, since the tu,tv values are sequential in the vertex buffer as they are in the glCommands. Remember too, that that code is written for DX7 and a vertex buffer is simply an array of vertices, not a vertex buffer in the way DX8 would consider it.

This does not solve your lighting problem though. The lighting information is still available without the glCommands, and using them accesses the same vertex and normal data as you are already using.

This is a quick synopsis of the glCommand data:

1) int NUMBER OF VERTICES (n) - if this value is negative, the next (n * -1) glCommands form a trifan, otherwise the next (n) glCommands form a tristrip.
2) n glCommands (to create the previously described strip or fan) at this point the vertex index is exactly the same as the one you are already using.



Main site | Free source | Email

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!