News:

Function Finder  Find all the functions within source code files

Main Menu

Retrieving a list of all supported screen modes

Started by AdeN, September 19, 2007, 05:31:47 PM

Previous topic - Next topic

AdeN

Hi,

Here is some code that retrieves all of the available screen modes that are supported on the PC that your app is running on, you can specify the minimum width/height/bpp requirements and a list is returned of only the screen modes that match.

At least this will help take the guesswork out of choosing a screen mode and allow you to match the native display much better at fullscreen - eg my laptop supports 800 x 600 - but then circles become ovals because the screen mode is stretched to fit the widescreen aspect ratio - so your game/application may prefer to choose a widescreen friendly screen mode instead.

Here is how you use it to return all the screen modes that are at least 800x600 at 32bpp:
GetScreens(800, 600, 32)
for i = 0 to GetArrayElements(screens(), 1)
    print Str$(screens(i).Width) + " x " + Str$(screens(i).Height) + " x " + Str$(screens(i).BPP) + " " + Str$(screens(i).Frequency) + " Hz"
next i

Example output:
800 x 600 x 32 60 Hz
1024 x 768 x 32 60 Hz
1280 x 800 x 32 60 Hz
1440 x 900 x 32 60 Hz


To get a complete list of all supported screen modes use the following but note that any BPP modes < 16bpp cannot be used by PlayBasic:
GetScreens(0, 0, 0)

... and here is the interesting bit:
Type ScreenInfo
    Width
    Height
    BPP
    Frequency
EndType

Dim screens(0) as ScreenInfo

PSUB GetScreens(minWidth, minHeight, minBPP)
    DLLid = GetFreeDll()
    LoadDll "User32", DLLid
    DLLCallConv DLLid, 0

    createbank 1, 200
    i = 0
    count = 0
    repeat
        result = CallDll(DLLid, "EnumDisplaySettingsA", 0, i,  GetBankPTR(1))
        if result = 1
            inc i
            screenWidth  = PeekBankInt(1, 108)
            screenHeight = PeekBankInt(1, 112)
            screenBPP    = PeekBankInt(1, 104)
            screenFreq   = PeekBankInt(1, 120)
            if screenWidth >= minWidth
                if screenHeight >= minHeight
                    if screenBPP >= minBPP
                        ReDim screens(count) as ScreenInfo
                        screens(count).Width     = screenWidth
                        screens(count).Height    = screenHeight
                        screens(count).BPP       = screenBPP
                        screens(count).Frequency = screenFreq
                        inc count
                    endif
                endif
            endif
        endif
    until result <> 1

    DeleteDll DLLid
EndPSub


Here's a question I hope someone (Kevin?) can answer: If there are two identical screen resolutions except for the frequency, eg 1024x768 32BPP but with 60Hz and 75Hz frequencies which one will PlayBasic use? Does it even matter and if it does can/will OpenScreen be extended to allow this selection?

Hope someone finds the above of use.

Best regards,
Adrian

kevin


    PB doesn't choose the refresh rate, it lets DX do that rate.   It seems to choose the current desktop refresh rate, when the apps starts.  So if the desktop is 60hz and you open a full screen exclusive screen mode with VSYNC,  then the sync rate will be 60hz also.    Safer than forcing a mode the monitor can't display correctly.

AdeN

OK - that makes sense - thanks.

Slightly off topic but is this code useful enough to be posted on the PlayBasic Code Tank site - I've noticed that not too much seems to get posted there?

kevin


AdeN

I've posted an improved version of the code in the PlayBasic Code Tank for all those that would like it at http://www.underwaredesign.com/pbct/pbct_dataview.php?key=57