DirectX 9 switching window state

Started by
36 comments, last by malborojones 12 years, 11 months ago

I found a way of changing the screen resolution, I wasn't far off already:




DEVMODE dm;
dm.dmSize = sizeof(DEVMODE);

if(windowed)
{
dm.dmPelsWidth = initDev.dmPelsWidth;
dm.dmPelsHeight = initDev.dmPelsHeight;
dm.dmFields = (DM_PELSWIDTH | DM_PELSHEIGHT);
} else {
dm.dmPelsWidth = mGameWindow.GetWidth();
dm.dmPelsHeight = mGameWindow.GetHeight();
dm.dmFields = (DM_PELSWIDTH | DM_PELSHEIGHT);
}

ChangeDisplaySettings(&dm, 0);




But it would seem that it causes the device to be lost because the contents of the window go white again sad.gif
I suppose the only way of doing it is to reset everything which is just so annoying D: I'll work on it tomorrow maybe.
Thanks for all the help smile.gif


i am unfimiliar with the DEVMODE structure, and what i found on it says that is ise used for printer or screen settings or something.
why do you use it ? / what benifet does it have over not using it ?

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

Advertisement

Device can even lost from a popup window that rapes your frame buffer. You can not avoid coding this if you creates a directx based application.


but the documentation said that you only have to recreate the data if the device is lost,
or did i miss sometihng ?

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

The documentation also says that if you change the presentation parameters, which needs to be done when switching between full screen to windowed or back again, then the device needs to be reset, to reset the device you need to manage the unmanaged resources as they will be lost from the graphics card memory.


[quote name='Geri' timestamp='1306284660' post='4815381']
Device can even lost from a popup window that rapes your frame buffer. You can not avoid coding this if you creates a directx based application.


but the documentation said that you only have to recreate the data if the device is lost,
or did i miss sometihng ?
[/quote]

You must create new device and upload all data to dx again.
Not really sure ^_^ that's the only way I could find to do it. I think it's just needed for the parameter of "ChangeDisplaySettings" You can use DEVMODE to set the colour depth also from what I've seen and some other display setting stuff like refresh rate, then just pass it into ChangeDisplaySettings and everything changes. When the program starts I also fill in the "initDev" with the initial setting so that they can be restored when the program closes, it works so I don't question it tongue.gif
Never refuse a cup of tea, that's how wars are started.

Not really sure ^_^ that's the only way I could find to do it. I think it's just needed for the parameter of "ChangeDisplaySettings" You can use DEVMODE to set the colour depth also from what I've seen and some other display setting stuff like refresh rate, then just pass it into ChangeDisplaySettings and everything changes. When the program starts I also fill in the "initDev" with the initial setting so that they can be restored when the program closes, it works so I don't question it tongue.gif


ok, i would have done that when setting the d3d presentation parameters.
but ill give it a try.

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

D: didn't notice there was a second page. I'm going to work on the having to reload all assets again today, would it also apply to 3D data when I get round to it? If so I can plan ahead instead of having to change everything like I do with my sprite system dry.gif

Thanks, Mal cool.gif
Never refuse a cup of tea, that's how wars are started.

D: didn't notice there was a second page. I'm going to work on the having to reload all assets again today, would it also apply to 3D data when I get round to it? If so I can plan ahead instead of having to change everything like I do with my sprite system dry.gif

Thanks, Mal cool.gif


yes, unless you have it in custom structure (but that is my theory on how not to have to reload some of the data)

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

You don't need ChangeDisplaySettings with D3D; just setting up your new present parameters and Resetting the device is enough. In fact your CDS call is most likely what's causing your device to become lost in the first place, and why your standard Reset isn't working. It's generally bad to mix D3D stuff with Windows API stuff for this kind of reason.

You should also look to switching your default pool resources to the managed pool where appropriate. There's almost always no reason to use the default pool unless the documentation says that you have to for any particular use case. As a general rule, unless the documentation is specific about which pool you should use, use managed.

You will find the whole process of destroying and recreating default pool resources a lot easier if you aim to use the same code as you use for initial creation and final destruction. Look at the OnLost/OnRecover paradigm that D3DX uses; this is a good initial model for basing your own code on. While we're talking about D3DX, don't forget that if any D3DX object you use exposes OnLost/OnRecover methods, you must also call those.

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

Arrgghh directx get's more annoying by the second D:
Having a new problem now, my sprites seem to be stretching their images to the nearest power of 2, I'll see if I can find something on it or sort it out before starting a new thread.
Never refuse a cup of tea, that's how wars are started.

This topic is closed to new replies.

Advertisement