Detecting best resolution for netbooks
BlitzMax Forums/BlitzMax Programming/Detecting best resolution for netbooks
| ||
After some prompting from Anawiki Games to fix my code to run on lo-res netbooks I did this which I thought I'd share: For example on a 1024x768 system it will use that for full-screen but only 800x600 for windowed mode. For a netbook that is 800x600 it should use 800x600 for full and 640x480 for windowed. There's no aspect ratio correction, but I don't care about that just yet, maybe for a later game. I just needed to fix this resolution crash issue first. Basically ScreenWidth/Height is my desired size that all my code is based on, and WindowWidth/Height is the best fit. Here's some code snippets for you to use if they prove helpful: 'Detect best Window Size DebugInt = 11301 Const MAX_RESOLUTIONS:Int = 3 Local ResolutionX:Int[MAX_RESOLUTIONS] Local ResolutionY:Int[MAX_RESOLUTIONS] ResolutionX[0] = 640 ResolutionY[0] = 480 ResolutionX[1] = 800 ResolutionY[1] = 600 ResolutionX[2] = 1024 ResolutionY[2] = 768 WindowWidth = ScreenWidth WindowHeight = ScreenHeight 'Loop back through resolutions until we get one that fits. Local resToTest:Int = MAX_RESOLUTIONS - 1 Local found:Int = 1 Local comparisonHeight:Int = DesktopHeight 'For Windowed mode we need to take into account the Window title bar, so reduce the comparisonHeight by a big title bar height. If FullScreen = 0 Then comparisonHeight:-30 EndIf While comparisonHeight < WindowHeight 'Did we fail? If resToTest < 0 Then found = 0 Exit EndIf DebugInt = 11302 WindowWidth = ResolutionX[resToTest] WindowHeight = ResolutionY[resToTest] resToTest:-1 Wend DebugInt = 11303 If found = 0 DebugInt = 11304 RuntimeError "Cannot find a suitable resolution. Desktop Resolution= " + DesktopWidth + "x" + DesktopHeight;End Depth = -1 'failed End If Method DoSetVirtualResolution() If ScreenWidth <> WindowWidth Then SetVirtualResolution(ScreenWidth, ScreenHeight) VirtualRatioX = ScreenWidth / Float(WindowWidth) VirtualRatioY = ScreenHeight / Float(WindowHeight) UsingVirtualResolution = 1 End If End Method With this any many other recent changes, my framework is now quite enhanced since the version I sold to BFG, muhahaha. |
| ||
Hey Grey, Could I ask, why you didn't include aspect correction. If you see an 800x600 screen stretched on a widescreen display, it doesn't look nice. It kinda like watching a 4:3 screen streched on a widescreen TV. I know odd aspect mod is really good for this. See http://www.blitzbasic.com/codearcs/codearcs.php?code=2707 Kind Regards |
| ||
Just that I don't have time to do it right now. Casual gamers aren't as bothered by it either, plus lots of screens auto-correct these days. |
| ||
Hey Jake! Just wondering when do you actually call your DoSetVirtualResolution method? Also did you have any issues with BlitzMax's SetVirtualResolution command? Cheers! |