- for now make fullscreen mode ONLY use desktop resolution, all other tries seem buggy in SDL2

This commit is contained in:
SoftCoder
2015-10-04 20:34:54 -07:00
parent 9e6e4dd6fe
commit d80ca9e0b2
8 changed files with 117 additions and 28 deletions

View File

@@ -738,6 +738,23 @@ void Program::exit() {
// ==================== PRIVATE ==================== // ==================== PRIVATE ====================
void Program::initResolution() {
const Metrics &metrics = Metrics::getInstance();
if(window->getScreenWidth() != metrics.getScreenW() ||
window->getScreenHeight() != metrics.getScreenH()) {
int oldW = metrics.getScreenW();
int oldH = metrics.getScreenH();
Config &config= Config::getInstance();
config.setInt("ScreenWidth",window->getScreenWidth(),true);
config.setInt("ScreenHeight",window->getScreenHeight(),true);
metrics.reload(window->getScreenWidth(), window->getScreenHeight());
printf("MainWindow forced change of resolution to desktop values (%d x %d) instead of (%d x %d)\n",metrics.getScreenW(), metrics.getScreenH(),oldW,oldH);
}
}
void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
@@ -809,6 +826,7 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
window->makeCurrentGl(); window->makeCurrentGl();
initResolution();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
@@ -948,6 +966,7 @@ void Program::reInitGl() {
config.getBool("FullScreenAntiAliasing","false"), config.getBool("FullScreenAntiAliasing","false"),
config.getFloat("GammaValue","0.0")); config.getFloat("GammaValue","0.0"));
window->setText(config.getString("WindowTitle","MegaGlest")); window->setText(config.getString("WindowTitle","MegaGlest"));
initResolution();
} }
} }

View File

@@ -233,6 +233,7 @@ private:
void setDisplaySettings(); void setDisplaySettings();
void restoreDisplaySettings(); void restoreDisplaySettings();
void restoreStateFromSystemError(); void restoreStateFromSystemError();
void initResolution();
}; };
}} //end namespace }} //end namespace

View File

@@ -523,8 +523,10 @@ void MenuStateOptionsGraphics::revertScreenMode(){
config.getBool("HardwareAcceleration","false"), config.getBool("HardwareAcceleration","false"),
config.getBool("FullScreenAntiAliasing","false"), config.getBool("FullScreenAntiAliasing","false"),
config.getFloat("GammaValue","0.0")); config.getFloat("GammaValue","0.0"));
Metrics::reload(this->program->getWindow()->getScreenWidth(),
this->program->getWindow()->getScreenHeight());
window->setText(config.getString("WindowTitle","MegaGlest")); window->setText(config.getString("WindowTitle","MegaGlest"));
Metrics::reload();
this->mainMenu->init(); this->mainMenu->init();
} }
@@ -635,7 +637,9 @@ void MenuStateOptionsGraphics::mouseClick(int x, int y, MouseButton mouseButton)
config.getBool("FullScreenAntiAliasing","false"), config.getBool("FullScreenAntiAliasing","false"),
strToFloat(listBoxGammaCorrection.getSelectedItem())); strToFloat(listBoxGammaCorrection.getSelectedItem()));
Metrics::reload(selectedMode->width,selectedMode->height); Metrics::reload(this->program->getWindow()->getScreenWidth(),
this->program->getWindow()->getScreenHeight());
this->mainMenu->init(); this->mainMenu->init();
mainMessageBoxState=1; mainMessageBoxState=1;

View File

@@ -122,7 +122,7 @@ private:
static map<wchar_t,bool> mapAllowedKeys; static map<wchar_t,bool> mapAllowedKeys;
protected: protected:
int w, h; //int w, h;
static bool isActive; static bool isActive;
static bool no2DMouseRendering; static bool no2DMouseRendering;
static bool allowAltEnterFullscreenToggle; static bool allowAltEnterFullscreenToggle;
@@ -149,6 +149,9 @@ public:
static void clearAllowedKeys(); static void clearAllowedKeys();
static bool isAllowedKey(wchar_t key); static bool isAllowedKey(wchar_t key);
virtual int getScreenWidth() = 0;
virtual int getScreenHeight() = 0;
virtual bool ChangeVideoMode(bool preserveContext,int resWidth, int resHeight, virtual bool ChangeVideoMode(bool preserveContext,int resWidth, int resHeight,
bool fullscreenWindow, int colorBits, int depthBits, int stencilBits, bool fullscreenWindow, int colorBits, int depthBits, int stencilBits,
bool hardware_acceleration, bool fullscreen_anti_aliasing, bool hardware_acceleration, bool fullscreen_anti_aliasing,
@@ -163,8 +166,8 @@ public:
string getText(); string getText();
int getX() { return 0; } int getX() { return 0; }
int getY() { return 0; } int getY() { return 0; }
int getW() { return w; } int getW() { return getScreenWidth(); }
int getH() { return h; } int getH() { return getScreenHeight(); }
//component state //component state
int getClientW() { return getW(); } int getClientW() { return getW(); }

View File

@@ -43,6 +43,8 @@ public:
SDL_Window * getScreenWindow(); SDL_Window * getScreenWindow();
SDL_Surface * getScreenSurface(); SDL_Surface * getScreenSurface();
virtual int getScreenWidth();
virtual int getScreenHeight();
virtual bool ChangeVideoMode(bool preserveContext, int resWidth, int resHeight, virtual bool ChangeVideoMode(bool preserveContext, int resWidth, int resHeight,
bool fullscreenWindow, int colorBits, int depthBits, int stencilBits, bool fullscreenWindow, int colorBits, int depthBits, int stencilBits,

View File

@@ -78,10 +78,13 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
//printf("In [%s::%s %d] PlatformCommon::Private::shouldBeFullscreen = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,PlatformCommon::Private::shouldBeFullscreen); //printf("In [%s::%s %d] PlatformCommon::Private::shouldBeFullscreen = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,PlatformCommon::Private::shouldBeFullscreen);
int flags = SDL_WINDOW_OPENGL; // SDL_WINDOW_FULLSCREEN seems very broken when changing resolutions that differ from the desktop resolution
// For now fullscreen will mean use desktop resolution
int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
if(PlatformCommon::Private::shouldBeFullscreen) { if(PlatformCommon::Private::shouldBeFullscreen) {
flags |= SDL_WINDOW_FULLSCREEN;
Window::setIsFullScreen(true); Window::setIsFullScreen(true);
//flags |= SDL_WINDOW_FULLSCREEN;
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
} }
else { else {
Window::setIsFullScreen(false); Window::setIsFullScreen(false);
@@ -97,19 +100,44 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to set resolution: %d x %d, colorBits = %d.\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,resW,resH,colorBits); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to set resolution: %d x %d, colorBits = %d.\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,resW,resH,colorBits);
if(Window::getIsFullScreen() && (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
//printf("#1 SDL_WINDOW_FULLSCREEN_DESKTOP\n");
// TODO: which display? is 0 the designated primary display always?
SDL_Rect display_rect;
SDL_GetDisplayBounds(0, &display_rect);
if(PlatformCommon::Private::ScreenWidth != display_rect.w ||
PlatformCommon::Private::ScreenHeight != display_rect.h) {
printf("Auto Change resolution to (%d x %d) from (%d x %d)\n",display_rect.w,display_rect.h,resW,resH);
resW = display_rect.w;
resH = display_rect.h;
PlatformCommon::Private::ScreenWidth = display_rect.w;
PlatformCommon::Private::ScreenHeight = display_rect.h;
}
}
int windowX = SDL_WINDOWPOS_UNDEFINED; int windowX = SDL_WINDOWPOS_UNDEFINED;
int windowY = SDL_WINDOWPOS_UNDEFINED; int windowY = SDL_WINDOWPOS_UNDEFINED;
string windowTitleText = "MG"; string windowTitleText = "MG";
int windowDisplayID = -1;
if(window != NULL) { if(window != NULL) {
SDL_GetWindowPosition(window,&windowX,&windowY); SDL_GetWindowPosition(window,&windowX,&windowY);
windowDisplayID = SDL_GetWindowDisplayIndex( window );
//printf("windowDisplayID = %d\n",windowDisplayID);
if(Window::getIsFullScreen()) {
windowX = SDL_WINDOWPOS_CENTERED_DISPLAY(windowDisplayID);
windowY = SDL_WINDOWPOS_CENTERED_DISPLAY(windowDisplayID);
}
windowTitleText = SDL_GetWindowTitle(window); windowTitleText = SDL_GetWindowTitle(window);
//SDL_FreeSurface(getScreenSurface());
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
window = NULL; window = NULL;
} }
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
//screen = SDL_CreateWindow(resW, resH, colorBits, flags); //screen = SDL_CreateWindow(resW, resH, colorBits, flags);
window = SDL_CreateWindow(windowTitleText.c_str(),windowX,windowY,resW, resH, flags); window = SDL_CreateWindow(windowTitleText.c_str(),windowX,windowY,resW, resH, flags);
if(window == 0) { if(window == 0) {
@@ -139,20 +167,14 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
} }
} }
if(Window::getIsFullScreen()) { // int totalDisplays = SDL_GetNumVideoDisplays();
SDL_SetWindowDisplayMode(window,NULL); // windowDisplayID = SDL_GetWindowDisplayIndex( window );
} // printf("!!! totalDisplays = %d, windowDisplayID = %d\n",totalDisplays,windowDisplayID);
if(glcontext != NULL) { //SDL_SetWindowDisplayMode(window, NULL);
if(Window::getIsFullScreen()) {
SDL_SetWindowFullscreen(window,SDL_WINDOW_FULLSCREEN);
}
else {
SDL_SetWindowFullscreen(window,0);
}
}
if(glcontext == NULL) { bool isNewWindow = (glcontext == NULL);
if(isNewWindow) {
glcontext = SDL_GL_CreateContext(window); glcontext = SDL_GL_CreateContext(window);
} }
else { else {
@@ -162,6 +184,27 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
int h; int h;
int w; int w;
SDL_GetWindowSize(window, &w, &h); SDL_GetWindowSize(window, &w, &h);
if((w != resW || h != resH) && (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
//printf("#2 SDL_WINDOW_FULLSCREEN_DESKTOP\n");
printf("#1 Change resolution mismatch get (%d x %d) desired (%d x %d)\n",w,h,resW,resH);
PlatformCommon::Private::ScreenWidth = w;
PlatformCommon::Private::ScreenHeight = h;
resW = PlatformCommon::Private::ScreenWidth;
resH = PlatformCommon::Private::ScreenHeight;
printf("#2 Change resolution to (%d x %d)\n",resW,resH);
// SDL_SetWindowFullscreen(window,0);
// SDL_SetWindowSize(window, resW, resH);
// SDL_SetWindowFullscreen(window,flags);
// SDL_SetWindowSize(window, resW, resH);
//
// SDL_GetWindowSize(window, &w, &h);
// printf("#2 Change resolution mismatch get (%d x %d) desired (%d x %d)\n",w,resW,h,resH);
}
glViewport( 0, 0, w, h ) ; glViewport( 0, 0, w, h ) ;
// There seems to be a bug where if relative mouse mouse is enabled when you create a new window, // There seems to be a bug where if relative mouse mouse is enabled when you create a new window,
@@ -287,14 +330,23 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
// SDL_WM_GrabInput(SDL_GRAB_ON); // SDL_WM_GrabInput(SDL_GRAB_ON);
// SDL_WM_GrabInput(SDL_GRAB_OFF); // SDL_WM_GrabInput(SDL_GRAB_OFF);
//SDL_SetRelativeMouseMode(SDL_TRUE); SDL_SetRelativeMouseMode(SDL_TRUE);
SDL_SetRelativeMouseMode(SDL_FALSE); SDL_SetRelativeMouseMode(SDL_FALSE);
// if(Window::getIsFullScreen()) // if(Window::getIsFullScreen())
// SDL_SetWindowGrab(window, SDL_TRUE); // SDL_SetWindowGrab(window, SDL_TRUE);
// else // else
// SDL_SetWindowGrab(window, SDL_FALSE); SDL_SetWindowGrab(window, SDL_FALSE);
// if(Window::getIsFullScreen()) {
// SDL_SetWindowSize(window, resW, resH);
// //SDL_SetWindowFullscreen(window,SDL_WINDOW_FULLSCREEN);
// SDL_SetWindowSize(window, resW, resH);
// }
// SDL_SetRelativeMouseMode(SDL_TRUE);
// SDL_SetRelativeMouseMode(SDL_FALSE);
} }
} }

View File

@@ -108,8 +108,8 @@ static bool isUnprintableChar(SDL_keysym key)
Window::Window() { Window::Window() {
this->sdlWindow=0; this->sdlWindow=0;
// Default to 1x1 until set by caller to avoid divide by 0 // Default to 1x1 until set by caller to avoid divide by 0
this->w = 1; //this->w = 1;
this->h = 1; //this->h = 1;
for(int idx = 0; idx < mbCount; idx++) { for(int idx = 0; idx < mbCount; idx++) {
lastMouseDown[idx] = 0; lastMouseDown[idx] = 0;
@@ -137,8 +137,8 @@ Window::Window() {
Window::Window(SDL_Window *sdlWindow) { Window::Window(SDL_Window *sdlWindow) {
this->sdlWindow=sdlWindow; this->sdlWindow=sdlWindow;
// Default to 1x1 until set by caller to avoid divide by 0 // Default to 1x1 until set by caller to avoid divide by 0
this->w = 1; //this->w = 1;
this->h = 1; //this->h = 1;
for(int idx = 0; idx < mbCount; idx++) { for(int idx = 0; idx < mbCount; idx++) {
lastMouseDown[idx] = 0; lastMouseDown[idx] = 0;
@@ -485,8 +485,8 @@ void Window::setText(string text) {
} }
void Window::setSize(int w, int h) { void Window::setSize(int w, int h) {
this->w = w; //this->w = w;
this->h = h; //this->h = h;
Private::ScreenWidth = w; Private::ScreenWidth = w;
Private::ScreenHeight = h; Private::ScreenHeight = h;
} }

View File

@@ -38,6 +38,14 @@ WindowGl::WindowGl(SDL_Window *sdlWindow) : Window(sdlWindow) {
WindowGl::~WindowGl() { WindowGl::~WindowGl() {
} }
int WindowGl::getScreenWidth() {
return PlatformCommon::Private::ScreenWidth;
}
int WindowGl::getScreenHeight() {
return PlatformCommon::Private::ScreenHeight;
}
void WindowGl::setGamma(SDL_Window *window,float gammaValue) { void WindowGl::setGamma(SDL_Window *window,float gammaValue) {
//SDL_SetGamma(gammaValue, gammaValue, gammaValue); //SDL_SetGamma(gammaValue, gammaValue, gammaValue);
//SDL_SetWindowGammaRamp(getSDLWindow(), gammaValue, gammaValue, gammaValue); //SDL_SetWindowGammaRamp(getSDLWindow(), gammaValue, gammaValue, gammaValue);