27 #include <boost/bind.hpp> 70 const uint32 sdlInitFlags = SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;
71 if (SDL_Init(sdlInitFlags) < 0)
94 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
95 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
96 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
97 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
98 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
100 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (fsaa > 0) ? 1 : 0);
101 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
105 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorVersion);
106 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorVersion);
107 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, type);
110 SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, useDebug ? SDL_GL_CONTEXT_DEBUG_FLAG : 0);
116 warning(
"Could not create OpenGL %i.%i context: %s", majorVersion, minorVersion, SDL_GetError());
124 Common::UString version(reinterpret_cast<const char *>(glGetString(GL_VERSION)));
131 status(
"OpenGL context successfully created:");
132 SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &majorVersion);
133 SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minorVersion);
135 SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, ¤tFsaa);
136 status(
"OpenGL version: %i.%i", majorVersion, minorVersion);
137 status(
"FSAA level : %ix", currentFsaa);
161 result = SDL_SetWindowFullscreen(
_window, SDL_WINDOW_FULLSCREEN);
163 result = SDL_SetWindowFullscreen(
_window, 0);
167 throw Common::Exception(
"Unable to set %s mode: %s", (fullScreen ?
"fullscreen" :
"windowed"), SDL_GetError());
173 SDL_GetWindowSize(
_window, &width, &height);
208 SDL_SetWindowSize(
_window, width, height);
210 SDL_DisplayMode displayMode;
211 result = SDL_GetWindowDisplayMode(
_window, &displayMode);
213 displayMode.w = width;
214 displayMode.h = height;
215 result = SDL_SetWindowDisplayMode(
_window, &displayMode);
220 throw Common::Exception(
"Unable to set window size to %ix%i: %s", width, height, SDL_GetError());
231 const int numDisplays = SDL_GetNumVideoDisplays();
233 std::vector<DisplayMode> modes;
234 for (
int i = 0; i < numDisplays; ++i) {
235 const int numModes = SDL_GetNumDisplayModes(i);
237 for (
int j = 0; j < numModes; ++j) {
239 SDL_GetDisplayMode(i, j, &mode);
240 modes.push_back(mode);
248 int displayIndex = SDL_GetWindowDisplayIndex(
_window);
249 SDL_DisplayMode maxWidth;
251 SDL_GetDisplayMode(displayIndex, 0, &maxWidth);
257 int displayIndex = SDL_GetWindowDisplayIndex(
_window);
258 SDL_DisplayMode maxHeight;
260 SDL_GetDisplayMode(displayIndex, 0, &maxHeight);
271 return SDL_GetWindowFlags(
_window);
273 uint32 flags = SDL_WINDOW_OPENGL;
275 flags |= SDL_WINDOW_FULLSCREEN;
280 int x =
ConfigMan.getInt(
"x", SDL_WINDOWPOS_UNDEFINED);
281 int y =
ConfigMan.getInt(
"y", SDL_WINDOWPOS_UNDEFINED);
303 for (
int i = 32; i >= 2; i >>= 1) {
304 SDL_GL_SetAttribute(SDL_GL_RED_SIZE , 8);
305 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE , 8);
306 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE , 8);
307 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE , 8);
308 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
310 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
311 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, i);
313 SDL_Window *testScreen = SDL_CreateWindow(
"nrst", 0, 0, 1, 1, SDL_WINDOW_OPENGL);
315 SDL_GLContext context = SDL_GL_CreateContext(testScreen);
317 SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &
_fsaaMax);
320 SDL_GL_DeleteContext(context);
321 SDL_DestroyWindow(testScreen);
325 SDL_DestroyWindow(testScreen);
356 SDL_CalculateGammaRamp(gamma, gammaRamp);
358 int result = SDL_SetWindowGammaRamp(
_window, gammaRamp, gammaRamp, gammaRamp);
360 error(
"Failed to set gamma to %f: %s", gamma, SDL_GetError());
366 SDL_WarpMouseInWindow(
_window, x, y);
385 SDL_ShowCursor(SDL_ENABLE);
387 SDL_ShowCursor(SDL_DISABLE);
393 SDL_SetWindowGrab(
_window, (SDL_bool) !SDL_GetWindowGrab(
_window));
int getWindowHeight() const
Return the current window height.
void showCursor(bool show)
Show/Hide the cursor.
Inter-thread request events.
Make the render window display our icon.
void setWindowIcon(SDL_Window &window)
Common::UString _windowTitle
The current window title.
A class holding an UTF-8 string.
int _width
The game's window width.
Template specialization for a MainThreadFunctor returning void.
The global config manager.
bool beginsWith(const UString &with) const
bool isMainThread()
Returns true if called from the main thread, false otherwise.
int getSystemHeight() const
Return the system's screen height.
void deinit()
Deinitialize the window manager.
SDL_Window * _window
The OpenGL hardware surface.
int getSystemWidth() const
Return the system's screen width.
#define NotificationMan
Shortcut for accessing the notification manager.
int _fsaaMax
Max supported FSAA level.
The global window manager.
void setWindowSize(int width, int height)
Set the window size.
bool initRender(RenderType type, bool useDebug, int fsaa)
Setup the Render Context on the window.
void init()
Initialize the window manager.
The notification manager, handling all notifications.
Basic exceptions to throw.
Threading system helpers.
Common::Mutex _cursorMutex
A mutex locked for the cursor.
const char * c_str() const
Return the (utf8 encoded) string data.
CursorState _cursorState
What to do with the cursor.
float getGamma() const
Get the overall gamma correction.
#define ConfigMan
Shortcut for accessing the config manager.
Utility templates and functions.
int getWindowWidth() const
Return the current window width.
Basic xoreos version information.
#define DECLARE_SINGLETON(T)
Note that you need to use this macro from the global namespace.
int getMaxFSAA() const
Return the max supported FSAA level.
int _height
The game's window height.
const char * getProjectNameVersion()
void setWindowTitle(const Common::UString &title="")
Set the window's title.
void initWindow(uint32 flags)
bool empty() const
Is the string empty?
void handleCursorSwitch()
bool isFullScreen() const
Are we currently in full screen mode?
void warning(const char *s,...)
Convenience class that locks a mutex on creation and unlocks it on destruction.
void setFullScreen(bool fullScreen)
Set full screen/windowed mode.
void enforceMainThread()
Throws an Exception if called from a non-main thread.
bool _fullScreen
Are we currently in fullscreen mode?
void status(const char *s,...)
SDL_DisplayMode DisplayMode
#define RequestMan
Shortcut for accessing the request manager.
void toggleMouseGrab()
Toggle mouse grab.
void toggleFullScreen()
Toggle between full screen and windowed mode.
float _gamma
The current gamma correction value.
std::vector< DisplayMode > getDisplayModes()
Get all possible display modes.
void NORETURN_PRE error(const char *s,...)
void setCursorPosition(int x, int y)
Set position to the cursor.
void setGamma(float gamma)
Set the overall gamma correction.