BGE Bug Fix:#17349, fixes some problems about 2d-filters
authorHamed Zaghaghi <hamed.zaghaghi@gmail.com>
Sun, 20 Jul 2008 23:03:01 +0000 (23:03 +0000)
committerHamed Zaghaghi <hamed.zaghaghi@gmail.com>
Sun, 20 Jul 2008 23:03:01 +0000 (23:03 +0000)
source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
source/gameengine/BlenderRoutines/KX_BlenderCanvas.h
source/gameengine/GamePlayer/common/GPC_Canvas.h
source/gameengine/Rasterizer/RAS_2DFilterManager.cpp
source/gameengine/Rasterizer/RAS_2DFilterManager.h
source/gameengine/Rasterizer/RAS_ICanvas.h

index 5f37de24ed68d89ce1d499abb92e17bdfa9af4c8..1604dfe5ccecd3fdd258b1b7d959d5325c9dfd3a 100644 (file)
@@ -101,6 +101,13 @@ int KX_BlenderCanvas::GetHeight(
        return scrarea_get_win_height(m_area);
 }
 
+RAS_Rect &
+KX_BlenderCanvas::
+GetWindowArea(
+){
+       return m_area_rect;
+}      
+
        void
 KX_BlenderCanvas::
 SetViewPort(
@@ -112,6 +119,11 @@ SetViewPort(
        int minx = scrarea_get_win_x(m_area);
        int miny = scrarea_get_win_y(m_area);
 
+       m_area_rect.SetLeft(minx + x1);
+       m_area_rect.SetBottom(miny + y1);
+       m_area_rect.SetRight(minx + x2);
+       m_area_rect.SetTop(miny + y2);
+
        glViewport(minx + x1, miny + y1, vp_width, vp_height);
        glScissor(minx + x1, miny + y1, vp_width, vp_height);
 }
index b155d39e149d04bfe7c5e40cbb1228a77efd82ee..bc202a8558c57bd0549ea5cee249c70d334d6ea7 100644 (file)
@@ -117,6 +117,10 @@ public:
                return m_displayarea;
        };
 
+               RAS_Rect &
+       GetWindowArea(
+       );
+
                void
        SetViewPort(
                int x1, int y1,
@@ -159,6 +163,7 @@ public:
 private:
        /** Blender area the game engine is running within */
        struct ScrArea* m_area;
+       RAS_Rect        m_area_rect;
 };
 
 #endif // __KX_BLENDERCANVAS
index f82166dfa8894357bcd81c4db33c95b58686523b..87719041f65624161018c2d0d2fb480a8261b055 100644 (file)
@@ -130,6 +130,12 @@ public:
        ) {
                return m_displayarea;
        };
+       
+               RAS_Rect &
+       GetWindowArea(
+       ) {
+               return m_displayarea;
+       }
 
                void 
        BeginFrame(
index 958fead33ce8b6ba117629b87d7d9f6efe2d3363..ebaeaa9e3d391fdac4d445f7b42eedd313dff33b 100644 (file)
@@ -43,6 +43,7 @@
 
 #include "STR_String.h"
 #include "RAS_ICanvas.h"
+#include "RAS_Rect.h"
 #include "RAS_2DFilterManager.h"
 #include <iostream>
 
@@ -293,10 +294,13 @@ void RAS_2DFilterManager::SetupTextures(bool depth, bool luminance)
        }
 }
 
-void RAS_2DFilterManager::UpdateOffsetMatrix(int width, int height)
+void RAS_2DFilterManager::UpdateOffsetMatrix(RAS_ICanvas* canvas)
 {
-       canvaswidth = texturewidth = width;
-       canvasheight = textureheight = height;
+       RAS_Rect canvas_rect = canvas->GetWindowArea();
+       canvaswidth = canvas->GetWidth();
+       canvasheight = canvas->GetHeight();
+       texturewidth = canvaswidth + canvas_rect.GetLeft();
+       textureheight = canvasheight + canvas_rect.GetBottom();
 
        GLint i,j;
        i = 0;
@@ -352,7 +356,7 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas)
 
        if(canvaswidth != canvas->GetWidth() || canvasheight != canvas->GetHeight())
        {
-               UpdateOffsetMatrix(canvas->GetWidth(), canvas->GetHeight());
+               UpdateOffsetMatrix(canvas);
                SetupTextures(need_depth, need_luminance);
        }
        GLuint  viewport[4]={0};
@@ -360,19 +364,21 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas)
        if(need_depth){
                glActiveTextureARB(GL_TEXTURE1);
                glBindTexture(GL_TEXTURE_2D, texname[1]);
-               glCopyTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT, 0,0, texturewidth,textureheight, 0);
+               glCopyTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT, 0, 0, texturewidth,textureheight, 0);
        }
        
        if(need_luminance){
                glActiveTextureARB(GL_TEXTURE2);
                glBindTexture(GL_TEXTURE_2D, texname[2]);
-               glCopyTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE16, 0,0, texturewidth,textureheight, 0);
+               glCopyTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE16, 0, 0 , texturewidth,textureheight, 0);
        }
 
        glGetIntegerv(GL_VIEWPORT,(GLint *)viewport);
-       glViewport(0, 0, texturewidth, textureheight);
+       glViewport(0,0, texturewidth, textureheight);
 
        glDisable(GL_DEPTH_TEST);
+       glMatrixMode(GL_TEXTURE);
+       glLoadIdentity();
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glMatrixMode(GL_MODELVIEW);
index 9d8326b96de525ba8333ee0ae35df09ffa7a8698..f5998e1f09375a3a3f0f023305cdcbc719fc8233 100644 (file)
@@ -42,7 +42,7 @@ private:
        void SetupTextures(bool depth, bool luminance);
        void FreeTextures();
 
-       void UpdateOffsetMatrix(int width, int height);
+       void UpdateOffsetMatrix(RAS_ICanvas* canvas);
 
        float                   textureoffsets[18];
        float                   view[4];
index d799dc9c9bb8ec36e6b664f03b8b3a08b96610d1..f3f817a943dbddda23ea18899547638674503f47 100644 (file)
@@ -136,6 +136,14 @@ public:
        GetDisplayArea(
        ) = 0;
 
+       /**
+        * Used to get canvas area within blender.
+        */
+       virtual
+               RAS_Rect &
+       GetWindowArea(
+       ) = 0;
+
        /**
         * Set the visible vieport 
         */