Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem with PostFx in 1.6  (Read 1435 times)

0 Members and 2 Guests are viewing this topic.

diegonolan

  • Newbie
  • *
  • Posts: 26
    • View Profile
Problem with PostFx in 1.6
« on: January 06, 2012, 03:21:51 am »
I'm having a problem getting a post effect to work in 1.6.  I got the tutorial working and then i tried applying the same effect to a project i am working on.  The only difference is that I have a class that deals with all the graphics.  So I added the sf::PostFx as a private member and then loaded it in the constructor of the class.  Then drew it using a pointer to the sf::RenderWindow i also stored in the class i guess minimum code is the following:

Code: [Select]


class Graphics
{
   public:
      Graphics();
      ~Graphics();
      void Draw();
      void Load(sf::RenderWindow * Window, Hud * MyHud, QuadTree * MyQuadTree, Objects * everything);
   private:
      sf::View View;
      sf::Vector2f Center;
      sf::Vector2f HalfSize;
      void ChangeView();
      QuadTree * QuadTreePtr;
      Hud * HudPtr;
      sf::RenderWindow * WindowPtr;
      Objects * Everything;
      Shadow Shadows;
      void DrawMenu();

      sf::PostFX Effect;
};


and then the draw function that draws all the objects on the screen for me

Code: [Select]


void Graphics::Draw()
{
   // Update view based on gambino's position
   ChangeView();

   // Get the mouse position in the range [0, 1]
   float X = WindowPtr->GetInput().GetMouseX()/
         static_cast<float>(WindowPtr->GetWidth());
   float Y = WindowPtr->GetInput().GetMouseY()/
         static_cast<float>(WindowPtr->GetHeight());

   // Update the effect parameters
   Effect.SetParameter("color", 0.5f, X, Y);

   // Clear screen of previous renderings
   WindowPtr->Clear();


   // Calculate New Position of background
   Everything->BkGrndImg.SetPosition(WindowPtr->GetView().GetCenter().x*
                                   (1-BGTRANSSCALE),
                                    WindowPtr->GetView().GetCenter().y*
                                   (1-BGTRANSSCALE));

   // Draw Background
   WindowPtr->Draw(Everything->BkGrndImg);
   WindowPtr->Draw(Effect);

   // Get Vector of objects to draw from quadtree
   sf::Rect<float> viewrect = View.GetRect();
   vector<BaseObject*> ToDraw = QuadTreePtr->Query(viewrect);
   for(unsigned int i=0;i<ToDraw.size();++i)
   {
      ToDraw[i]->Draw(*WindowPtr);
   }

   // Display Heads Up Display
   HudPtr->DrawStatusBars(*WindowPtr,Everything->Gambino);
   HudPtr->DisplayFrameRate(*WindowPtr);

   // Draw menu if open
   if(state.GetMenu())
   {
      DrawMenu();
   }

   // Draw QuadTree for debugging purposes if TAB is being held down
   if(state.DrawQuadTree)
   {
      QuadTreePtr->Draw();
   }


   WindowPtr->Display();
}


I'm just wondering what I could be doing wrong or if there is something about post effects that doesn't allow me to do it this way.  Again, the tutorial does work and i am able to load the effect with this project it just doesn't seem to do anything.

diegonolan

  • Newbie
  • *
  • Posts: 26
    • View Profile
Problem with PostFx in 1.6
« Reply #1 on: January 06, 2012, 03:37:14 am »
Oh, I figured it out looks like.  For some reason the effect seems to be cleared when i load it in the constructor.  If i put it the draw function it works.  Don't know if its supposed to work like that but I got it working at least.

diegonolan

  • Newbie
  • *
  • Posts: 26
    • View Profile
Problem with PostFx in 1.6
« Reply #2 on: January 06, 2012, 03:39:51 am »
nevermind, looks like i am an even bigger idiot that i thought!  I re-declared Effect in the constructor so I had declared it twice.  So the effect that i loaded the sfx scope was only in the constructor thus the draw function had no idea about the private member.