Jump to content
  • Advertisement
Sign in to follow this  
sunsflower

c++ direct9 fullscreen problem

This topic is 1014 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 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
Advertisement
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


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
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
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!