mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-10-17 03:49:28 +00:00
Implement "Desktop" resolution (0x0, default). Also fix music slider update in options menu
This makes the window resizable in desktop mode, and fixed size otherwise. Fullscreen desktop has always the dame resolution as the desktop. Add config setting to specify initial display. Add config setting for the refresh rate (not yet properly integrated) Closes #17
This commit is contained in:
parent
40e5385636
commit
b781b45789
8 changed files with 280 additions and 145 deletions
301
BBGE/Core.cpp
301
BBGE/Core.cpp
|
@ -69,6 +69,7 @@ static std::ofstream _logOut;
|
|||
#define KMOD_GUI KMOD_META
|
||||
#endif
|
||||
|
||||
|
||||
void Core::resetCamera()
|
||||
{
|
||||
cameraPos = Vector(0,0);
|
||||
|
@ -145,11 +146,45 @@ void Core::setup_opengl()
|
|||
}
|
||||
|
||||
|
||||
void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp)
|
||||
void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp, int display)
|
||||
{
|
||||
assert(lib_graphics);
|
||||
|
||||
bool wasFullscreen = _fullscreen;
|
||||
const int oldDisplay = getDisplayIndex();
|
||||
if(display == -1)
|
||||
display = oldDisplay;
|
||||
|
||||
int screenw = 0, screenh = 0;
|
||||
if(display >= 0)
|
||||
{
|
||||
SDL_DisplayMode desktop;
|
||||
if(SDL_GetDesktopDisplayMode(display, &desktop) == 0)
|
||||
{
|
||||
screenw = desktop.w;
|
||||
screenh = desktop.h;
|
||||
}
|
||||
else // fail-safe
|
||||
{
|
||||
screenw = 800;
|
||||
screenh = 600;
|
||||
display = oldDisplay;
|
||||
}
|
||||
|
||||
// Move window to specified display if necessary
|
||||
if(display != oldDisplay)
|
||||
{
|
||||
SDL_Rect bounds;
|
||||
SDL_GetDisplayBounds(display,&bounds);
|
||||
SDL_SetWindowPosition(gScreen, bounds.x, bounds.y);
|
||||
}
|
||||
}
|
||||
|
||||
const int oldw = width;
|
||||
const int oldh = height;
|
||||
|
||||
|
||||
const bool useDesktop = w == 0 || h == 0 || (oldw && w == -1 && oldh && h == -1 && _useDesktopResolution);
|
||||
const bool wasFullscreen = _fullscreen;
|
||||
|
||||
if (fullscreen == -1)
|
||||
fullscreen = _fullscreen;
|
||||
|
@ -157,6 +192,12 @@ void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp)
|
|||
if (vsync == -1)
|
||||
vsync = _vsync;
|
||||
|
||||
if(useDesktop)
|
||||
{
|
||||
w = screenw;
|
||||
h = screenh;
|
||||
}
|
||||
|
||||
if (w == -1)
|
||||
w = width;
|
||||
|
||||
|
@ -166,10 +207,6 @@ void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp)
|
|||
if (bpp == -1)
|
||||
bpp = _bpp;
|
||||
|
||||
int oldw = width;
|
||||
int oldh = height;
|
||||
width = w;
|
||||
height = h;
|
||||
_vsync = vsync;
|
||||
_fullscreen = fullscreen;
|
||||
_bpp = bpp;
|
||||
|
@ -183,51 +220,57 @@ void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp)
|
|||
else
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
|
||||
if(w != oldw|| h != oldh)
|
||||
SDL_SetWindowSize(gScreen, w, h);
|
||||
// Record window position so we can properly restore it when leaving fullscreen
|
||||
if(fullscreen && !wasFullscreen)
|
||||
SDL_GetWindowPosition(gScreen, &winPosX, &winPosY);
|
||||
|
||||
if(!!fullscreen != wasFullscreen)
|
||||
{
|
||||
int screenflags = 0;
|
||||
if(fullscreen)
|
||||
{
|
||||
// Record window position so we can properly restore it when leaving fullscreen
|
||||
if(!wasFullscreen)
|
||||
SDL_GetWindowPosition(gScreen, &winPosX, &winPosY);
|
||||
|
||||
// Use desktop fullscreen if possible, but only if the resolution
|
||||
// matches the actual desktop resolution.
|
||||
// Else we'll get unused areas on the screen.
|
||||
int disp = SDL_GetWindowDisplayIndex(gScreen);
|
||||
if(disp >= 0)
|
||||
{
|
||||
SDL_DisplayMode desktop;
|
||||
if(SDL_GetDesktopDisplayMode(disp, &desktop) == 0)
|
||||
{
|
||||
if(w == desktop.w && h == desktop.h)
|
||||
{
|
||||
screenflags = SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
debugLog("Switching to desktop fullscreen");
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!screenflags)
|
||||
{
|
||||
screenflags = SDL_WINDOW_FULLSCREEN;
|
||||
debugLog("Switching to fullscreen");
|
||||
}
|
||||
screenflags |= useDesktop ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN;
|
||||
}
|
||||
|
||||
SDL_SetWindowFullscreen(gScreen, screenflags);
|
||||
|
||||
if(!fullscreen)
|
||||
if(!fullscreen && wasFullscreen)
|
||||
{
|
||||
// Need to do this; else the window ends up at (0, 0) with the title bar outside the screen area
|
||||
SDL_SetWindowPosition(gScreen, winPosX, winPosY);
|
||||
}
|
||||
}
|
||||
|
||||
bool resize = true;
|
||||
bool reloadRes = false;
|
||||
if(useDesktop != _useDesktopResolution)
|
||||
{
|
||||
if(useDesktop)
|
||||
createWindow(oldw, oldh, true, fullscreen);
|
||||
else
|
||||
createWindow(w, h, false, fullscreen);
|
||||
|
||||
reloadRes = true;
|
||||
if(useDesktop)
|
||||
{
|
||||
SDL_MaximizeWindow(gScreen);
|
||||
resize = false;
|
||||
}
|
||||
}
|
||||
// First time called + windowed mode --> maximize window
|
||||
else if(!oldw && !oldh && useDesktop && !fullscreen)
|
||||
{
|
||||
SDL_MaximizeWindow(gScreen);
|
||||
resize = false;
|
||||
}
|
||||
|
||||
if(resize && !fullscreen && !useDesktop)
|
||||
{
|
||||
if(w != oldw|| h != oldh)
|
||||
{
|
||||
SDL_SetWindowSize(gScreen, w, h);
|
||||
if(wasFullscreen)
|
||||
{
|
||||
// Need to do this; else the window ends up at (0, 0) with the title bar outside the screen area
|
||||
SDL_SetWindowPosition(gScreen, winPosX, winPosY);
|
||||
}
|
||||
int c = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
|
||||
SDL_SetWindowPosition(gScreen, c, c);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,16 +280,33 @@ void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp)
|
|||
|
||||
#endif
|
||||
|
||||
_useDesktopResolution = useDesktop;
|
||||
|
||||
SDL_GetWindowSize(gScreen, &w, &h);
|
||||
|
||||
updateWindowDrawSize(w, h);
|
||||
|
||||
if(reloadRes)
|
||||
{
|
||||
unloadResources();
|
||||
reloadResources();
|
||||
resetTimer();
|
||||
}
|
||||
}
|
||||
|
||||
void Core::updateWindowDrawSize(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
setup_opengl();
|
||||
|
||||
enable2DWide(w, h);
|
||||
|
||||
reloadDevice();
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
void Core::onWindowResize(int w, int h)
|
||||
{
|
||||
initGraphics(w, h);
|
||||
updateWindowDrawSize(w, h);
|
||||
}
|
||||
|
||||
void Core::setFullscreen(bool full)
|
||||
|
@ -440,6 +500,7 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
|
|||
doScreenshot = false;
|
||||
baseCullRadius = 1;
|
||||
width = height = 0;
|
||||
_fullscreen = false;
|
||||
afterEffectManagerLayer = 0;
|
||||
renderObjectLayers.resize(1);
|
||||
invGlobalScale = 1.0;
|
||||
|
@ -586,6 +647,20 @@ bool Core::isFullscreen()
|
|||
return _fullscreen;
|
||||
}
|
||||
|
||||
bool Core::isDesktopResolution()
|
||||
{
|
||||
return _useDesktopResolution;
|
||||
}
|
||||
|
||||
int Core::getDisplayIndex()
|
||||
{
|
||||
#ifdef BBGE_BUILD_SDL2
|
||||
return SDL_GetWindowDisplayIndex(gScreen);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Core::isShuttingDown()
|
||||
{
|
||||
return shuttingDown;
|
||||
|
@ -752,7 +827,7 @@ void Core::setClearColor(const Vector &c)
|
|||
|
||||
}
|
||||
|
||||
bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsync, int bpp)
|
||||
bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsync, int bpp, int display)
|
||||
{
|
||||
assert(!gScreen);
|
||||
|
||||
|
@ -783,62 +858,7 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsyn
|
|||
#endif
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
|
||||
{
|
||||
#ifdef BBGE_BUILD_SDL2
|
||||
Uint32 flags = 0;
|
||||
flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE;
|
||||
if (fullscreen)
|
||||
flags |= SDL_WINDOW_FULLSCREEN;
|
||||
gScreen = SDL_CreateWindow(appName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags);
|
||||
if (gScreen == NULL)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Couldn't set resolution [" << width << "x" << height << "]\n" << SDL_GetError();
|
||||
errorLog(os.str());
|
||||
SDL_Quit();
|
||||
exit(0);
|
||||
}
|
||||
gGLctx = SDL_GL_CreateContext(gScreen);
|
||||
if (gGLctx == NULL)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Couldn't create OpenGL context!\n" << SDL_GetError();
|
||||
errorLog(os.str());
|
||||
SDL_Quit();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
{
|
||||
const char *name = SDL_GetCurrentVideoDriver();
|
||||
std::ostringstream os2;
|
||||
os2 << "Video Driver Name [" << name << "]";
|
||||
debugLog(os2.str());
|
||||
}
|
||||
|
||||
#else
|
||||
Uint32 flags = 0;
|
||||
flags = SDL_OPENGL;
|
||||
if (fullscreen)
|
||||
flags |= SDL_FULLSCREEN;
|
||||
|
||||
gScreen = SDL_SetVideoMode(width, height, bpp, flags);
|
||||
if (gScreen == NULL)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Couldn't set resolution [" << width << "x" << height << "]\n" << SDL_GetError();
|
||||
SDL_Quit();
|
||||
exit_error(os.str());
|
||||
}
|
||||
|
||||
{
|
||||
char name[256];
|
||||
SDL_VideoDriverName((char*)name, 256);
|
||||
std::ostringstream os2;
|
||||
os2 << "Video Driver Name [" << name << "]";
|
||||
debugLog(os2.str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
createWindow(width, height, !width && !height, fullscreen);
|
||||
|
||||
#if BBGE_BUILD_OPENGL_DYNAMIC
|
||||
if (SDL_GL_LoadLibrary(NULL) == -1)
|
||||
|
@ -866,7 +886,7 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsyn
|
|||
|
||||
enumerateScreenModes();
|
||||
|
||||
initGraphics(width, height, fullscreen, vsync, bpp);
|
||||
initGraphics(width, height, fullscreen, vsync, bpp, display);
|
||||
|
||||
_hasFocus = true;
|
||||
|
||||
|
@ -874,11 +894,90 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsyn
|
|||
return true;
|
||||
}
|
||||
|
||||
void Core::createWindow(int w, int h, bool resizable, bool fullscreen)
|
||||
{
|
||||
if(w <= 0)
|
||||
w = 640;
|
||||
if(h <= 0)
|
||||
h = 480;
|
||||
|
||||
#ifdef BBGE_BUILD_SDL2
|
||||
if(gScreen)
|
||||
{
|
||||
SDL_DestroyWindow(gScreen);
|
||||
gScreen = NULL;
|
||||
}
|
||||
if(gGLctx)
|
||||
{
|
||||
SDL_GL_MakeCurrent(gScreen, NULL);
|
||||
SDL_GL_DeleteContext(gGLctx);
|
||||
gGLctx = NULL;
|
||||
}
|
||||
Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
|
||||
if(resizable)
|
||||
flags |= SDL_WINDOW_RESIZABLE;
|
||||
//if(fullscreen) // Ignore fullscreen setting here, it's applied later
|
||||
// flags |= SDL_WINDOW_FULLSCREEN;
|
||||
gScreen = SDL_CreateWindow(appName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, flags);
|
||||
if (gScreen == NULL)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Couldn't set resolution [" << w << "x" << h << "]\n" << SDL_GetError();
|
||||
errorLog(os.str());
|
||||
SDL_Quit();
|
||||
exit(0);
|
||||
}
|
||||
gGLctx = SDL_GL_CreateContext(gScreen);
|
||||
if (gGLctx == NULL)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Couldn't create OpenGL context!\n" << SDL_GetError();
|
||||
errorLog(os.str());
|
||||
SDL_Quit();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
{
|
||||
const char *name = SDL_GetCurrentVideoDriver();
|
||||
std::ostringstream os2;
|
||||
os2 << "Video Driver Name [" << name << "]";
|
||||
debugLog(os2.str());
|
||||
}
|
||||
|
||||
#else
|
||||
Uint32 flags = 0;
|
||||
flags = SDL_OPENGL;
|
||||
if(fullscreen)
|
||||
flags |= SDL_FULLSCREEN;
|
||||
if (resizable)
|
||||
flags |= SDL_RESIZABLE;
|
||||
|
||||
gScreen = SDL_SetVideoMode(width, height, bpp, flags);
|
||||
if (gScreen == NULL)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Couldn't set resolution [" << width << "x" << height << "]\n" << SDL_GetError();
|
||||
SDL_Quit();
|
||||
exit_error(os.str());
|
||||
}
|
||||
|
||||
{
|
||||
char name[256];
|
||||
SDL_VideoDriverName((char*)name, 256);
|
||||
std::ostringstream os2;
|
||||
os2 << "Video Driver Name [" << name << "]";
|
||||
debugLog(os2.str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Core::enumerateScreenModes()
|
||||
{
|
||||
screenModes.clear();
|
||||
|
||||
#ifdef BBGE_BUILD_SDL2
|
||||
screenModes.push_back(ScreenMode(0, 0, 0)); // "Desktop" screen mode
|
||||
|
||||
SDL_DisplayMode mode;
|
||||
const int modecount = SDL_GetNumDisplayModes(0);
|
||||
if(modecount == 0){
|
||||
|
@ -890,7 +989,7 @@ void Core::enumerateScreenModes()
|
|||
SDL_GetDisplayMode(0, i, &mode);
|
||||
if (mode.w && mode.h && (mode.w > mode.h))
|
||||
{
|
||||
screenModes.push_back(ScreenMode(i, mode.w, mode.h, mode.refresh_rate));
|
||||
screenModes.push_back(ScreenMode(mode.w, mode.h, mode.refresh_rate));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
16
BBGE/Core.h
16
BBGE/Core.h
|
@ -41,10 +41,10 @@ class ParticleManager;
|
|||
|
||||
struct ScreenMode
|
||||
{
|
||||
ScreenMode() { idx = x = y = hz = 0; }
|
||||
ScreenMode(int i, int x, int y, int hz) : idx(i), x(x), y(y), hz(hz) {}
|
||||
ScreenMode() { x = y = hz = 0; }
|
||||
ScreenMode(int x, int y, int hz) : x(x), y(y), hz(hz) {}
|
||||
|
||||
int idx, x, y, hz;
|
||||
int x, y, hz;
|
||||
};
|
||||
|
||||
struct CoreSettings
|
||||
|
@ -278,7 +278,8 @@ public:
|
|||
|
||||
unsigned getTicks();
|
||||
|
||||
void initGraphics(int w, int h, int fullscreen=-1, int vsync=-1, int bpp=-1);
|
||||
void initGraphics(int w, int h, int fullscreen=-1, int vsync=-1, int bpp=-1, int display=-1); // pass 0x0 for desktop resolution
|
||||
void updateWindowDrawSize(int w, int h);
|
||||
|
||||
Vector getGameCursorPosition();
|
||||
Vector getGamePosition(const Vector &v);
|
||||
|
@ -413,6 +414,8 @@ public:
|
|||
void updateInputGrab();
|
||||
|
||||
bool isFullscreen();
|
||||
bool isDesktopResolution();
|
||||
int getDisplayIndex();
|
||||
|
||||
int getVirtualOffX();
|
||||
int getVirtualOffY();
|
||||
|
@ -480,7 +483,8 @@ protected:
|
|||
bool initSoundLibrary(const std::string &defaultDevice);
|
||||
bool initInputLibrary();
|
||||
void initJoystickLibrary();
|
||||
bool initGraphicsLibrary(int w, int h, bool fullscreen, bool vsync, int bpp);
|
||||
bool initGraphicsLibrary(int w, int h, bool fullscreen, bool vsync, int bpp, int display);
|
||||
void createWindow(int w, int h, bool resizable, bool fullscreen);
|
||||
void shutdownInputLibrary();
|
||||
void shutdownJoystickLibrary();
|
||||
void shutdownGraphicsLibrary();
|
||||
|
@ -510,7 +514,7 @@ protected:
|
|||
int nowTicks, thenTicks;
|
||||
|
||||
int _vsync, _bpp;
|
||||
bool _fullscreen;
|
||||
bool _fullscreen, _useDesktopResolution;
|
||||
int winPosX, winPosY; // pre-fullscreen
|
||||
|
||||
CountedPtr<Texture> texError;
|
||||
|
|
|
@ -97,6 +97,8 @@ bool FrameBuffer::init(int width, int height, bool fitToScreen)
|
|||
return false;
|
||||
}
|
||||
|
||||
unloadDevice();
|
||||
|
||||
//
|
||||
// Create a frame-buffer object and a render-buffer object...
|
||||
//
|
||||
|
@ -177,7 +179,6 @@ void FrameBuffer::unloadDevice()
|
|||
|
||||
if (g_frameBuffer)
|
||||
{
|
||||
debugLog("bind 0");
|
||||
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, 0 );
|
||||
|
||||
debugLog("frameBuffer handle present, deleting");
|
||||
|
@ -187,7 +188,6 @@ void FrameBuffer::unloadDevice()
|
|||
|
||||
if (g_dynamicTextureID)
|
||||
{
|
||||
debugLog("bind 0");
|
||||
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, 0 );
|
||||
|
||||
debugLog("dynamic texture ID handle present, deleting");
|
||||
|
@ -197,7 +197,6 @@ void FrameBuffer::unloadDevice()
|
|||
|
||||
if (g_depthRenderBuffer)
|
||||
{
|
||||
debugLog("bind 0");
|
||||
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, 0 );
|
||||
|
||||
debugLog("depth render buffer handle present, deleting");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue