Skip to main content
gamedev.net
🔒 Locked

Model Rendering

Started by To_N 4 replies 450+ views
Original Post
To_N
To_N
http://www.nut-shell.com/~josh/Upload/files/ModelTest.zip this is a small (only 53KB) app, that should explain you my problem while rendering x files... This is my global model pointer CD3DFile * enemy; during the initialisation I use the following code: enemy = new CD3DFile(); enemy->Load("helicopter.x"); This is my main loop
  
while(!done)
{
	//dd is the DirectDraw interface

	if(FAILED(dd.ClearBuffer(BK_COLOR)))
		done = true;

	D3DMATRIX matWorld;

	matWorld._11 = matWorld._22 = matWorld._33 = matWorld._44 = 1.0f;
	matWorld._12 = matWorld._13 = matWorld._14 = matWorld._41 = 0.0f;
	matWorld._21 = matWorld._23 = matWorld._24 = matWorld._42 = 0.0f;
	matWorld._31 = matWorld._32 = matWorld._34 = matWorld._43 = 0.0f;
		
	matWorld._22 =  cosf(i);
	matWorld._23 =  sinf(i);
	matWorld._32 = -sinf(i);
	matWorld._33 =  cosf(i);

	matWorld._44 = 20.0f;
	i += 0.005;

	d3ddev->SetRenderState(D3DRENDERSTATE_CULLMODE, TRUE);
	d3ddev->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_WIREFRAME);

	d3ddev->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorld);

	d3ddev->BeginScene();
	enemy->Render(d3ddev);
	d3ddev->EndScene();

	d3ddev->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID);
}
  
This is the code for clearing the BackBuffer Surface
  
HRESULT CRat_DirectDraw::ClearBuffer(DWORD Color)
{
	HRESULT ddrval;
	DDBLTFX ddBltFx;

	ZeroMemory(&ddBltFx, sizeof(DDBLTFX));
	ddBltFx.dwSize = sizeof(DDBLTFX);
	ddBltFx.dwFillColor = Color;
	
	ddrval = m_lpDDSBack->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddBltFx);

	return ddrval;
}
  
This is the code for initialising the d3d device. I know its kind of dirty still but I''ll include a graphic board device enumeration later. Anyhow this should not be the problem...
  
