[MAXGUI] Getting depth of desktop

BlitzMax Forums/BlitzMax Beginners Area/[MAXGUI] Getting depth of desktop

Russell(Posted 2006) [#1]
Is there an easy way to do this? I thought for sure the object returned by Desktop() would have a .depth field (and it does have width and height).

Seems I should be able to say:
dskDesktop:TGadget = Desktop()
width = dskDesktop.Width   ' Works!
height = dskDesktop.Height ' Also works!
depth = dskDesktop.Depth   ' Oops!


I know I can use GetGraphicsMode to get info about a specific mode available on the user's system (including depth), but how do I know which index (the first parameter of GetGraphicsMode) is the current one?

Thanks!
Russell


FlameDuck(Posted 2006) [#2]
A TGadget, which is what Desktop() returns for some reason does not have a depth parameter.

Try this:
Print GetDeviceCaps(GetDC(0),COLORRES)



Russell(Posted 2006) [#3]
Thanks FlameDuck. I was going to try that next ;) (really, I was!). Interestingly, though, although my desktop is set to 32bits, the above returns 24 instead. Maybe it ignores the alpha bits (no relation to the breakfast cereal ;))?

Any ideas on how to do the above on Mac and Linux?

Speaking of the TGadget type, I couldn't find the methods and/or functions available for it and tried .height and .width by chance and they worked. Where are these listed?

Russell


assari(Posted 2006) [#4]
one way is to look into the source code ..\mod\brl.mod\maxgui.mod\gadget.bmx and navigate via the IDE's Code Tab.


ImaginaryHuman(Posted 2006) [#5]
In OpenGL you can use glGetIntegerv(GL_RED_BITS,Varptr(redbits)) and the same for GL_GREEN_BITS, GL_BLUE_BITS, GL_ALPHA_BITS, and also for the other buffers such as GL_STENCIL_BITS, GL_DEPTH_BITS, GL_ACCUM_BITS.

You WILL find that the numbers that this reports back to you might well be different to how the mode is *described* in the list of screen modes, and even how it is described in the o/s.

My desktop is 32-bit. Or rather, it refers to is as widthxheight Millions of colors. Then in Max, if I get the list of modes, it reports it as 32-bit. However, OpenGL reports the desktop is a 24-bit desktop, not 32-bit, and doesn't have an alpha buffer. Also if I switch my display to a 16-bit desktop, which is advertized in the o/s as widthxheight Thousands of colors, Max reports it as a 16-bit mode from the list, but in OpenGL it reports it is actually a 5:5:5 mode, ie 15-bit, with no alpha.

Conclusion: GetGraphicsMode() returns only a higher-level approximation of what the mode is, not the actual mode. The actual mode internally may be less bits per pixel and may not include an alpha channel. 32-bit might actually be 24-bit and 16-bit might be 15-bit.

Yet, if you try opening a 15-bit screen, having been told by OpenGL that it is 5 bits per pixel not 5:6:5, you will have some problems - a display might open but it can be extremely slow compared to the 16-bit mode - whereas if you request a 16-bit mode, it gives you 16-bits-per-pixel but uses only 15 of them. All confusing stuff.

To get desktop depth I open a very small window 64x1 and then use test via OpenGL, add up the bits and see what you get. You might want to assume that 15-bit=16-bit, but it probably will report correctly whether you have an alpha buffer.

NB: Opening a window on a 32-bit screen which is actually a 24-bit screen, and asking for an alpha channel, does give you an alpha channel. It seems.


Russell(Posted 2006) [#6]
Thanks, AD. If I were using OGL directly, I'd probably use the method you describe.

Basically, what I want to do is inform the user that if they are running a 256 color desktop (unlikely, I know), they will have to switch to HiColor or TrueColor...and have this work on all platforms.

FlameDuck's method works fine on Win32, but doesn't help me if/when I try to compile this on other platforms.

Hopefully, BRL will offer a simple solution in a near-future update? :)

Russell


ImaginaryHuman(Posted 2006) [#7]
Well, you can't use DirectX on linux or mac so you have to use OpenGL if you want to test it.

You may get an unusual response from OpenGL, as well, it might say the bit depth is -1.

I'm still experimenting with this. Having a box come up in 256-color mode is a good idea. Having said that, the display probably will still work if the desktop is 256-color, it will just take a while longer to convert from truecolor to indexed.


Russell(Posted 2006) [#8]
As a simple workaround that should work on all platforms, is there a way to find out which mode is the current one? Because then I could just use GetGraphicsMode() to get the depth.

Thanks!
Russell


ImaginaryHuman(Posted 2006) [#9]
Unfortunately that won't work becauase the list of graphics modes filters out any 256-color modes and lists only modes from 15/16-bit upwards. You can however apply that when the mode is 16/24/32-bit, but usually if it says 24-bit you may have to upgrade it to a 32-bit mode.