Change fullscreen/windowed mode at runtime

Started by
9 comments, last by vecchia 12 years, 7 months ago
Hi all,
I want to add the ability to change the window from windowed mode to fullscreen and from fullscreen to windowed mode. I added the code to manage it but I have still a question: when I go from windowed to fullscreen the text and generally the application looks like "witouth antialiasing", I suppose because the backfuffer format is incorrect. Should I change it to the resolution of the monitor? If yes, how? Can i simply write:

myD3DParams.BackBufferWidth = XXXX;
myD3DParams.BackBufferHeight = YYYY;
Advertisement
Direct3D9 or 10/11?
Yes, if the resolution of your game in fullscreen is different from the native/max resolution of the monitor then it will look all blurry or pixelated, that doesn't mean antialiasing isn't working though.
DirectX 9. Basically, what should I change when going fullscreen?
Change your present params in accordance with the documentation (it will tell you what values are valid for windowed or fullscreen), Release all D3DPOOL_DEFAULT resources, call OnLostDevice for any D3DX interfaces you use and which implement it, Reset the device, then recreate D3DPOOL_DEFAULT resources and call OnResetDevice for D3DX interfaces. Typically if you go fullscreen and your new resolution is not the same as your monitor's native resolution you'll get a loss in quality; that's a property of your monitor not of D3D and there's nothing you can do about it in code.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

how can i release all D3DPOOL_DEFAULT resources?
By calling Release on them, like so:
// let's assume this was a texture created in D3DPOOL_DEFAULT
LPDIRECT3DTEXTURE9 tex;
.
.
.
// (some time later)
tex->Release ();
tex = NULL;

You'll normally see a SAFE_RELEASE macro implemented something like this:
#define SAFE_RELEASE(r) {if (r) {(r)->Release; (r) = NULL;}}
You should be keeping all such resources in some kind of list or array rather than creating them directly on the object that uses them so that you can more easily access them for this purpose later on. In fact an object should probably not be responsible for creating it's own resources but should instead call a separate resource creator which will pull the next free resource from your list (or alloc a new one and add it to the list if it needs to). This helps code cleanliness by centralizing resource creation in the one place.

It's also generally recommended that you use D3DPOOL_MANAGED for absolutely everything unless the documentation specifically states that you must use D3DPOOL_DEFAULT (e.g. for a resource created with D3DUSAGE_DYNAMIC). It takes a lot of the pain away from situations like this.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

wait, if I release the textures I need to load them again... why should I do this?

wait, if I release the textures I need to load them again... why should I do this?


If you don't release them, when you switch to windowed/fullscreen it will reset the device and all the data you have loaded will be lost and probably cause a memory leak
so I need to release them and reload all the textures?
That's what happens when you use D3DPOOL_DEFAULT. Resetting a device is like turning your PC off and back on again - anything that's not saved to disk is lost (or in this case anything that's only resident in video memory gets lost). Use D3DPOOL_MANAGED and you will get a system memory backing copy that D3D itself can put back into video memory post-rest so you don't need to worry about losing them or having to recreate them. Why should you do it? Because that's the way it works.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement