#include <iostream>
#include <physfs.h>
#include "SDL.h"
-//#include "SDL/SDL.h"
-//#include "SDL/SDL_opengl.h"
#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
#endif
GLRenderer::GLRenderer() :
+ window(),
desktop_size(-1, -1),
screen_size(-1, -1),
fullscreen_active(false),
void
GLRenderer::resize(int w, int h)
{
-#ifdef OLD_SDL1
- SDL_CreateWindow(SDL_GL_CreateContext(w, h, 0, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE));
-#endif
-
g_config->window_size = Size(w, h);
+ PHYSICAL_SCREEN_WIDTH = w;
+ PHYSICAL_SCREEN_HEIGHT = h;
+
apply_config();
}
void
GLRenderer::apply_video_mode(const Size& size, bool fullscreen)
{
- // Only change video mode when its different from the current one
- if (screen_size != size || fullscreen_active != fullscreen)
+ if (window)
{
- int flags = SDL_WINDOW_OPENGL;
+ SDL_SetWindowSize(window, size.width, size.height);
if (fullscreen)
{
- flags |= SDL_WINDOW_FULLSCREEN;
+ int fullscreen_flags = SDL_WINDOW_FULLSCREEN; // SDL_WINDOW_FULLSCREEN_DESKTOP or 0
+ SDL_SetWindowDisplayMode(window, NULL);
+ SDL_SetWindowFullscreen(window, fullscreen_flags);
}
else
{
- flags |= SDL_WINDOW_RESIZABLE;
+ SDL_SetWindowFullscreen(window, 0);
}
-
- window = SDL_CreateWindow("SuperTux",
- SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
- size.width, size.height,
- flags);
- if (!window)
- {
- std::ostringstream msg;
- msg << "Couldn't set video mode " << size.width << "x" << size.height << ": " << SDL_GetError();
- throw std::runtime_error(msg.str());
- }
- else
+ }
+ else
+ {
+ // Only change video mode when its different from the current one
+ if (screen_size != size || fullscreen_active != fullscreen)
{
- glcontext = SDL_GL_CreateContext(window);
- screen_size = size;
- fullscreen_active = fullscreen;
+ int flags = SDL_WINDOW_OPENGL;
+
+ if (fullscreen)
+ {
+ flags |= SDL_WINDOW_FULLSCREEN;
+ }
+ else
+ {
+ flags |= SDL_WINDOW_RESIZABLE;
+ }
+
+ window = SDL_CreateWindow("SuperTux",
+ SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
+ size.width, size.height,
+ flags);
+ if (!window)
+ {
+ std::ostringstream msg;
+ msg << "Couldn't set video mode " << size.width << "x" << size.height << ": " << SDL_GetError();
+ throw std::runtime_error(msg.str());
+ }
+ else
+ {
+ glcontext = SDL_GL_CreateContext(window);
+ screen_size = size;
+
+ PHYSICAL_SCREEN_WIDTH = size.width;
+ PHYSICAL_SCREEN_HEIGHT = size.height;
+
+ SCREEN_WIDTH = size.width;
+ SCREEN_HEIGHT = size.height;
+
+ fullscreen_active = fullscreen;
+ }
}
}
}
int width = g_config->window_size.width;
int height = g_config->window_size.height;
- int flags = 0;
+ int flags = SDL_WINDOW_RESIZABLE;
if(g_config->use_fullscreen)
{
flags |= SDL_WINDOW_FULLSCREEN;
height = g_config->fullscreen_size.height;
}
+ SCREEN_WIDTH = width;
+ SCREEN_HEIGHT = height;
+
+ PHYSICAL_SCREEN_WIDTH = width;
+ PHYSICAL_SCREEN_HEIGHT = height;
+
int ret = SDL_CreateWindowAndRenderer(width, height, flags,
&window, &renderer);
}
void
-SDLRenderer::resize(int, int)
+SDLRenderer::resize(int w , int h)
{
-
+ SCREEN_WIDTH = w;
+ SCREEN_HEIGHT = h;
+
+ PHYSICAL_SCREEN_WIDTH = w;
+ PHYSICAL_SCREEN_HEIGHT = h;
}
void