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

Author Topic: PostFX usage in SFML 1.6  (Read 2591 times)

0 Members and 1 Guest are viewing this topic.

Josh

  • Newbie
  • *
  • Posts: 19
    • View Profile
PostFX usage in SFML 1.6
« on: May 06, 2010, 10:35:30 am »
Hey,

I'm writing a game in SFML 1.6 that requires I colourise various images on the screen (i.e. platforms, enemies, etc). Each game object has a sprite which refers to common images in my resource manager.

What I originally tried to do was store the original, uncolourised image in the resource manager, then apply the PostFX to the sprite as I was drawing it (As I'd do when writing games with directx), however, I found out I couldn't do that. That is, according to the documentation I either have to apply the PostFX to the screen or to an image.

So I decided to just store a copy of each colourised image in the resource manager. I only need a handful of different copies anyway (As in, I'm only colourising to 5-6 discrete colours). So, I load the original image, create a new image which copies the original image, and then try to apply the PostFX to that.

However, I'm unsure how to actually tell the PostFX to apply the effect. For the frame buffer, you call a draw on the effect, and that applies it to everything drawn previously, but how do I do it for an image in memory?

Or do I have it wrong and applying the effect on the image does what I originally wanted (As in, applies it only to the drawn instance rather than the image in memory)?  If so, how do I do this properly, since calling sprite.GetImage() as the second parameter for the SetTexture call returns a const mismatch error.

The code that changes the images (in memory, I'm hoping) looks like:
Code: [Select]
tempEffect = ShaderManager::Get()->getEffectByIndex(tempIndex);
tempEffect->SetTexture("framebuffer", (&initial));
tempEffect->SetParameter("colour", (float)colours[red].r/255,(float)colours[red].g/255,
(float)colours[red].b/255);

App->Draw((*tempEffect));


Initial is the sf::Image& which contains the pixels I'd like to colourise. tempEffect is the sf::PostFX which does this. I'm just not sure how to actually "submit" it (i.e. I'm not sure what the last line should be)

Any suggestions would be much appreciated,
Josh

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
PostFX usage in SFML 1.6
« Reply #1 on: May 06, 2010, 11:13:17 am »
A PostFX can only modify what's drawn on a render target, it can't change an image in memory.

What you want to do is possible in SFML 2, where sf::PostFX has been replaced with a sf::Shader class that can be applied to individual drawables.

In SFML 1 there's no easy way to achieve that, but if all you want is to apply a global color (no fancy algorithm) then maybe you can simply use sprite.SetColor(...)? Otherwise, if the modifications are less trivial to perform, maybe you can do it manually using image.GetPixel / image.SetPixel.
Laurent Gomila - SFML developer

Josh

  • Newbie
  • *
  • Posts: 19
    • View Profile
PostFX usage in SFML 1.6
« Reply #2 on: May 06, 2010, 03:51:57 pm »
Quote from: "Laurent"
What you want to do is possible in SFML 2, where sf::PostFX has been replaced with a sf::Shader class that can be applied to individual drawables.


So, I just Bind and Unbind the shader around the object I want it applied to? Cool. And how performance heavy is that process? I.e, do I want to be optimising that so I call un/bind the least number of times, or it shouldn't impact that much?

Cheers for the help

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
PostFX usage in SFML 1.6
« Reply #3 on: May 06, 2010, 03:57:24 pm »
Look at the documentation carefully, bind/unbind are only for using directly with OpenGL (and for internal SFML stuff).
The proper way of using shaders with drawables is the following:
Code: [Select]
window.Draw(sprite, shader);

Quote
And how performance heavy is that process? I.e, do I want to be optimising that so I call un/bind the least number of times, or it shouldn't impact that much?

If you can draw together everything that uses the same shader it's better (less shader switches on the driver side), but you shouldn't care about this unil you really need to.
Laurent Gomila - SFML developer

Josh

  • Newbie
  • *
  • Posts: 19
    • View Profile
PostFX usage in SFML 1.6
« Reply #4 on: May 06, 2010, 04:06:08 pm »
Oh right, forgot about the local documentation.

Thanks