]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
added Graphix EFFECTS (enable/disable)
authorPeter Schaefer <schaeferpm@gmail.com>
Sun, 14 Jun 2015 11:10:02 +0000 (13:10 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Sun, 14 Jun 2015 11:10:02 +0000 (13:10 +0200)
added MotionBlur

Weave/Events.cpp
Weave/Game.cpp
Weave/Graphix/Graphix.cpp
Weave/Graphix/Graphix.h

index 467b48f32160ef3ee996d8d2224ec167d4e1447a..5d1b1cbe6f87fbd911f62fff375fff93259e447d 100644 (file)
@@ -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;
index 551c37a61a4e1246e318cde2af4964025b4e0845..1b0d7fdc91b4cc731fa9c9a13893b756c6266a1d 100644 (file)
@@ -91,6 +91,7 @@ void Game::play()
 {
        Fps fps(0.3f);
        int sleep_time=0;
+
        while (!Events::halt){
                fps.step();
 
index 74519861ba07ce8f30e94313e51a438f3aa58db9..415883817a424a7b288f53b21a30573602ae4295 100644 (file)
@@ -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;
index d45b642bb33f9a10ad7b013d5d155355bcf3a343..ea8285c7cae22d8abe12ea507b7bc227c67a123b 100644 (file)
@@ -5,6 +5,14 @@
 
 #include <string>
 
+#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;
+
 };