How do I find the resolution (and possibly also depth and hertz) of the desktop, in a fully cross-platform compatible way, and preferably one method that works on all three platforms?
I had an idea to do it, although not very directly...
Open a window the size of the largest resolution available, acquired using CountGraphicsModes() and GraphicsModeExists() etc. The window opens on the desktop even if it is larger than the screen. Doesn't matter where it is positioned.
Next, move the mouse with MoveMouse() to 0,0. Then read the x and y mouse coords. Presumably, if the top left of the window is `off-screen`, the o/s will have cropped the mouse positioning and put it in the top left corner of the screen. The coords should tell you what `offset` you have in the top left corner.
Then position the mouse at the lower right corner of your window with MoveMouse() e.g. MoveMouse(1600,1200). Then read the x and y coords again and if they are less than the window size the o/s should have cropped the mouse's position and it should tell you how much of your window is visible.
Then close the window and open a new window with the visible size that you found. Then restore the mouse pointer to the position it was in originally.
????? I guess it would work. Any reasons why not?
I guess you'd have to take into account that at least on the Mac you can't open a window that covers the title bar, and maybe on the PC you can't open a window that covers the task bar (not sure about Linux) .... so should subtract a bit from the verticle size? Also what about window borders?
Is there a better reliable way?
Also, how to get GraphicsHertz()? Does it work in OpenGL and DirectX?
And how to get the color depth? Draw something with an 8-bit-per-component color resolution, flip the display, set the glReadBuffer() to the front buffer, grab the drawn piece into a 32-bit pixmap, look at the color resolution to see if what you drew came out in 32-bit or 16-bit? Also if it dithered, you might be able to detect some `un-pure` pixels? This would tell you if the desktop is 32-bit or 16-bit or whatever? Would it work?
Any other solutions?
I had an idea to do it, although not very directly...
Open a window the size of the largest resolution available, acquired using CountGraphicsModes() and GraphicsModeExists() etc. The window opens on the desktop even if it is larger than the screen. Doesn't matter where it is positioned.
Next, move the mouse with MoveMouse() to 0,0. Then read the x and y mouse coords. Presumably, if the top left of the window is `off-screen`, the o/s will have cropped the mouse positioning and put it in the top left corner of the screen. The coords should tell you what `offset` you have in the top left corner.
Then position the mouse at the lower right corner of your window with MoveMouse() e.g. MoveMouse(1600,1200). Then read the x and y coords again and if they are less than the window size the o/s should have cropped the mouse's position and it should tell you how much of your window is visible.
Then close the window and open a new window with the visible size that you found. Then restore the mouse pointer to the position it was in originally.
????? I guess it would work. Any reasons why not?
I guess you'd have to take into account that at least on the Mac you can't open a window that covers the title bar, and maybe on the PC you can't open a window that covers the task bar (not sure about Linux) .... so should subtract a bit from the verticle size? Also what about window borders?
Is there a better reliable way?
Also, how to get GraphicsHertz()? Does it work in OpenGL and DirectX?
And how to get the color depth? Draw something with an 8-bit-per-component color resolution, flip the display, set the glReadBuffer() to the front buffer, grab the drawn piece into a 32-bit pixmap, look at the color resolution to see if what you drew came out in 32-bit or 16-bit? Also if it dithered, you might be able to detect some `un-pure` pixels? This would tell you if the desktop is 32-bit or 16-bit or whatever? Would it work?
Any other solutions?