MD2 Model with Normals, and Windowed mode

This topic is 4068 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I've used the MD2 model loader posted as an article here on gamedev.net (with some minor modifications) but have found a small problem with it: it doesn't load normal information. I'm currently working with lighting and none of the MD2 models show properly because their normals aren't set. When I put in the reading of normals (calculated via the normal index and anorms.h) the model doesn't draw properly, it's multicolored, some parts are transparent, and it doesn't look anything like the MD2 model (it's all stretched and distorted). I can't post a shot because Fraps crashes my game when I hit F10 for a screenshot (but that's a different discussion, unless you want to throw some ideas in - I do make sure I recreate lost devices...). Any ideas why this is happening? Another thing, to avoid double posting (sorry!), I have a problem entering windowed mode (fullscreen works properly). This is my current code:
	// now setup the device parameters
ZeroMemory( &m_PresentParms, sizeof( m_PresentParms ) );
m_PresentParms.Windowed = true; // TODO: make this changeable

// stencil format
m_PresentParms.EnableAutoDepthStencil = true;
m_PresentParms.AutoDepthStencilFormat = D3DFMT_D16;

// backbuffer
m_PresentParms.BackBufferWidth = m_Width;
m_PresentParms.BackBufferHeight = m_Height;
m_PresentParms.BackBufferFormat = D3DFMT_UNKNOWN;

// create the device
HRESULT hr = m_D3DObj->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hwnd, m_VertexProcessing, &m_PresentParms, &m_D3DDev );

// failed?
if( FAILED( hr ) )
{
MessageBox( NULL, DXGetErrorString8( hr ), "Fatal Error!", MB_OK | MB_ICONERROR );
return false;
}


I get D3DERR_INVALIDCALL... I have tried everything I could find on Google, but most of it is people having trouble with fullscreen. Any ideas? Edit: OK, the windowed mode problem is now non-existent, I just had to get the adapter information first and use that in the presentation parameters. Edit 2: I now have a screen of the MD2 model problem: The weird thing in the foreground is the MD2 model (with normals enabled), and the box is a vertex buffer being rendered. I've purposely moved the camera to try to see as much of the model as possible as well. I think it has something to do with the position, normals, and texture co-ordinates being messed up somehow. Here's the FVF and struct I use for the MD2 model:
#define D3DFVF_MD2		( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0) )

// <snip>

// md2 vertex
struct D3DVERTEX_MD2 {
D3DXVECTOR3 m_vecPos;
D3DVECTOR Normal;
DWORD m_dwDiffuse;
D3DXVECTOR2 m_vecTex;
};


It works perfectly if I remove the Normal vector. Edit 3: I fixed it. I made such a stupid mistake... I had left the draw code alone, so it was like so:
	// draw
HRESULT h = d3d->GetDevice()->DrawPrimitiveUP(
D3DPT_TRIANGLELIST,					//Type
GetTriangleCount(),					//Count
(BYTE**)&m_data[frame].vertex[0],	//Pointer to data
sizeof(MODELVERTEX)				//Size vertex
);


Of course, MODELVERTEX didn't have the normal information :D So I changed it to this,
	// draw
HRESULT h = d3d->GetDevice()->DrawPrimitiveUP(
D3DPT_TRIANGLELIST,					//Type
GetTriangleCount(),					//Count
(BYTE**)&m_data[frame].vertex[0],	//Pointer to data
sizeof(D3DVERTEX_MD2)				//Size vertex
);


And my problem is fixed. [Edited by - pcmattman on June 26, 2007 7:38:15 PM]

1. 1
2. 2
frob
15
3. 3
4. 4
Rutin
12
5. 5

• 13
• 12
• 58
• 14
• 15
• Forum Statistics

• Total Topics
632121
• Total Posts
3004231

×