From ff0cfef33b01b1146306b0f6d81bf3604789c546 Mon Sep 17 00:00:00 2001 From: ludwig Date: Sat, 8 Dec 2007 10:08:05 +0000 Subject: 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 git-svn-id: svn://svn.icculus.org/quake3/trunk@1231 edf5b092-35ff-0310-97b2-ce42778d08ea --- code/sdl/sdl_glimp.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'code/sdl') diff --git a/code/sdl/sdl_glimp.c b/code/sdl/sdl_glimp.c index a1e1a27..be2ab18 100644 --- a/code/sdl/sdl_glimp.c +++ b/code/sdl/sdl_glimp.c @@ -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( ); -- cgit v1.2.3