auto adjust the screen resolution on first start. Closes #921

This commit is contained in:
oy 2012-03-04 12:46:55 +01:00
parent 38256d0d45
commit 2a4af1573b
6 changed files with 24 additions and 10 deletions

View file

@ -388,7 +388,7 @@ void CCommandProcessor_SDL_OpenGL::RunBuffer(CCommandBuffer *pBuffer)
// ------------ CGraphicsBackend_SDL_OpenGL
int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int Width, int Height, int FsaaSamples, int Flags)
int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags)
{
if(!SDL_WasInit(SDL_INIT_VIDEO))
{
@ -407,6 +407,13 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int Width, int Height,
const SDL_VideoInfo *pInfo = SDL_GetVideoInfo();
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); // prevent stuck mouse cursor sdl-bug when loosing fullscreen focus in windows
// use current resolution as default
if(*Width == 0 || *Height == 0)
{
*Width = pInfo->current_w;
*Height = pInfo->current_h;
}
// set flags
int SdlFlags = SDL_OPENGL;
if(Flags&IGraphicsBackend::INITFLAG_RESIZABLE)
@ -442,7 +449,7 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int Width, int Height,
SDL_WM_SetCaption(pName, pName);
// create window
m_pScreenSurface = SDL_SetVideoMode(Width, Height, 0, SdlFlags);
m_pScreenSurface = SDL_SetVideoMode(*Width, *Height, 0, SdlFlags);
if(!m_pScreenSurface)
{
dbg_msg("gfx", "unable to set video mode: %s", SDL_GetError());

View file

@ -188,7 +188,7 @@ class CGraphicsBackend_SDL_OpenGL : public CGraphicsBackend_Threaded
ICommandProcessor *m_pProcessor;
SGLContext m_GLContext;
public:
virtual int Init(const char *pName, int Width, int Height, int FsaaSamples, int Flags);
virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags);
virtual int Shutdown();
virtual void Minimize();

View file

@ -761,12 +761,19 @@ int CGraphics_OpenGL::Init()
int CGraphics_SDL::TryInit()
{
m_ScreenWidth = g_Config.m_GfxScreenWidth;
m_ScreenHeight = g_Config.m_GfxScreenHeight;
const SDL_VideoInfo *pInfo = SDL_GetVideoInfo();
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); // prevent stuck mouse cursor sdl-bug when loosing fullscreen focus in windows
// use current resolution as default
if(g_Config.m_GfxScreenWidth == 0 || g_Config.m_GfxScreenHeight == 0)
{
g_Config.m_GfxScreenWidth = pInfo->current_w;
g_Config.m_GfxScreenHeight = pInfo->current_h;
}
m_ScreenWidth = g_Config.m_GfxScreenWidth;
m_ScreenHeight = g_Config.m_GfxScreenHeight;
// set flags
int Flags = SDL_OPENGL;
if(g_Config.m_DbgResizable)

View file

@ -716,7 +716,7 @@ int CGraphics_Threaded::IssueInit()
if(g_Config.m_GfxVsync) Flags |= IGraphicsBackend::INITFLAG_VSYNC;
if(g_Config.m_DbgResizable) Flags |= IGraphicsBackend::INITFLAG_RESIZABLE;
return m_pBackend->Init("Teeworlds", g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, g_Config.m_GfxFsaaSamples, Flags);
return m_pBackend->Init("Teeworlds", &g_Config.m_GfxScreenWidth, &g_Config.m_GfxScreenHeight, g_Config.m_GfxFsaaSamples, Flags);
}
int CGraphics_Threaded::InitWindow()

View file

@ -302,7 +302,7 @@ public:
INITFLAG_RESIZABLE = 4,
};
virtual int Init(const char *pName, int Width, int Height, int FsaaSamples, int Flags) = 0;
virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags) = 0;
virtual int Shutdown() = 0;
virtual void Minimize() = 0;

View file

@ -57,8 +57,8 @@ MACRO_CONFIG_INT(SndDevice, snd_device, -1, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "
MACRO_CONFIG_INT(SndNonactiveMute, snd_nonactive_mute, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(GfxScreenWidth, gfx_screen_width, 800, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution width")
MACRO_CONFIG_INT(GfxScreenHeight, gfx_screen_height, 600, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution height")
MACRO_CONFIG_INT(GfxScreenWidth, gfx_screen_width, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution width")
MACRO_CONFIG_INT(GfxScreenHeight, gfx_screen_height, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution height")
MACRO_CONFIG_INT(GfxFullscreen, gfx_fullscreen, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Fullscreen")
MACRO_CONFIG_INT(GfxAlphabits, gfx_alphabits, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Alpha bits for framebuffer (fullscreen only)")
MACRO_CONFIG_INT(GfxColorDepth, gfx_color_depth, 24, 16, 24, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Colors bits for framebuffer (fullscreen only)")