Detecting current screen resolution (again!)

I’m almost ready to distribute my game, and other people’s beta-playtests
confirmed what I suspected: I NEED to know the current screen resolution.

With that, I could set the fullscreen mode at the current resolution, and every
end-user is happy. Without that, any default I set is badly wrong for someone,
and I so need to add a “select your preferred screen resolution” screen, which
really detracts from the immediacy of the game :(((. bad bad. I cannot
distribute it like that.

Now, I know, for having tryied about every possible way, that there is no way in
SDL to detect the current screen resolution. This leaves two options:

(A) wait for the next SDL version to let me do it.

or

(B) add some platform specific part in my code (a-la “#ifdef _WIN32…”) and
implement it for just a couple of cases - yes that would limit the portability
of the code.----------------------------------
about (A): can anybody tell me if it is likely to happen? and if so, when? (I
only recently strted using SDL and have no idea about new-version frequency);
also can I do anything to help?

Let me also suggest the simplest way (from the point of view of the
library-user, not the SDL-dev) to have that: make
SDL_SetVideoMode(sx,sx,bpp,flags), when

  • flags includes SDL_FULLSCREEN and
  • (sx,sy,bpp)==(0,0,0)
    set the fullscreen mode at the current screen bpp, size x, and y.

Also, VideoInfo would return screen res as well. BTW isn’t it peculiar that it
currently doesn’t? I wonder if it is that nobody though that it would be useful,
or if there is problem I can’t see implementing it in some system.

As for (B) - and now I’m going off topic in this board I aplogize - anybody
coded it already?

Any help greatly appreciated!

Marco

Marco Tarini wrote:

I’m almost ready to distribute my game, and other people’s beta-playtests
confirmed what I suspected: I NEED to know the current screen resolution.

completely agreeable rationale

Now, I know, for having tryied about every possible way, that there is no way in
SDL to detect the current screen resolution. This leaves two options:

(A) wait for the next SDL version to let me do it.

or

(B) add some platform specific part in my code (a-la “#ifdef _WIN32…”) and
implement it for just a couple of cases - yes that would limit the portability
of the code.


about (A): can anybody tell me if it is likely to happen? and if so, when? (I
only recently strted using SDL and have no idea about new-version frequency);
also can I do anything to help?

Let me also suggest the simplest way (from the point of view of the
library-user, not the SDL-dev) to have that: make
SDL_SetVideoMode(sx,sx,bpp,flags), when

  • flags includes SDL_FULLSCREEN and
  • (sx,sy,bpp)==(0,0,0)
    set the fullscreen mode at the current screen bpp, size x, and y.

Also, VideoInfo would return screen res as well. BTW isn’t it peculiar that it
currently doesn’t? I wonder if it is that nobody though that it would be useful,
or if there is problem I can’t see implementing it in some system.

I wrote a patch to add a function to get the current desktop resolution.
Unfortunately, it’s only implemented for X11 and Windows. There was a
thread about it on this list which starts here:


and continues in February:

To summarise the thread:

It was widely agreed that this would be useful functionality. Some
people didn’t like my API (int SDL_GetDesktopMode(int *width, int
*height)), and it doesn’t allow for complete binary compatibility
(programs that use the new function can’t run with earlier SDL 1.2
libs). Stephane Marchesin suggested adding the information to the
SDL_VideoInfo structure. This can’t be done without breaking binary
compatibility, so will have to wait for SDL 1.3 (I don’t know if there’s
a schedule for that yet). Simon Roby suggested the same API as you did
above. I was not wild about it, because it makes it harder/more
error-prone to specify a fallback default resolution, which is
particularly important when the functionality isn’t implemented for all
the SDL platforms/video drivers.

Sam Lantinga (lead developer of SDL) chimed in that he likes the idea of
using 0,0 in SDL_SetVideoMode to specify the desktop resolution, which
can be done now, in SDL 1.2. He also likes the idea of adding the
desktop resolution to SDL_VideoInfo at a later date.

So, it seems like it would be sensible for me to rewrite my patch to use
the 0,0 API, make sure it’s documented well to minimise problems, and
accept a little ugliness in our application code which can be removed
when SDL 1.3 is available. I’ll get to work on it, since Ryan just made
a call for patches, and that would seem like a good chance of getting my
code commited and in the next release.

As for (B) - and now I’m going off topic in this board I aplogize - anybody
coded it already?

If you’re packaging your own build of SDL with your game, feel free to
use my patch. If not, you could use the code from it for X11 and Windows
in your game.–
Jon