Acknowledge Irrlicht of maximum screen size and ratio

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
Dareltibus
Posts: 115
Joined: Mon May 17, 2010 7:42 am

Acknowledge Irrlicht of maximum screen size and ratio

Post by Dareltibus »

Hi, anyone know how to get Irrlicht know wich is the maximum screen size on the machine the game is running in?

1) Wich method give the max Screen resolution for full screen mode (if the desktop is 800x600 but the monitor can use higher resolution, the user can choose to run the game in full screen at 1024x768 for example)


2) wich method give the actual screen resolution when running in windowed mode (you can create a 2000x2000 window on a 1024x768 desktop with irrlicht, so if you know the desktop is 1024x768 you will resize the window to a smaller size)


3) how to know if the screen uses 16:9 ration instead of 4:3 (i will use that result for showing a list of available resolutions depending on the user screen) and will this affect GUI elements? ( i tried and see no change on 3D meshes, so it seems that irrlicht has no problem related to the screen ratio. but i just started and made no testes with GUI elements)

I'm working on a graphics settings selection screen showed before the game starts.


thanks

EDIT:

i found only 1 of the method i need.. there is a list of screemodes somewhere but i really don't understand how to use it.

//! Returns current desktop screen resolution.
const core::dimension2d<u32>& CVideoModeList::getDesktopResolution() const
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yeah, ask the VideoModeList. All possible resolutions should be stored in there. The hw aspect ratio is not stored anywhere, you should probably let the user choose.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Acknowledge Irrlicht of maximum screen size and ratio

Post by greenya »

Dareltibus wrote:how to get Irrlicht know wich is the maximum screen size on the machine the game is running in?
You can get all fullscreen video modes supported using next code:

Code: Select all

video::IVideoModeList* l = device->getVideoModeList();
for (int i = 0; i < l->getVideoModeCount(); i++)
{
    core::dimension2du resolution = l->getVideoModeResolution(i);
    int depth = l->getVideoModeDepth(i);

    // now you have resolution and depth
    // ...
}
If you want to check certain video mode, you can use:
Irrlicht Documentation wrote:core::dimension2du video::IVideoModeList::getVideoModeResolution(core::dimension2du& minSize, core::dimension2du& maxSize);

Parameters:
minSize: Minimum dimensions required.
maxSize: Maximum dimensions allowed.

Returns:
Size of screen in pixels which matches the requirements. as good as possible.
Dareltibus wrote:how to know if the screen uses 16:9 ration instead of 4:3
you can just get current screen resolution and check its ratio:

Code: Select all

core::dimension2du resolution = l->getDesktopResolution();
float ratio = (float)resolution.Width / resolution.Height;
if (ratio == 16.0f/9.0f)
{
   // this is 16:9
}
else if (ratio == 4.0f/3.0f)
{
   // this is 4:3
}
else
{
   // this is some other ratio
}
d3jake
Posts: 198
Joined: Sat Mar 22, 2008 7:49 pm
Location: United States of America

Post by d3jake »

Forgive me for asking, but isn't it a bit leery to directly compare floats? Or is that taken care of with overloaded operators?
The Open Descent Foundation is always looking for programmers! http://www.odf-online.org
"I'll find out if what I deleted was vital here shortly..." -d3jake
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

Yes, it's probably a bad idea to do that. A different way of comparing would be:

Code: Select all

if (yRes/(xRes/4)==3) {
// 4:3
}
else if (yRes/(xRes/16)==9) {
// 16:9
}
This way should be much safer as no floating points need to be involved.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

You could always just use core::equals...
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

d3jake wrote:Forgive me for asking, but isn't it a bit leery to directly compare floats? Or is that taken care of with overloaded operators?
Why floats cannot be compared ?

Next code writes "true" into "c":

Code: Select all

float a = 1.f/2.f;
float b = 1000.f/2000.f;
bool c = a == b;
So i do not see any problems doing so.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Problems would arise, if someone e.g. would write 16.0/9.0 as it would use doubles and often come to different results. Other bad things may happen with floats and doubles as well. Always be careful with such things.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

hybrid wrote:Problems would arise, if someone e.g. would write 16.0/9.0 as it would use doubles and often come to different results. Other bad things may happen with floats and doubles as well. Always be careful with such things.
I didn't mention doubles.
Solution that i showed uses floats.

There is no problems when you use floats for converting 1-7 meaning digits integers to float to divide them and compare the result. There are problems only with doubles and when we mixing both types.

Code: Select all

float a = (float)0.000151f/0.000252f;
float b = (float)151000000/252000000;
bool c = a == b; // true
if we change "float" to "double", "c" will be "false".
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

I think the issue is that even if you aren't converting, a small amount of precision difference (EG: 4.999999f is not technically 5.f.) Like slavik262, use irr::core::equals for safety.
Dareltibus
Posts: 115
Joined: Mon May 17, 2010 7:42 am

thanks

Post by Dareltibus »

ok thanks you all. if i get any trouble i'll ask. I love this community and you all:)
Post Reply