18 #include "precompiled.h"
45 m_IsFullscreen(false), m_IsInitialised(false), m_Window(NULL),
46 m_PreferredW(0), m_PreferredH(0), m_PreferredBPP(0), m_PreferredFreq(0),
47 m_ConfigW(0), m_ConfigH(0), m_ConfigBPP(0), m_ConfigFullscreen(false), m_ConfigForceS3TCEnable(true),
68 #if SDL_VERSION_ATLEAST(2, 0, 0)
70 Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
72 flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
74 flags |= SDL_WINDOW_RESIZABLE;
78 m_Window = SDL_CreateWindow(
"0 A.D.", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, flags);
84 LOGWARNING(L
"Failed to set the video mode to fullscreen for the chosen resolution "
85 L
"%dx%d:%d (\"%hs\"), falling back to windowed mode",
93 LOGERROR(L
"SetVideoMode failed in SDL_CreateWindow: %dx%d:%d %d (\"%hs\")",
99 if (SDL_SetWindowDisplayMode(
m_Window, NULL) < 0)
101 LOGERROR(L
"SetVideoMode failed in SDL_SetWindowDisplayMode: %dx%d:%d %d (\"%hs\")",
106 SDL_GLContext context = SDL_GL_CreateContext(
m_Window);
109 LOGERROR(L
"SetVideoMode failed in SDL_GL_CreateContext: %dx%d:%d %d (\"%hs\")",
118 if (SDL_SetWindowFullscreen(
m_Window, flags) < 0)
120 LOGERROR(L
"SetVideoMode failed in SDL_SetWindowFullscreen: %dx%d:%d %d (\"%hs\")",
135 SDL_SetWindowGrab(
m_Window, SDL_TRUE);
137 SDL_SetWindowGrab(
m_Window, SDL_FALSE);
157 LOGWARNING(L
"Failed to set the video mode to fullscreen for the chosen resolution "
158 L
"%dx%d:%d (\"%hs\"), falling back to windowed mode",
166 LOGERROR(L
"SetVideoMode failed: %dx%d:%d %d (\"%hs\")",
209 if (w == 0 || h == 0)
217 if (w == 0 || h == 0)
237 #if !SDL_VERSION_ATLEAST(1, 3, 0)
241 #if CONFIG2_GLES && SDL_VERSION_ATLEAST(1, 3, 0)
257 #if SDL_VERSION_ATLEAST(1, 3, 0)
258 SDL_GL_SetSwapInterval(
g_VSync ? 1 : 0);
274 #if SDL_VERSION_ATLEAST(2, 0, 0)
276 SDL_CalculateGammaRamp(
g_Gamma, ramp);
277 if (SDL_SetWindowGammaRamp(
m_Window, ramp, ramp, ramp) < 0)
332 #if !(OS_WIN || OS_MACOSX) // (assume Mesa is used for all non-Windows non-Mac platforms)
334 setenv(
"force_s3tc_enable",
"true", 0);
386 if (w == 0 ||
h == 0)
391 if (w == 0 ||
h == 0)
bool SetVideoMode(int w, int h, int bpp, bool fullscreen)
int setenv(const char *envname, const char *envval, int overwrite)
rationale: the Windows headers declare many POSIX functions (e.g.
SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode)
static int DEFAULT_WINDOW_H
#define CFG_GET_VAL(name, type, destination)
bool ToggleFullscreen()
Switch between fullscreen and windowed mode.
LIB_API Status GetVideoMode(int *xres, int *yres, int *bpp, int *freq)
(useful for choosing a new video mode)
int SDL_GL_SetAttribute(SDL_GLattr attr, int value)
void UpdateResolution()
See CGUI::UpdateResolution; applies to all loaded pages.
void SetViewport(const SViewPort &vp)
bool ResizeWindow(int w, int h)
Resize the SDL window and associated graphics stuff to the new size.
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
void Shutdown()
Shut down after InitSDL/InitNonSDL, so that they can be used again.
static int DEFAULT_WINDOW_W
static int DEFAULT_FULLSCREEN_H
CGame * g_Game
Globally accessible pointer to the CGame object.
static void UpdateRenderer(int w, int h)
Update the graphics code to start drawing to the new size.
bool InitNonSDL()
Initialise parts of the video mode, for use in Atlas (which uses wxWidgets instead of SDL for GL)...
static bool IsInitialised()
struct SDL_Window SDL_Window
CGameView * GetView()
Get the pointer to the game view object.
bool m_IsInitialised
Remember whether Init has been called.
void ogl_Init()
initialization: import extension function pointers and do feature detect.
bool SetFullscreen(bool fullscreen)
Switch to fullscreen or windowed mode.
static int DEFAULT_FULLSCREEN_W
bool m_ConfigForceS3TCEnable
int SDL_SetGamma(float r, float g, float b)
SDL_Surface * SDL_SetVideoMode(int w, int h, int bpp, Uint32 flags)
bool InitSDL()
Initialise the video mode, for use in an SDL-using application.
void UpdateScreenSize(int w, int h)
size_t flags
see TexFlags and "Format Conversion" in docs.