From 00a039fffea099eb53d2bbe77d3300b3d7ea768f Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 5 Feb 2008 23:40:20 +0000 Subject: make keyboard input actually work --- src/client/video.cc | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'src/client/video.cc') diff --git a/src/client/video.cc b/src/client/video.cc index df11b90..f7ae792 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -18,11 +18,15 @@ namespace client { namespace video { -const int defaultwidth = 1024; -const int defaultheight = 768; - int width = 0; int height = 0; + +int width_prev = 0; +int height_prev = 0; + +const int width_default = 1024; +const int height_default = 768; + float aspect = 1; //--- cvars ------------------------------------------------------- @@ -48,8 +52,8 @@ bool init() con_print << "Initializing video..." << std::endl; // initialize cvars - r_width = core::cvar::get("r_width", defaultwidth); - r_height = core::cvar::get("r_height", defaultheight); + r_width = core::cvar::get("r_width", width_default); + r_height = core::cvar::get("r_height", height_default); r_fullscreen = core::cvar::get("r_fullscreen", 1); int bpp = 0; @@ -66,8 +70,11 @@ bool init() return false; } - width = 1024; - height = 768; + width_prev = width; + height_prev = height; + width = (int) r_width->value(); + height = (int) r_height->value(); + bpp = sdl_videoinfo->vfmt->BitsPerPixel; SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); @@ -80,10 +87,17 @@ bool init() flags = SDL_OPENGL | SDL_FULLSCREEN; if(!SDL_SetVideoMode(width, height, bpp, flags )) { - std::cerr << "SDL_SetVideoMode() failed: " << SDL_GetError() << std::endl; - return false; + con_warn << "Failed to set video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl; + if (width_prev && height_prev) { + width = width_prev; + height = height_prev; + if(!SDL_SetVideoMode(width, height, bpp, flags )) { + con_error << "Failed to restore video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl; + return false; + } + } else + return false; } - con_print << " video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl; aspect = (float) width / (float) height; -- cgit v1.2.3