How do I find out the current screen resolution

I’ve been trying without success to change to a fullscreen video mode
MATCHING the current screen resolution. Where can I get this
information through SDL? I know it stores it somewhere because it
remembers what resolution to return to after you quit.
Any way to access it?
There are some functions like GetVideoSurface which seem to make
sense, but you get a null until the video mode is set and then you are
getting SDL’s new window res not the screen res. Thanks, in advance.

Aaron

I’ve been trying without success to change to a fullscreen video mode
MATCHING the current screen resolution. Where can I get this
information through SDL? I know it stores it somewhere because it
remembers what resolution to return to after you quit.
Any way to access it?
There are some functions like GetVideoSurface which seem to make
sense, but you get a null until the video mode is set and then you are
getting SDL’s new window res not the screen res. Thanks, in advance.

Aaron

Hi Aaron.

I have this code for test what resolution have my monitor:

--------------------- code -----------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include “SDL.h”

int main()
{
SDL_Surface *pantalla;
SDL_Rect **modes;

int i;

if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
fprintf(stderr, “Can’t open SDL: %s\n”, SDL_GetError());
exit(1);
}
atexit(SDL_Quit);

if ((pantalla = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE)) == NULL)
{
fprintf(stderr, “Can’t create window: %s\n”, SDL_GetError());
exit(2);
}

/* Get available fullscreen/hardware modes */
modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_SWSURFACE);

/* Check is there are any modes available */
if (modes == (SDL_Rect **)0)
{
printf(“No modes available! \n”);
exit(-1);
}

/* Check if or resolution is restricted */
if (modes == (SDL_Rect *) - 1)
{
printf(“All resolutions available. \n”);
}
else
{
/
Print valid modes */
printf(“Available Modes \n”);
for (i = 0; modes[i]; ++i)
printf(" %d x %d\n", modes[i]->w, modes[i]->h);
}

SDL_UpdateRect(pantalla, 0, 0, 0, 0);

exit(0);
}
--------------------- code -----------------------

The matter is the function SDL_ListModes() that
can back to you the resolution.

I hope this can be useful for you and others.

Regards.

Jose.

http://www.lordofunix.org

Registered BSD User 51101.
Registered Linux User #213309.
Memories… You are talking about memories.
Rick Deckard. Blade Runner.----------------------------------
Tu correo gratuito 10 MB en http://www.geomundos.com
Tambi?n acceso a Internet, chat, titulares… ?Pru?balo!
Nuevo: Las mejores ofertas en http://compras.geomundos.com

Thanks for the reply. That is useful and I have similar code already.

What I was looking for, however, is a way to determine the screen
resolution BEFORE the video mode is switched.
In other words, the player hasn’t started the game yet, and they are using
1024 x 768. I want whatever THAT resolution is to be the primary
fullscreen option by default, so they can use a resolution I know they
are comfortable with.

Anyone have an option for me here?

Anyone have an option for me here?

You may have to use OS specific code to achieve this.
Dig around in the documentation of the OS, or try
google, to see if there is anything.__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs
http://hotjobs.sweepstakes.yahoo.com/careermakeover

You may have to use OS specific code to achieve this.
I thought that might be the case. Unfortunately, it’s not
important enough for me to spend the time researching
it for each platform. Thanks for the reply, though!

The thing is, I know SDL keeps track of it for each platform
because it restores the settings after quitting… Maybe I’ll
dig into the SDL code if I feel I need the feature badly enough.

Just thought someone might have done that already :slight_smile:

Hello !

It would be usefull to have things like
this, maybe in an SDL helper library called
for example SDL_os :slight_smile:

CU>> You may have to use OS specific code to achieve this.

I thought that might be the case. Unfortunately, it’s not
important enough for me to spend the time researching
it for each platform. Thanks for the reply, though!

The thing is, I know SDL keeps track of it for each platform
because it restores the settings after quitting… Maybe I’ll
dig into the SDL code if I feel I need the feature badly enough.

Just thought someone might have done that already :slight_smile:


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

This is planned for SDL 1.3… patches welcome. :slight_smile:

See ya!
-Sam Lantinga, Software Engineer, Blizzard Entertainment