Page 1 of 1

detectCurrentScreenMode()

Posted: Fri Dec 04, 2009 11:47 pm
by pianoman
A method (in RenderSystem:: maybe ?) for detecting the current system screen resolution/depth. This way, for example, you could start your Ogre application in full screen mode using the user's current mode (the mode of their "desktop").

To help a bit, here is some code from my old 2D game library for doing it under Windows with a Win32 GDI call :D :

Code: Select all

	DEVMODE dm;
	dm.dmSize = sizeof(dm);
	dm.dmDriverExtra = 0;
	EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &dm);
	return SCREEN_MODE(dm.dmPelsWidth, dm.dmPelsHeight, dm.dmBitsPerPel, dm.dmDisplayFrequency);
I haven't looked into it for Linux or MacOS, but I would imagine it wouldn't be much more complex than the above.

Re: detectCurrentScreenMode()

Posted: Sat Dec 05, 2009 12:43 pm
by Klaim
You already have all those informations in the RenderWindow class .

Re: detectCurrentScreenMode()

Posted: Sat Dec 05, 2009 2:22 pm
by madmarx
Hi Klaim, I think there is a misunderstanding there. It looks like pianoman is asking for the screen abilities before even 1 rendersystem was created. Not the renderwindow abilities.
This is quite 'system' oriented. Pianoman, if you want to know what are the available display settings of the graphic card, you might have a look at rendersystem->getCapabilities(), even if that does not answer your request.

>>>you could start your Ogre application in full screen mode using the user's current mode (the mode of their "desktop").
I am not sure this is always possible, because you need a directx/opengl surface to draw. And the rendering might be bigger than the available surface (what if you have 3 screens?). This is just my thought. I am not 100% sure of that.

Re: detectCurrentScreenMode()

Posted: Sat Dec 05, 2009 2:34 pm
by pianoman
Hi, Klaim: madmarx is right, we're looking for the user's current screen resolution before any render window is created, so that we can create a full-screen render surface in the same resolution.

Hi, Madmarx: yes, getting the possible screen modes is one way of doing it, but it's nice also to be able to automatically use a resolution that the user prefers, in the sense that it is the resolution that they have their desktop set to. Concerning multiple monitors, I believe the code I gave gives the resolution for the primary display monitor. I used to use dual-monitoring, but can't remember 100% sure if i tested the code with dual-monitors, so that is indeed something one would need to verify with the above code. However, it is certainly "possible" to use the primary display device, and default to the resolution at which that device was already set to. It is useful to the developer when you don't want the user to have to wade through a dialog before diving into your game. And, if you don't want to guess which resolution to choose from a list of available; besides, the resolutions at which a device can run may include resolutions that the actual monitor being used doesn't support (particularly CRTs i think). (Hence the "Keep current settings? 20 seconds left..." dialog when you change your resolution in Windows OS, in case the user can't see anything after the change).

Thus I still think this is a useful feature :) Thanks for the discussion.

Re: detectCurrentScreenMode()

Posted: Sat Dec 05, 2009 4:06 pm
by Vectrex
I think this is a good idea. No need to set it automatically to fullscreen though. Simply show the ogre dialog with the current desktop res highlighted in the resolution options. 99% of the time the user wouldn't have to change it.

Re: detectCurrentScreenMode()

Posted: Sat Dec 05, 2009 5:43 pm
by Klaim
Hi, Klaim: madmarx is right, we're looking for the user's current screen resolution before any render window is created, so that we can create a full-screen render surface in the same resolution.
Oh, ok didn't understood that. ^^;

Re: detectCurrentScreenMode()

Posted: Mon Jan 04, 2010 4:21 pm
by bishopnator
Hi, I used following code for determining desktop resolution (in Windows):

Code: Select all

	//////////////////////////////////////////////////////////////////////////
	// turn-on fullscreen mode
	CRect rect;

	// Next function copies the dimensions of 
	// the bounding rectangle of the desktop
	// note: don't use CWnd::GetDesktopWindow()->GetWindowRect(&rect)
	//       due to multimonitor systems
	HMONITOR hMonitor = MonitorFromWindow(AfxGetMainWnd()->m_hWnd, MONITOR_DEFAULTTONEAREST);
	MONITORINFO lpmi;
	lpmi.cbSize = sizeof(lpmi);
	if(GetMonitorInfo(hMonitor, &lpmi))
	{
		rect.left = lpmi.rcMonitor.left;
		rect.top = lpmi.rcMonitor.top;
		rect.right = lpmi.rcMonitor.right;
		rect.bottom = lpmi.rcMonitor.bottom;
	}

	// note: rect.Width() and rect.Height() contains desktop resolution
	// etc.
It is piece of code using MFC, but it is really easy to remove MFC calls from this code (use RECT instead of CRect and use your own HWND handle instead of AfxGetMainWnd()->m_hWnd). For example you can use ogre initialization dialog's HWND for determining resolution of monitor where dialog is located in multimonitor systems.