DirectX 9 switching window state

Started by
36 comments, last by malborojones 12 years, 10 months ago
If I may add my 2 pennies worth of limited knowledge on this -

When you change from full to windowed or visa versa, you need to release any resources that you created with the *POOL_DEFAULT parameter. If I've read the docs correctly, the ones created with MANAGED will live through the change without problems - I'm open to be corrected on this.

I hope this helps some. And yes, I do believe you load everything back in.

Advertisement

If I may add my 2 pennies worth of limited knowledge on this -

When you change from full to windowed or visa versa, you need to release any resources that you created with the *POOL_DEFAULT parameter. If I've read the docs correctly, the ones created with MANAGED will live through the change without problems - I'm open to be corrected on this.

I hope this helps some. And yes, I do believe you load everything back in.




yip, i think that is about right too :cool:

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.

Ughhhhh that sounds so annoying x)

All the images I load are using POOL_DEFAULT which means I'm going to have to add something that keeps track of all images that are loaded and then some way of reloading all images and recreating all the sprites D:

I've been trying the workaround ryan suggested with making it look full screen by changing the screen resolution but can't figure out how to do that in C++
I tried changing my method to do this:



if (!windowed)
{
//setup the device mode
DEVMODE devmode;
devmode.dmSize = sizeof(DEVMODE);
devmode.dmPelsWidth = mGameWindow.GetWidth();
devmode.dmFields |= DM_PELSWIDTH;
devmode.dmPelsHeight = mGameWindow.GetHeight();
devmode.dmFields |= DM_PELSHEIGHT;
devmode.dmBitsPerPel = 32;
devmode.dmFields |= DM_BITSPERPEL;

//position the window to 0, 0
mGameWindow.SetPosition(0, 0);
//change screen resolution
ChangeDisplaySettings(&devmode, 0);
} else {
//set screen resolution to initial settings
ChangeDisplaySettings(&initDev, 0);
//position window in middle of the screen
mGameWindow.CenterScreen();
}



But that doesn't seem to do anything at all, the window moves like I tell it to (0,0 for full screen and back to the middle for windowed) and the border disappears and comes back when windowed like it should but the screen resolution itself doesn't change. Any ideas how to do this? it'll save having to do all the reloading of textures etc.
Never refuse a cup of tea, that's how wars are started.

the DirectX device could be lost, i hade that when i was experimenting with Fullscreen and then minimizeing it.
you need to resoet the device and reload your assets (refer to the DirectX documentation on what needs to be reloaded, but as far as i know you have to reser and reload everything but shaders)


Your probably right, the device gets lost on an alt + TAB, and what ive seen in Luna code, you change the back buffer dimensions etc, and then you have to reset the change to enable full screen

Ughhhhh that sounds so annoying x)

All the images I load are using POOL_DEFAULT which means I'm going to have to add something that keeps track of all images that are loaded and then some way of reloading all images and recreating all the sprites D:

I've been trying the workaround ryan suggested with making it look full screen by changing the screen resolution but can't figure out how to do that in C++
I tried changing my method to do this:



if (!windowed)
{
//setup the device mode
DEVMODE devmode;
devmode.dmSize = sizeof(DEVMODE);
devmode.dmPelsWidth = mGameWindow.GetWidth();
devmode.dmFields |= DM_PELSWIDTH;
devmode.dmPelsHeight = mGameWindow.GetHeight();
devmode.dmFields |= DM_PELSHEIGHT;
devmode.dmBitsPerPel = 32;
devmode.dmFields |= DM_BITSPERPEL;

//position the window to 0, 0
mGameWindow.SetPosition(0, 0);
//change screen resolution
ChangeDisplaySettings(&devmode, 0);
} else {
//set screen resolution to initial settings
ChangeDisplaySettings(&initDev, 0);
//position window in middle of the screen
mGameWindow.CenterScreen();
}



But that doesn't seem to do anything at all, the window moves like I tell it to (0,0 for full screen and back to the middle for windowed) and the border disappears and comes back when windowed like it should but the screen resolution itself doesn't change. Any ideas how to do this? it'll save having to do all the reloading of textures etc.


so, that code imatates fullscreen ?
can you post the code that creates the window ?

what i would do is this (i have my screen set to 1024x768)
set window position to 0,0
and screen width and height to 1024,768
and make it a borderless window (i hade the code to do this but i dont think i have it anymore, but you should only need to set the borderstyle to none)

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.

Excellent, I changed the size of the window instead of having to change the actual screen resolution and it worked perfectly.
The only problem is that if the window is an odd shape the images and sprites get stretched (mine is 800x600 so it was fine scaling wise)
That's why I'd rather actually change the screen resolution if it's possible, but thank's for the help, that will do for now until I can find a better way or can be bothered to actually use the reset device method tongue.gif

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

Excellent, I changed the size of the window instead of having to change the actual screen resolution and it worked perfectly.
The only problem is that if the window is an odd shape the images and sprites get stretched (mine is 800x600 so it was fine scaling wise)
That's why I'd rather actually change the screen resolution if it's possible, but thank's for the help, that will do for now until I can find a better way or can be bothered to actually use the reset device method tongue.gif

Thanks, Mal cool.gif


when you figure that out, can you PM me or post it here ?

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.

Will do smile.gif
Never refuse a cup of tea, that's how wars are started.
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
Never refuse a cup of tea, that's how wars are started.
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.

This topic is closed to new replies.

Advertisement