HRESULT CRat_Direct3D::Init(CRat_DirectDraw *pDDrawDevice)
{
	HRESULT d3drval;

	LOG("CRat_Direct3D::Init() called -> ");

	if((!pDDrawDevice) || (!pDDrawDevice->IsInitialised()))
	{
		LOG("Error, No valid CRat_DirectDraw pointer given\n");
		return D3DERR_INVALID_DEVICE;
	}

	DWORD dwScreenX = pDDrawDevice->GetScreenX();
	DWORD dwScreenY = pDDrawDevice->GetScreenY();
	LPDIRECTDRAW7 lpDD = pDDrawDevice->GetDirectDrawDevice();
	LPDIRECTDRAWSURFACE7 lpDDSBack = pDDrawDevice->GetBackBuffer();

	if(lpDD == NULL)
	{
		LOG("Error, No valid DirectDraw Device pointer in CRat_DirectDraw Object\n");
		return D3DERR_INVALID_DEVICE;
	}

	m_pDDraw = pDDrawDevice;

	if(lpDDSBack == NULL)
	{
		LOG("Error, No valid Backbuffer pointer in CRat_DirectDraw Object\n");
		return D3DERR_INVALID_DEVICE;
	}

	d3drval = lpDD->QueryInterface(IID_IDirect3D7, (LPVOID *)&m_lpD3D);

	if(FAILED(d3drval))
	{
		m_lpD3D = NULL;
		LOG("Error, in QueryInterface() for Direct3D Object\n");
		return d3drval;
	}

	initialised = true;

	d3drval = m_lpD3D->CreateDevice(IID_IDirect3DTnLHalDevice, lpDDSBack, &m_lpD3DDevice);

	if(FAILED(d3drval))
	{
		LOG("Initialisation with IID_IDirect3DTnLHalDevice failed, trying IID_IDirect3DHALDevice\n");
		LOG("CRat_Direct3D::Init() called -> ");

		d3drval = m_lpD3D->CreateDevice(IID_IDirect3DHALDevice, lpDDSBack, &m_lpD3DDevice);

		if(FAILED(d3drval))
		{
			LOG("Initialisation with IID_IDirect3DHALDevice failed, trying IID_IDirect3DMMXDevice\n");
			LOG("CRat_Direct3D::Init() called -> ");

			d3drval = m_lpD3D->CreateDevice(IID_IDirect3DMMXDevice, lpDDSBack, &m_lpD3DDevice);

			if(FAILED(d3drval))
			{
				LOG("Initialisation with IID_IDirect3DMMXDevice failed, trying IID_IDirect3DRGBDevice\n");
				LOG("CRat_Direct3D::Init() called -> ");

				d3drval = m_lpD3D->CreateDevice(IID_IDirect3DRGBDevice, lpDDSBack, &m_lpD3DDevice);

				if(FAILED(d3drval))
				{
					LOG("Error, Initialisation with IID_IDirect3DRGBDevice failed, no valid D3D Device detected\n");
					UnInit();
					return d3drval;
				}
				else
					LOG("IID_IDirect3DRGBDevice found");
			}
			else
				LOG("IID_IDirect3DMMXDevice found");
		}
		else
			LOG("IID_IDirect3DHALDevice found");
	}
	else
		LOG("IID_IDirect3DTnLHalDevice found");

	D3DVIEWPORT7 D3DViewport;
	D3DViewport.dwX	= 0;
	D3DViewport.dwY	= 0; 
	D3DViewport.dwWidth	= dwScreenX;
	D3DViewport.dwHeight = dwScreenY; 
	D3DViewport.dvMinZ = 0.0f;
	D3DViewport.dvMaxZ = 1.0f;
	
	d3drval = m_lpD3DDevice->SetViewport(&D3DViewport);

	if(FAILED(d3drval))
	{
		LOG("... Error, in SetViewport() for D3DDevice\n");
		UnInit();
		return d3drval;
	}

	LOG("... OK\n");

	return D3D_OK;
}
  
Thats all. So what could be the problem? Thx in advance... Tobias Nöll / Germany
Alan Kemp
Alan Kemp

  
d3ddev->SetRenderState(D3DRENDERSTATE_CULLMODE, TRUE);


The last parameter for SetRenderState in this case should be one of:


D3DCULL_CCW
Cull faces with counterclockwise vertices.
D3DCULL_CW
Cull faces with clockwise vertices.
D3DCULL_NONE
Do not cull faces.


TRUE is a define for ''1'', which probably just happens to match the value of D3DCULL_CW, so you are culling all the clockwise wound triangles. Try using D3DCULL_CCW.

Out of intrest, why are you using Direct3d 7?

Alan
"There will come a time when you believe everything is finished. That will be the beginning." -Louis L'Amour
To_N
To_N
OK, this one is right, which Alan stated, BUT it does not solve my problem...
I changed the Culling to D3DCULL_CCW and still the same problem occours
It seems that there is a plane where my model half looks through (see sample program), but I am _ONLY_ rendering this model...

I am no 3D guru, are there more
d3ddev->SetTransform(foo, foo);
to set except the D3DTRANSFORMSTATE_WORLD?

Also I am not using a ZBuffer, could this raise my problem?

@Alan: I am using DX7 since I am creating a 2D Engine with only SOME D3D7 features such as 3DModels, Alpha Blending and stuff. I dont like the way DX8/9 handles 2D Graphics...

[edited by - To_N on January 6, 2003 9:46:07 AM]
Alan Kemp
Alan Kemp
You need to set up a projection matrix to specify the near and far clipping planes. I think your near clipping plane is too far out and your model is going through it as it rotates.

The code you are looking for will be somthing like:


  
D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
g_pd3dDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &matProj);


Alan
"There will come a time when you believe everything is finished. That will be the beginning." -Louis L'Amour
To_N
To_N
OK Alan!
Thank you VERY MUCH!
Its working now
Drath
Drath
Just as a warning, I saw somewhere that the DX7 2D way will eventually be quite a lot slower because of reforms in the chip architecture or something. Kind of vague so I''d appriciate if no one qoutes more or flames me please.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.