From: Peter Schaefer Date: Sun, 14 Jun 2015 11:10:02 +0000 (+0200) Subject: added Graphix EFFECTS (enable/disable) X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=bb4989f460d3785054e74a76f56ab2d2c8d3c131;p=cgue_weave.git added Graphix EFFECTS (enable/disable) added MotionBlur --- diff --git a/Weave/Events.cpp b/Weave/Events.cpp index 467b48f..5d1b1cb 100644 --- a/Weave/Events.cpp +++ b/Weave/Events.cpp @@ -131,6 +131,7 @@ void Events::KeyDown(int _key) break; case SDLK_LSHIFT: timeshift = true; + Graphix::enableEffects(EF_MOTION_BLUR); break; default: break; @@ -143,6 +144,7 @@ void Events::KeyUp(int _key) { case SDLK_LSHIFT: timeshift = false; + Graphix::disableEffects(EF_MOTION_BLUR); break; default: break; diff --git a/Weave/Game.cpp b/Weave/Game.cpp index 551c37a..1b0d7fd 100644 --- a/Weave/Game.cpp +++ b/Weave/Game.cpp @@ -91,6 +91,7 @@ void Game::play() { Fps fps(0.3f); int sleep_time=0; + while (!Events::halt){ fps.step(); diff --git a/Weave/Graphix/Graphix.cpp b/Weave/Graphix/Graphix.cpp index 7451986..4158838 100644 --- a/Weave/Graphix/Graphix.cpp +++ b/Weave/Graphix/Graphix.cpp @@ -6,6 +6,9 @@ using std::string; +#define MOTION_BLUR_COEFF 0.99f +#define MOTION_BLUR_INTENS 0.99f + void Graphix::setWindowSize(unsigned int _width, unsigned int _height) { width = _width; @@ -27,12 +30,23 @@ unsigned int Graphix::getWindowWidth() return width; } -void Graphix::swap() + +void Graphix::enableEffects(Effects _eff) { - SDL_GL_SwapWindow(sdl_window); + effects |= _eff; } +void Graphix::disableEffects(Effects _eff) +{ + effects &= ~_eff; +} + +bool Graphix::testEffect(Effects _eff) +{ + return effects & _eff; +} + void Graphix::init() { @@ -43,6 +57,11 @@ void Graphix::init() SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + //SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 16); + //SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 16); + //SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 16); + //SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 16); + sdl_window = SDL_CreateWindow(windowTitle.c_str(), xpos, ypos, width, height, windowFlags); if (sdl_window == nullptr) @@ -72,6 +91,11 @@ void Graphix::init() glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glClearColor(0.9f, 0.9f, 1.0f, 1.f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClearAccum(0.f, 0.f, 0.f, 0.f); + glClear(GL_ACCUM_BUFFER_BIT); + shader_BBox = new Shader("basic_VS.hlsl", "basic_FS.hlsl"); } @@ -89,10 +113,26 @@ void Graphix::freeMouse() void Graphix::clear() { - glClearColor(0.9f, 0.9f, 1.0f, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + if (testEffect(EF_MOTION_BLUR)) + { + glAccum(GL_RETURN, MOTION_BLUR_INTENS); + glClear(GL_ACCUM_BUFFER_BIT); + } + + +} + + +void Graphix::swap() +{ + if (testEffect(EF_MOTION_BLUR)) + glAccum(GL_ACCUM, MOTION_BLUR_COEFF); + SDL_GL_SwapWindow(sdl_window); } + + void Graphix::cleanup() { delete shader_BBox; @@ -148,5 +188,6 @@ SDL_Window* Graphix::sdl_window; SDL_GLContext Graphix::sdl_glcontext; +short Graphix::effects = EF_NOTHING; Shader* Graphix::shader_BBox; diff --git a/Weave/Graphix/Graphix.h b/Weave/Graphix/Graphix.h index d45b642..ea8285c 100644 --- a/Weave/Graphix/Graphix.h +++ b/Weave/Graphix/Graphix.h @@ -5,6 +5,14 @@ #include +#define BIT(x) (1<<(x)) + +enum Effects { + EF_NOTHING = 0, + EF_MOTION_BLUR = BIT(1), + EF_TRANSPARENCY = BIT(2), + EF_BLOOM = BIT(3) +}; class Shader; @@ -19,6 +27,10 @@ public: static void catchMouse(); static void freeMouse(); + static void enableEffects(Effects eff); + static void disableEffects(Effects eff); + static bool testEffect(Effects eff); + static void swap(); static void init(); @@ -45,5 +57,7 @@ private: static SDL_GLContext sdl_glcontext; + static short effects; + };