Sign in to follow this  
sunsflower

c++ direct9 fullscreen problem

Recommended Posts

sunsflower    268
I set fullscreen to be true and it did run as a fullscreen window. However, when I switch to other application(so the game window is minimized) and switch back, problems emerge. This program doesn't render at all, and it has a window frame(though this frame is as big as the screen...). How can I do to fix this? i think I should recreate dx resources, but how?
bool Direct3d_Init(HWND window, int width, int height, bool fullscreen)
{
	d3d = Direct3DCreate9(D3D_SDK_VERSION);
	if (!d3d)
	{
		MessageBox(window, "Error initializing Direct3D", "Error", MB_OK);
		return false;
	}

	D3DPRESENT_PARAMETERS d3dpp;

	D3DDISPLAYMODE dm;
	d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm);

	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.Windowed = (!fullscreen);
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;

	d3dpp.EnableAutoDepthStencil = 1;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
	d3dpp.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
	//d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
	//d3dpp.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES; //MULTIPLE_SAMPLES!!!


	d3dpp.BackBufferFormat = dm.Format;
	//d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	d3dpp.BackBufferCount = 1;
	d3dpp.BackBufferWidth = dm.Width;
	d3dpp.BackBufferHeight = dm.Height;
	d3dpp.hDeviceWindow = window;

	d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
		D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);

	if (!d3ddev)
	{
		MessageBox(window, "Error creating Direct3D device", "Error", MB_OK);
		return false;
	}
	d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);

	D3DXCreateSprite(d3ddev, &spriteobjfont);

	return true;
}

and by the way, how to set resolution of screen when game is running? and...how to change the coordinate system(the origin of which is by default at the top left corner)?

Share this post


Link to post
Share on other sites
Aardvajk    13207
You need to test device->TestCooperativeLevel() == D3DERR_DEVICELOST and then wait for device->TestCooperativeLevel() == D3DERR_DEVICENOTRESET.

At that point you need to release any non-managed resources, call device->reset() then re-create the resources you destroyed. I'm not sure if the resource(s) from D3DXCreateSprite are managed or not.

Lost device handling is a bit of a pain with D3D9. Edited by Aardvajk

Share this post


Link to post
Share on other sites
C0lumbo    4411


Lost device handling is a bit of a pain with D3D9.

 

The worst bit is getting useful debugging information for DX9 on a modern version of windows. Enabling debug runtime just doesn't work anymore (on Windows 7 and above I beleive). So if you've forgotten to release one of your non-managed resources, it can be a challenge to track down the problem!

Share this post


Link to post
Share on other sites
Aardvajk    13207
One of the reasons I generally re-wrap D3D API in my own interfaces and use RAII to look after calling Release(). I also normally register non-managed resources with some kind of central system that is used on device reset.

For example, DepthStencilSurface, VertexBuffer and so on derive from GraphicsResource which has virtual release() and reset() methods. Non-managed resources are added to a list of GraphicsResources which I walk during the reset.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this