Changing screen resolution

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Ced666
Posts: 86
Joined: Fri Jan 13, 2006 10:29 am
Location: Belgium

Changing screen resolution

Post by Ced666 »

Hello !
Is there a way to change the screen resolution without destroying the Irrlicht device ?
Or the only way to do that is to destroy the existing device and create a new one with the new screen resolution (which implies to add all the nodes and camera once again) ?

Thanks
killzone721
Posts: 19
Joined: Thu Feb 09, 2006 1:45 am

Post by killzone721 »

I am surprised that no one answered this question for so long but meh...

u don't have to create another device just to change the screen resolution...

if you do create new devices... there is more chances that the program will crash or when u drop the device or close it

well i know one way of changing the resoluion with just ione device in the whole program.
simply declare your device as a global variable... and change its resolution in other function

let me show u an example ..... :wink:

//CODE BEGINS HERE

//declare you header and the namspaces
//then... without declaring the device, declare it her or globally

Irrlichtdevic*device=0;

//start main function

int main()
{

device = //set the screen resolution...

//BLA BLA BLA...............
//now you want to change the screen resolution
//you can either in the same function or be more OOP
//and declare a new function to change the resolution
//right now i will do it in the same fucntion (int main)

device = //set the new resolution

//BLA BLA BLA .................

}

//END OF CODE HERE....................


HOPE THIS HELP YOU :wink:
TO ALL THE AMATEURS OUT THERE LIKE ME......

AIM HIGH AND YOU MAKE SOMETHING PRETTY DECENT TO SHOW THE WORLD

CURRENTLY WORKING ON MY COMPANY WITH ME CREW MEMBERS. MY COMPANY IS CALLED
BIG DREAMS
AND WE ARE MAKE VERSION 0.1 FPS GAME
Guest

Post by Guest »

Ive been doing it (without crashes) by closing/droping the device (note the "app" is still alive so you keep all your game data) and recreating the device with new parms. However I didn't realise you could just pass new parms to the createdevice function and it would work cleanly.

I also clear all the scenemanager before doing this (I think irrlicht takes care of all the texture managment and cleans it all up - no mem leaks anyway).

With this method is there even any need to clear the scenemanger?

I will try it out thanks.
Guest

Post by Guest »

Ok , when I try it, I can call my devicecreation function (with global device as usual) and it "works" but it leaves behind a window of the old device - not an active one but one for each time you resend new paramaters - resetting/new res 8 times results in 8 windows but only the latest one the "real" active one.


what am I doing wrong? I am not dropping or closing - should I at least close it first?
Guest

Post by Guest »

Also I use my "Device reset" function when I change other options including resolution but also texturefiltering, antialiasing, colourmode - not sure you can do that without a proper restart (and reload of all assets in the case of colourmode?)

if not then I may as well stick to my close/drop/recreate as it works ok, though I am worried about this crash talk - does irrlicht not release resources properly or something?
killzone721
Posts: 19
Joined: Thu Feb 09, 2006 1:45 am

Post by killzone721 »

remember that if u make new devices everytime just to change the SCREEN RESOLUTION, you have to declare all those driver, snv and smgr function back to each device...

this really affects the game's efficency, especially when u r making a high-graphic 3 d game with good graphic models and stuff...

and yes if you make more devices that ther is more chances of crashes like at the end when u try to close there will usually be an exceptional error if the engine doesn't completely drop everything... don't get me wrong it doesn't crashes ALWAYS but it does...

i found my method to be more OOP as well (object oriented programming)... since i hav only 1 device to make the whole game.

YOU ARE ALSO RIGHT THAT THE RE ARE LEFTOVER WINDOWS AT THE END, WHICH IS THE PAIN IN THE BUTT WHERE YOU HAVE TO CLOSE THEM YOURSELVE TO ACTUALLY END THE GAME

