Skip to main content
gamedev.net
🔒 Locked

3D Initialization

Started by c_back 2 replies 750+ views
Original Post
c_back
c_back
I've been staring at this source I wrote but can't find the problem. It starts up fine in windowed mode but when I change it to fullscreen, I get the messagebox errors.

int InitD3DDevice(HWND hWndTarget, int Width, int Height, BOOL bWindowed, 
				  D3DFORMAT FullScreenFormat, LPDIRECT3D9 pD3D, LPDIRECT3DDEVICE9* ppDevice)

{

	D3DPRESENT_PARAMETERS d3dpp;

	D3DDISPLAYMODE d3ddm;

	HRESULT result = 0;

	if(*ppDevice)
		(*ppDevice)->Release();

	ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));

	result = pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);

	if(FAILED(result))
	{
		MessageBox(g_hWndMain, "Could not get 3D card!", "Error", MB_OK | MB_ICONINFORMATION);
		return E_FAIL;
	}
if(bWindowed)
{
	d3dpp.BackBufferWidth = Width;
	d3dpp.BackBufferHeight = Height;
	d3dpp.BackBufferFormat = d3ddm.Format;

	d3dpp.BackBufferCount = 1;

	d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
	d3dpp.hDeviceWindow = hWndTarget;

	d3dpp.Windowed = TRUE;

	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;

	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
	
	d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
}

if(!bWindowed)
{

	d3dpp.BackBufferWidth = Width;
	d3dpp.BackBufferHeight = Height;
	d3dpp.BackBufferFormat = FullScreenFormat;
	
	d3dpp.BackBufferCount = 1;

	d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
	d3dpp.hDeviceWindow = hWndTarget;

	d3dpp.Windowed = FALSE;

	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;

	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;

	d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
}

	result = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWndTarget,
		D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, ppDevice);

	if(FAILED(result))
	{
		MessageBox(g_hWndMain, "Could not initialize 3D card!", "Error", MB_OK | MB_ICONINFORMATION);
		return E_FAIL;
	}

	g_DeviceHeight = Height;
	g_DeviceWidth = Width;

	g_SavedPresParams = d3dpp;

	return S_OK;
}




As I said, when I run windowed it's fine but when I turn on fullscreen, the errors comes up: "Could not initialize 3D card!" Obviously, the createdevice call is failing. I think it has to do w/ one of the parameters in d3dpp but I'm not sure which one. I'm using DX9 for the coding. I think I've been staring at the code too long, I just can't find the problem. Thanks for any help you can give.
dx elliot
dx elliot
I think PresentationInterval must be set to 0 if it's full screen mode. IIRC, the width and height of the window must be powers of 2 if running fullscreen mode as well, but not windowed.

by the way, if you're running it in debug mode, it should tell you exactly what's wrong.
c_back
c_back
Yeah, I get this:

Direct3D9: (ERROR) :The specified mode is unsupported. CreateDevice/Reset Fails
Direct3D9: (ERROR) :Unable to set the new mode. CreateDevice/Reset Fails
Direct3D9: (ERROR) :Failed to initialize primary swapchain
Direct3D9: (ERROR) :Failed to initialize Framework Device. CreateDevice Failed.

I'm using an ATI Radeon 9800 Pro.
c_back
c_back
Fixed it, thanks :)

Topic Locked

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

Sign in to reply to this topic.