Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Problems with DirectX 9 MD2 viewer. Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
terence tan

May 16, 2005, 02:12 AM

Hi,

I am having a problem it seems with culling of in my MD2 viewer. It's coming out like this:
http://www.posdreams.com/images/q2pic2.jpg

Things I have checked on:
a) Winding is correct(seems correct)
b) Window creation has Z-Buffering in it.

Pretty boggled on what is going on...These are my code excerpts:

Translating from MD2 file format to DX vertex's

  1.  
  2.         hResult = g_pDirect3DDevice->CreateVertexBuffer((3*header.num_tris*sizeof(MODELVERTEX)),0,
  3.                                                                                                                                                                                                         D3DFVF_MODELVERTEX,D3DPOOL_DEFAULT,
  4.                                                                                                                                                                                                         &m_pVBuffer, NULL);
  5.         if (FAILED(hResult))
  6.                 return 0;
  7.  
  8.         m_pModelVertex = new MODELVERTEX *[header.num_frames];
  9.        
  10.         // Unroll vertices(not optimal), could use indexed vertices instead
  11.  
  12.         for (i=0; i < header.num_frames; i++)
  13.         {
  14.                 pFrame = &frames[i];
  15.                 k=0;
  16.  
  17.                 m_pModelVertex[i] = new MODELVERTEX [3 * header.num_tris];
  18.  
  19.                 pVertices = m_pModelVertex[i];
  20.  
  21.                 for (j=0; j < header.num_tris; j++)
  22.                 {
  23.                         // 3 vertices per triangle
  24.  
  25.                         pVert =&pFrame->verts[ triangles[j].vertex[0] ];
  26.                         pVertices[k].x=(pFrame->scale[0] * pVert->v[0]) + pFrame->translate[0];
  27.                         pVertices[k].z=(pFrame->scale[1] * pVert->v[1]) + pFrame->translate[1];
  28.                         pVertices[k].y=(pFrame->scale[2] * pVert->v[2]) + pFrame->translate[2];
  29.                         pVertices[k].dwDiffuse=D3DCOLOR_XRGB(255,255,255);     
  30.  
  31.                         pVertices[k].u=(float) texcoords[ triangles[j].st[0]].s / header.skinwidth;
  32.                         pVertices[k].v=(float) texcoords[ triangles[j].st[0]].t / header.skinheight;
  33.  
  34.                         pVertices[k].nx=m_kAnorms[pVert->normalIndex][0];
  35.                         pVertices[k].nz=m_kAnorms[pVert->normalIndex][1];
  36.                         pVertices[k].ny=m_kAnorms[pVert->normalIndex][2];
  37.                         k++;
  38.  
  39.                         pVert =&pFrame->verts[ triangles[j].vertex[1] ];
  40.                         pVertices[k].x=(pFrame->scale[0] * pVert->v[0]) + pFrame->translate[0];
  41.                         pVertices[k].z=(pFrame->scale[1] * pVert->v[1]) + pFrame->translate[1];
  42.                         pVertices[k].y=(pFrame->scale[2] * pVert->v[2]) + pFrame->translate[2];
  43.                         pVertices[k].dwDiffuse=D3DCOLOR_XRGB(255,255,255);     
  44.  
  45.                         pVertices[k].u=(float) texcoords[ triangles[j].st[1]].s / header.skinwidth;
  46.                         pVertices[k].v=(float) texcoords[ triangles[j].st[1]].t / header.skinheight;
  47.  
  48.                         pVertices[k].nx=m_kAnorms[pVert->normalIndex][0];
  49.                         pVertices[k].nz=m_kAnorms[pVert->normalIndex][1];
  50.                         pVertices[k].ny=m_kAnorms[pVert->normalIndex][2];
  51.                         k++;
  52.  
  53.                         pVert =&pFrame->verts[ triangles[j].vertex[2] ];
  54.                         pVertices[k].x=(pFrame->scale[0] * pVert->v[0]) + pFrame->translate[0];
  55.                         pVertices[k].z=(pFrame->scale[1] * pVert->v[1]) + pFrame->translate[1];
  56.                         pVertices[k].y=(pFrame->scale[2] * pVert->v[2]) + pFrame->translate[2];
  57.                         pVertices[k].dwDiffuse=D3DCOLOR_XRGB(255,255,255);     
  58.  
  59.                         pVertices[k].u=(float) texcoords[ triangles[j].st[2]].s / header.skinwidth;
  60.                         pVertices[k].v=(float) texcoords[ triangles[j].st[2]].t / header.skinheight;
  61.  
  62.                         pVertices[k].nx=m_kAnorms[pVert->normalIndex][0];
  63.                         pVertices[k].nz=m_kAnorms[pVert->normalIndex][1];
  64.                         pVertices[k].ny=m_kAnorms[pVert->normalIndex][2];
  65.  
  66.                         k++;
  67.                 }
  68.         }
  69.  


Most of the file loading info i got from:
http://tfc.duke.free.fr/coding/md2-specs-en.html

 
tokjunior

May 16, 2005, 03:27 AM

You're on the right track, this is because of not utilizing the depthbuffer.
I guess you need to set the correct renderstates, and Clear() the targets correctly.

 
terence tan

May 16, 2005, 04:00 AM

Hmmm?

These are the render states I have set:

  1.  
  2.     g_pDirect3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
  3.                 g_pDirect3DDevice->SetRenderState( D3DRS_ZENABLE,          TRUE );
  4.                 g_pDirect3DDevice->SetRenderState( D3DRS_ZWRITEENABLE,        FALSE);
  5.         //      g_pDirect3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW);
  6. //      g_pDirect3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW);
  7. //      g_pDirect3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE);
  8.  


Played around with changing the CULLMODE..I keep looking at the winding..I feel certain that its some thing to do with the way i pull apart the vertices. I could probably do it straight with indexed vertices ...but I still won't know why this won't work(which bugs me).

 
Endurion

May 16, 2005, 04:32 AM

You want to change

g_pDirect3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE);

to

g_pDirect3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );

 
terence tan

May 16, 2005, 06:31 AM

Yes I am a moron.

Moo

 
This thread contains 5 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.