I KNOW....... :(

well... i just found this idea since i am making my own game... it makes my game a whole lot easier to CODE as well make the game a whole lot EFFICIENT

REST IS UP TO U
HOPE I HELPED :wink:
TO ALL THE AMATEURS OUT THERE LIKE ME......

AIM HIGH AND YOU MAKE SOMETHING PRETTY DECENT TO SHOW THE WORLD

CURRENTLY WORKING ON MY COMPANY WITH ME CREW MEMBERS. MY COMPANY IS CALLED
BIG DREAMS
AND WE ARE MAKE VERSION 0.1 FPS GAME
Guest

Post by Guest »

i don't know if is it a stupid question, but i'm in a project at the university and i need to change the resolution only of the border of the screen. The first image is the example of Collision in irrlicht and the second is how the
user needs to see.

1->http://nosafira.z6.com.br/mapa.jpg

2->http://nosafira.z6.com.br/mapb.jpg

Is it possible using irrlicht?
nosafira
Posts: 7
Joined: Thu Feb 09, 2006 10:55 pm
Location: joinville - brasil
Contact:

Post by nosafira »

i've seen this code in the forum, but i don't know if this can help me changing only de border resolution.

int AltForRes(int number, int origResolution, int newResolution){
number *= newResolution;
number /= origResolution;
return number;
}


core::dimension2d<s32> ChgForRes(core::dimension2d<s32> Dim, int origResolution, int newResolution)
{
Dim = core::dimension2d<s32>(
AltForRes(Dim.Width, origResolution, newResolution),
AltForRes(Dim.Height, origResolution, newResolution)
);

return Dim;
}

core::position2d<s32> ChgForRes(core::position2d<s32> Pos, int origResolution, int newResolution)
{
Pos = core::position2d<s32>(
AltForRes(Pos.X, origResolution, newResolution),
AltForRes(Pos.Y, origResolution, newResolution));
return Pos;
}

core::rect<s32> ChgForRes(core::rect<s32> Rect, int origResolution, int newResolution){
Rect = core::rect<s32>(
AltForRes(Rect.UpperLeftCorner.X, origResolution, newResolution),
AltForRes(Rect.UpperLeftCorner.Y, origResolution, newResolution),
AltForRes(Rect.LowerRightCorner.X, origResolution, newResolution),
AltForRes(Rect.LowerRightCorner.Y, origResolution, newResolution));
return Rect;
}
Eu não acredito em duendes - eles mentem muito!
Ced666
Posts: 86
Joined: Fri Jan 13, 2006 10:29 am
Location: Belgium

Post by Ced666 »

To killzone721:

You mean that you don't drop your previous device and you just call createDevice another time with the new screen resolution ?

But this will result in memory leaks first and then, you have still to recreate everything cause you ger an empty device.
Or maybe I misunderstood what you said.
Guest

Post by Guest »

well I think having a new window each time you recreate is not viable. The correct way is to drop/close it and recreate it (globally) and reload your stuff back in - that's just the way things are with games.

Now, if it *crashes* sometimes then you need to check WHY it's crashing and make sure you are not referencing something that was dropped in the reset or reloading something that doesnt need it etc. even if it's irrlichts "fault" then that needs fixing. Simply opening a new window each time looks stupid and far from pro - imagine someone changes res 10 times - they have 9 useless windows on their screen ( in windowed mode) and yes - mem leaks are bound to happen!

just do

device->close
device->drop

then restart your device as if it is a new first run launch - call a "device setup" function (or member function of your class if you have to abstract it) and in that call "game setup " or "scene init" or whatever you need to re-create driver,filesystem, assets etc. It works for me and takes about 3 seconds. I can loop it all night long (soak test) changing res and restarting and it works fine an retains all data, and not even 1 byte of memory leak showing! :)
jrm
Posts: 111
Joined: Tue Dec 13, 2005 8:57 pm

Post by jrm »

What does your code look like? I have tried this and it crashes.

Code: Select all

	while(device->run() && driver)
	{
		//get network data even though the window is not active.

		if (device->isWindowActive())//if the window isn't active don't draw anything.
		{
            if (receiver.keys[irr::KEY_F2])
			{ //go to setup screen
                ShowOptionsStartGame();

			}
                  }
           }
.......
ShowOptionsStartGame(); has all the creation stuff code.

Thank you,

Josh
jrm
Posts: 111
Joined: Tue Dec 13, 2005 8:57 pm

Post by jrm »

I think I found what is happening. I have to recreate everything, link up all my images again. Which means I need to go through my map file again to get the image name/locations. Is that correct?

I haven't done that yet. So there isn't another way to change the device parameters without dropping and recreating? Is there anyway to copy the data from the old device over to the new one? then drop the old one?

JRM
genesisrage
Posts: 93
Joined: Tue Feb 08, 2005 12:19 pm

Post by genesisrage »

not that ive found JRM, there are many topics releating to this... and they all say it isnt possible unless you rewrite the engine.
ive personally tried to use smngr pointers and some other things to try and copy from another device, but nothing ive tried has worked.
one idea i had was to use the null device (was trying to find a use for it), but it doesnt seem to store any data about objects created under it. im not that experienced with irrlicht, maybe someone that knows more might be able to do something, but i doubt it.
jrm
Posts: 111
Joined: Tue Dec 13, 2005 8:57 pm

Post by jrm »

hmm. ok I think I will ask for the res and driver when the games starts and don't allow it to be changed after that. Fixes the problem.

Thank you,

JRM
Post Reply