Jump to content
  • Advertisement
Sign in to follow this  

MD2 Model with Normals, and Windowed mode

This topic is 4137 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 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
	m_PresentParms.SwapEffect = D3DSWAPEFFECT_DISCARD; // discards the last frame

	// 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: weird md2 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:

// <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]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!