D3D Device scope

Started by
-1 comments, last by shakazed 20 years, 8 months ago
Hi! I´m poking around with some code for mesh rendereing (both static and skinned). So what I´m doing is splitting the code up into classes. One class for terrain, one for meshloading, one for physics and so on. The app ran smoothly until I added support for dinput. Then I get an error in my terrain class when setting up the fvf before rendering. I´ll give you the code I added for dinput first.

HRESULT CCamera::SetInputDevices(HINSTANCE hInstance, HWND hWnd)
{
	hResult = DirectInput8Create(hInstance, DIRECTINPUT_VERSION,
		IID_IDirectInput8, (void**)&p_iDInput8,NULL);
	DX_ERROR_CHK(hResult, "Failed to create input object");

	hResult = p_iDInput8->CreateDevice(GUID_SysKeyboard,&p_iDInputDevice8,NULL);
	DX_ERROR_CHK(hResult,"Failed to create input device");
	
	hResult = p_iDInputDevice8->SetDataFormat(&c_dfDIKeyboard);
	DX_ERROR_CHK(hResult, "Failed to set keyboard data format");

	hResult = p_iDInputDevice8->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE|DISCL_FOREGROUND);
	DX_ERROR_CHK(hResult, "Failed to set cooperative lever (keyboard)");

	return hResult;

}
And this is the code I use for rendering the terrain. This code is the called on by the main class "CGraphics".

HRESULT CTerrain::RenderTerrain(IDirect3DDevice9 *p_iD3DDevice9)
{
	hResult = p_iD3DDevice9->SetStreamSource(0,p_iD3DVertexBuffer9,0, sizeof(CUSTOMVERTEX));
	DX_ERROR_CHK(hResult, "Failed to set stream source (terrain)");
	
	hResult = 	p_iD3DDevice9->SetFVF(CUSTOMVERTEX_FVF);
	DX_ERROR_CHK(hResult, "Failed to set flexible vertex format (terrain)");

	hResult = 	p_iD3DDevice9->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
	DX_ERROR_CHK(hResult, "Failed to draw primitve (terrain)");

	return hResult;
}
[source]

It almost seems as the d3d device gets lost or something. As I said the code worked fine until I added dinput support. Would greatly appreciate any help.


Bad Monkey Productions

This topic is closed to new replies.

Advertisement