From 26b5a524e4ffe4e8937cbe6d36cd43c2c74fb51e Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Wed, 30 Jul 2014 20:20:51 +0200 Subject: [PATCH] Implemented set_gamma() --- src/scripting/functions.cpp | 8 ++++---- src/video/gl/gl_renderer.cpp | 8 ++++++++ src/video/gl/gl_renderer.hpp | 1 + src/video/renderer.hpp | 1 + src/video/sdl/sdl_renderer.cpp | 8 ++++++++ src/video/sdl/sdl_renderer.hpp | 1 + 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index e82191b7a..ba0fc3fb5 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -32,6 +32,7 @@ #include "supertux/tile.hpp" #include "supertux/world.hpp" #include "util/gettext.hpp" +#include "video/renderer.hpp" #include "worldmap/tux.hpp" #include "scripting/squirrel_util.hpp" @@ -271,10 +272,9 @@ void camera() log_info << "Camera is at " << Sector::current()->camera->get_translation().x << "," << Sector::current()->camera->get_translation().y << std::endl; } -void set_gamma(float /*gamma*/) { -#ifdef OLD_SDL1 - SDL_SetWindowGammaRamp(screen,gamma, gamma, gamma); -#endif +void set_gamma(float gamma) +{ + Renderer::instance()->set_gamma(gamma); } void quit() diff --git a/src/video/gl/gl_renderer.cpp b/src/video/gl/gl_renderer.cpp index 991e3aa21..ba3a60165 100644 --- a/src/video/gl/gl_renderer.cpp +++ b/src/video/gl/gl_renderer.cpp @@ -640,4 +640,12 @@ GLRenderer::apply_video_mode(const Size& size, bool fullscreen) } } +void +GLRenderer::set_gamma(float gamma) +{ + Uint16 ramp[256]; + SDL_CalculateGammaRamp(gamma, ramp); + SDL_SetWindowGammaRamp(window, ramp, ramp, ramp); +} + /* EOF */ diff --git a/src/video/gl/gl_renderer.hpp b/src/video/gl/gl_renderer.hpp index 028222504..359103a0a 100644 --- a/src/video/gl/gl_renderer.hpp +++ b/src/video/gl/gl_renderer.hpp @@ -129,6 +129,7 @@ public: void resize(int w, int h); void apply_config(); void apply_video_mode(const Size& size, bool fullscreen); + void set_gamma(float gamma); }; #endif diff --git a/src/video/renderer.hpp b/src/video/renderer.hpp index 8bb39c7ac..e4430ad80 100644 --- a/src/video/renderer.hpp +++ b/src/video/renderer.hpp @@ -52,6 +52,7 @@ public: virtual void flip() = 0; virtual void resize(int w, int h) = 0; virtual void apply_config() = 0; + virtual void set_gamma(float gamma) = 0; static Renderer* instance() { assert(instance_); return instance_; } diff --git a/src/video/sdl/sdl_renderer.cpp b/src/video/sdl/sdl_renderer.cpp index 591a9e5ec..26da4d31e 100644 --- a/src/video/sdl/sdl_renderer.cpp +++ b/src/video/sdl/sdl_renderer.cpp @@ -414,4 +414,12 @@ SDLRenderer::resize(int, int) } +void +SDLRenderer::set_gamma(float gamma) +{ + Uint16 ramp[256]; + SDL_CalculateGammaRamp(gamma, ramp); + SDL_SetWindowGammaRamp(window, ramp, ramp, ramp); +} + /* EOF */ diff --git a/src/video/sdl/sdl_renderer.hpp b/src/video/sdl/sdl_renderer.hpp index b03cf4137..042a2855d 100644 --- a/src/video/sdl/sdl_renderer.hpp +++ b/src/video/sdl/sdl_renderer.hpp @@ -35,6 +35,7 @@ public: void flip(); void resize(int w, int h); void apply_config() {} + void set_gamma(float gamma); SDL_Renderer* get_sdl_renderer() const { return renderer; }; -- 2.11.0