Setting up maximum resolution available on startup

BlitzMax Forums/BlitzMax Tutorials/Setting up maximum resolution available on startup

Brazilian Joe(Posted 2009) [#1]
Disclaimer
I am not an expert BlitzMax programmer, in fact I am a beginner.
My code does not try to be optimal, i just try to get the stuff I want done, without being too hackish. If there is something too ugly about it, please post and i will review it, feedback is welcome. End of line.

Motivation
While I understand that for the sake of simplicity, tutorials and code snippets usually use a hard-coded fixed resolution, like 800x600 windowed, to be sure anyone will be able to see the code in action in their monitors, I wanted to venture my initial coding on, well, the first thing you need to do when you create a game: set the screen mode.

I don't like very much games running on windows, or games which select a low resolution by default. I would appreciate if when I open a game, it understands my screen native resolution and uses it by default. If performance suffers, then I would set a different resolution.

So I set up this task for me: starting up at full screen, maximum resolution, 32bpp and at the highest screen refresh rate available.

The useful functions
There are two functions which came to my rescue: GraphicsModes() and CountGraphicsModes(). The latter just give me an int stating how many graphic modes are available, and the former returns an array of the actual graphics modes.

Each item the GraphicsModes() returned collection has four integer values: width, height, depth (bits per pixel) and hertz (screen refresh rate).

I may be wrong, but I figured the function calls could be expensive (it's just a wild guess, mind you), so i decided to store the value in an array, and reuse memorized values later on.

Algorithm

I decided to accomplish my goal using a simple method: I would simply add the four values (width,height,depth and hertz), and select the mode which gave me the highest result. No special treatment of screen size first, then bit depth, then hertz individually. Crude, but effective. Since a bit depth of zero equals to windowed mode, and I wanted to avoid it, it is just what I want.

So, I need two variables for the index and sum calculated for the current object, plus two to store the highest values found, and loop through the array with the stored graphics modes.

To be sure I am doing it all right, I will write all screen modes to screen.
I set up two variables for the vertical and horizontal position of the text (although I only used the one for the vertical position).

Next steps
What i will do next, and will be left as an exercise to the reader (and the writer!), is to:
1) store the value in a config file;
2) provide an interface to customize the screen mode and store it accordingly, exposing all screen modes available, refresh rates and windowed/fulscreen options;

The Code

It basically show everything I have done, with a few comments interspersed: