- for now make fullscreen mode ONLY use desktop resolution, all other tries seem buggy in SDL2
This commit is contained in:
parent
9e6e4dd6fe
commit
d80ca9e0b2
|
@ -738,6 +738,23 @@ void Program::exit() {
|
|||
|
||||
// ==================== 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){
|
||||
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__);
|
||||
|
||||
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__);
|
||||
|
||||
|
@ -948,6 +966,7 @@ void Program::reInitGl() {
|
|||
config.getBool("FullScreenAntiAliasing","false"),
|
||||
config.getFloat("GammaValue","0.0"));
|
||||
window->setText(config.getString("WindowTitle","MegaGlest"));
|
||||
initResolution();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -233,6 +233,7 @@ private:
|
|||
void setDisplaySettings();
|
||||
void restoreDisplaySettings();
|
||||
void restoreStateFromSystemError();
|
||||
void initResolution();
|
||||
};
|
||||
|
||||
}} //end namespace
|
||||
|
|
|
@ -523,8 +523,10 @@ void MenuStateOptionsGraphics::revertScreenMode(){
|
|||
config.getBool("HardwareAcceleration","false"),
|
||||
config.getBool("FullScreenAntiAliasing","false"),
|
||||
config.getFloat("GammaValue","0.0"));
|
||||
Metrics::reload(this->program->getWindow()->getScreenWidth(),
|
||||
this->program->getWindow()->getScreenHeight());
|
||||
window->setText(config.getString("WindowTitle","MegaGlest"));
|
||||
Metrics::reload();
|
||||
|
||||
this->mainMenu->init();
|
||||
}
|
||||
|
||||
|
@ -635,7 +637,9 @@ void MenuStateOptionsGraphics::mouseClick(int x, int y, MouseButton mouseButton)
|
|||
config.getBool("FullScreenAntiAliasing","false"),
|
||||
strToFloat(listBoxGammaCorrection.getSelectedItem()));
|
||||
|
||||
Metrics::reload(selectedMode->width,selectedMode->height);
|
||||
Metrics::reload(this->program->getWindow()->getScreenWidth(),
|
||||
this->program->getWindow()->getScreenHeight());
|
||||
|
||||
this->mainMenu->init();
|
||||
|
||||
mainMessageBoxState=1;
|
||||
|
|
|
@ -122,7 +122,7 @@ private:
|
|||
static map<wchar_t,bool> mapAllowedKeys;
|
||||
|
||||
protected:
|
||||
int w, h;
|
||||
//int w, h;
|
||||
static bool isActive;
|
||||
static bool no2DMouseRendering;
|
||||
static bool allowAltEnterFullscreenToggle;
|
||||
|
@ -149,6 +149,9 @@ public:
|
|||
static void clearAllowedKeys();
|
||||
static bool isAllowedKey(wchar_t key);
|
||||
|
||||
virtual int getScreenWidth() = 0;
|
||||
virtual int getScreenHeight() = 0;
|
||||
|
||||
virtual bool ChangeVideoMode(bool preserveContext,int resWidth, int resHeight,
|
||||
bool fullscreenWindow, int colorBits, int depthBits, int stencilBits,
|
||||
bool hardware_acceleration, bool fullscreen_anti_aliasing,
|
||||
|
@ -163,8 +166,8 @@ public:
|
|||
string getText();
|
||||
int getX() { return 0; }
|
||||
int getY() { return 0; }
|
||||
int getW() { return w; }
|
||||
int getH() { return h; }
|
||||
int getW() { return getScreenWidth(); }
|
||||
int getH() { return getScreenHeight(); }
|
||||
|
||||
//component state
|
||||
int getClientW() { return getW(); }
|
||||
|
|
|
@ -43,6 +43,8 @@ public:
|
|||
|
||||
SDL_Window * getScreenWindow();
|
||||
SDL_Surface * getScreenSurface();
|
||||
virtual int getScreenWidth();
|
||||
virtual int getScreenHeight();
|
||||
|
||||
virtual bool ChangeVideoMode(bool preserveContext, int resWidth, int resHeight,
|
||||
bool fullscreenWindow, int colorBits, int depthBits, int stencilBits,
|
||||
|
|
|
@ -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);
|
||||
|
||||
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) {
|
||||
flags |= SDL_WINDOW_FULLSCREEN;
|
||||
Window::setIsFullScreen(true);
|
||||
//flags |= SDL_WINDOW_FULLSCREEN;
|
||||
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
}
|
||||
else {
|
||||
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::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 windowY = SDL_WINDOWPOS_UNDEFINED;
|
||||
string windowTitleText = "MG";
|
||||
int windowDisplayID = -1;
|
||||
|
||||
if(window != NULL) {
|
||||
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);
|
||||
//SDL_FreeSurface(getScreenSurface());
|
||||
|
||||
SDL_DestroyWindow(window);
|
||||
window = NULL;
|
||||
}
|
||||
|
||||
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);
|
||||
window = SDL_CreateWindow(windowTitleText.c_str(),windowX,windowY,resW, resH, flags);
|
||||
if(window == 0) {
|
||||
|
@ -139,20 +167,14 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
|
|||
}
|
||||
}
|
||||
|
||||
if(Window::getIsFullScreen()) {
|
||||
SDL_SetWindowDisplayMode(window,NULL);
|
||||
}
|
||||
// int totalDisplays = SDL_GetNumVideoDisplays();
|
||||
// windowDisplayID = SDL_GetWindowDisplayIndex( window );
|
||||
// printf("!!! totalDisplays = %d, windowDisplayID = %d\n",totalDisplays,windowDisplayID);
|
||||
|
||||
if(glcontext != NULL) {
|
||||
if(Window::getIsFullScreen()) {
|
||||
SDL_SetWindowFullscreen(window,SDL_WINDOW_FULLSCREEN);
|
||||
}
|
||||
else {
|
||||
SDL_SetWindowFullscreen(window,0);
|
||||
}
|
||||
}
|
||||
//SDL_SetWindowDisplayMode(window, NULL);
|
||||
|
||||
if(glcontext == NULL) {
|
||||
bool isNewWindow = (glcontext == NULL);
|
||||
if(isNewWindow) {
|
||||
glcontext = SDL_GL_CreateContext(window);
|
||||
}
|
||||
else {
|
||||
|
@ -162,6 +184,27 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
|
|||
int h;
|
||||
int w;
|
||||
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 ) ;
|
||||
|
||||
// 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_OFF);
|
||||
//SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
|
||||
|
||||
// if(Window::getIsFullScreen())
|
||||
// SDL_SetWindowGrab(window, SDL_TRUE);
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,8 +108,8 @@ static bool isUnprintableChar(SDL_keysym key)
|
|||
Window::Window() {
|
||||
this->sdlWindow=0;
|
||||
// Default to 1x1 until set by caller to avoid divide by 0
|
||||
this->w = 1;
|
||||
this->h = 1;
|
||||
//this->w = 1;
|
||||
//this->h = 1;
|
||||
|
||||
for(int idx = 0; idx < mbCount; idx++) {
|
||||
lastMouseDown[idx] = 0;
|
||||
|
@ -137,8 +137,8 @@ Window::Window() {
|
|||
Window::Window(SDL_Window *sdlWindow) {
|
||||
this->sdlWindow=sdlWindow;
|
||||
// Default to 1x1 until set by caller to avoid divide by 0
|
||||
this->w = 1;
|
||||
this->h = 1;
|
||||
//this->w = 1;
|
||||
//this->h = 1;
|
||||
|
||||
for(int idx = 0; idx < mbCount; idx++) {
|
||||
lastMouseDown[idx] = 0;
|
||||
|
@ -485,8 +485,8 @@ void Window::setText(string text) {
|
|||
}
|
||||
|
||||
void Window::setSize(int w, int h) {
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
//this->w = w;
|
||||
//this->h = h;
|
||||
Private::ScreenWidth = w;
|
||||
Private::ScreenHeight = h;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,14 @@ WindowGl::WindowGl(SDL_Window *sdlWindow) : Window(sdlWindow) {
|
|||
WindowGl::~WindowGl() {
|
||||
}
|
||||
|
||||
int WindowGl::getScreenWidth() {
|
||||
return PlatformCommon::Private::ScreenWidth;
|
||||
|
||||
}
|
||||
int WindowGl::getScreenHeight() {
|
||||
return PlatformCommon::Private::ScreenHeight;
|
||||
}
|
||||
|
||||
void WindowGl::setGamma(SDL_Window *window,float gammaValue) {
|
||||
//SDL_SetGamma(gammaValue, gammaValue, gammaValue);
|
||||
//SDL_SetWindowGammaRamp(getSDLWindow(), gammaValue, gammaValue, gammaValue);
|
||||
|
|
Loading…
Reference in New Issue