detect available resolutions and offer them in the menu

Store the resolutions detected by SDL in a cvar. The mod code can
then optionally use the cvar to offer a better choice in the menu.

Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
This commit is contained in:
Ludwig Nussel 2007-12-08 10:08:05 +00:00
parent f2cbb819fc
commit 6b5fbd189d
2 changed files with 172 additions and 19 deletions

View file

@ -110,6 +110,46 @@ void GLimp_LogComment( char *comment )
{
}
static void set_available_modes(void)
{
char buf[MAX_STRING_CHARS];
SDL_Rect **modes;
size_t len = 0;
int i;
modes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN);
if (!modes)
{
ri.Printf( PRINT_WARNING, "Can't get list of available modes\n");
return;
}
if (modes == (SDL_Rect **)-1)
{
ri.Printf( PRINT_ALL, "Display supports any resolution\n");
return; // can set any resolution
}
for (i = 0; modes[i]; ++i)
{
if(snprintf(NULL, 0, "%ux%u ", modes[i]->w, modes[i]->h) < (int)sizeof(buf)-len)
{
len += sprintf(buf+len, "%ux%u ", modes[i]->w, modes[i]->h);
}
else
{
ri.Printf( PRINT_WARNING, "Skipping mode %ux%x, buffer too small\n", modes[i]->w, modes[i]->h);
}
}
if(len)
{
buf[strlen(buf)-1] = 0;
ri.Printf( PRINT_ALL, "Available modes: '%s'\n", buf);
ri.Cvar_Set( "r_availableModes", buf );
}
}
/*
===============
GLimp_SetMode
@ -275,6 +315,8 @@ static int GLimp_SetMode( int mode, qboolean fullscreen )
break;
}
set_available_modes();
if (!vidscreen)
{
ri.Printf( PRINT_ALL, "Couldn't get a visual\n" );
@ -526,6 +568,8 @@ void GLimp_Init( void )
// initialize extensions
GLimp_InitExtensions( );
ri.Cvar_Get( "r_availableModes", "", CVAR_ROM );
// This depends on SDL_INIT_VIDEO, hence having it here
IN_Init( );