mirror of
https://github.com/glest/glest-source.git
synced 2025-08-22 07:52:51 +02:00
- allow changes to video resolution and fullscreen mode without restart
This commit is contained in:
@@ -1694,9 +1694,8 @@ void getFullscreenVideoModes(vector<ModeInfo> *modeinfos, bool isFullscreen) {
|
||||
|
||||
|
||||
|
||||
bool changeVideoMode(int resW, int resH, int colorBits, int ) {
|
||||
Private::shouldBeFullscreen = true;
|
||||
return true;
|
||||
void changeVideoModeFullScreen(bool value) {
|
||||
Private::shouldBeFullscreen = value;
|
||||
}
|
||||
|
||||
void restoreVideoMode(bool exitingApp) {
|
||||
|
@@ -105,6 +105,8 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
|
||||
// try different color bits
|
||||
screen = SDL_SetVideoMode(resW, resH, i, flags);
|
||||
if(screen != 0) {
|
||||
glViewport( 0, 0, resW, resH ) ;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -116,6 +118,8 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
|
||||
if(screen != 0) {
|
||||
resW = 800;
|
||||
resH = 600;
|
||||
|
||||
glViewport( 0, 0, resW, resH ) ;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -127,6 +131,8 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
|
||||
if(screen != 0) {
|
||||
resW = 640;
|
||||
resH = 480;
|
||||
|
||||
glViewport( 0, 0, resW, resH ) ;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -136,6 +142,10 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
|
||||
throw std::runtime_error(msg.str());
|
||||
}
|
||||
}
|
||||
else {
|
||||
glViewport( 0, 0, resW, resH ) ;
|
||||
//printf("Reset resolution to [%d] x [%d]\n",resW, resH);
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
string mg_icon_file = "";
|
||||
|
@@ -12,9 +12,12 @@
|
||||
|
||||
#include "gl_wrap.h"
|
||||
#include "graphics_interface.h"
|
||||
#include "util.h"
|
||||
#include "platform_util.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Graphics;
|
||||
using namespace Shared::Util;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
@@ -44,4 +47,90 @@ void WindowGl::swapBuffersGl(){
|
||||
context.swapBuffers();
|
||||
}
|
||||
|
||||
// changes display resolution at any time
|
||||
bool WindowGl::ChangeVideoMode(bool preserveContext, int resWidth, int resHeight,
|
||||
bool fullscreenWindow,
|
||||
int colorBits, int depthBits, int stencilBits, bool hardware_acceleration,
|
||||
bool fullscreen_anti_aliasing, float gammaValue) {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d] preserveContext = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,preserveContext);
|
||||
|
||||
#ifdef WIN32
|
||||
if(preserveContext == true) {
|
||||
SDL_SysWMinfo info;
|
||||
|
||||
// get window handle from SDL
|
||||
SDL_VERSION(&info.version);
|
||||
if (SDL_GetWMInfo(&info) == -1) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s %d] SDL_GetWMInfo #1 failed\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
// get device context handle
|
||||
HDC tempDC = GetDC( info.window );
|
||||
|
||||
// create temporary context
|
||||
HGLRC tempRC = wglCreateContext( tempDC );
|
||||
if (tempRC == NULL) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s %d] wglCreateContext failed\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
// share resources to temporary context
|
||||
SetLastError(0);
|
||||
if (!wglShareLists(info.hglrc, tempRC)) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s %d] wglShareLists #1 failed\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// set video mode
|
||||
//if (!SetVideoMode())
|
||||
// return false;
|
||||
// this->initGl(config.getInt("ColorBits"),
|
||||
// config.getInt("DepthBits"),
|
||||
// config.getInt("StencilBits"),
|
||||
// config.getBool("HardwareAcceleration","false"),
|
||||
// config.getBool("FullScreenAntiAliasing","false"),
|
||||
// config.getFloat("GammaValue","0.0"));
|
||||
|
||||
|
||||
this->setStyle(fullscreenWindow ? wsWindowedFixed: wsFullscreen);
|
||||
this->setPos(0, 0);
|
||||
this->setSize(resWidth, resHeight);
|
||||
|
||||
this->initGl(colorBits, depthBits, stencilBits,hardware_acceleration,
|
||||
fullscreen_anti_aliasing,gammaValue);
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
|
||||
this->makeCurrentGl();
|
||||
|
||||
#ifdef WIN32
|
||||
if(preserveContext == true) {
|
||||
// previously used structure may possibly be invalid, to be sure we get it again
|
||||
SDL_VERSION(&info.version);
|
||||
if (SDL_GetWMInfo(&info) == -1) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s %d] SDL_GetWMInfo #2 failed\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
// share resources to new SDL-created context
|
||||
if (!wglShareLists(tempRC, info.hglrc)) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s %d] wglShareLists #2 failed\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
// we no longer need our temporary context
|
||||
if (!wglDeleteContext(tempRC)) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s %d] wglDeleteContext failed\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// success
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}}//end namespace
|
||||
|
Reference in New Issue
Block a user