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

Author Topic: crossfading images  (Read 9866 times)

0 Members and 3 Guests are viewing this topic.

kfj

  • Newbie
  • *
  • Posts: 19
    • View Profile
crossfading images
« on: June 30, 2020, 10:16:38 am »
I'm using SFML to write an image viewer. I'd like a simple way to crossfade from the current image to the next one. I haven't found a way to do this with SFML yet - if there is one, please let me know! I have the images as textures on the GPU and I'd like to use the GPU to produce the effect.

I think the simplest way to do this is to draw the new texture on top of the old one several times, increasing the new frame's alpha values every time until it's fully opaque, but touching every single pixel with the CPU just for that is too expensive. What I'd like is a function to globally change the transparency of a complete texture, or a blending mode to the same effect. I suppose this would be easy to do with a fragment shader, but I haven't worked with shaders so far and I'd prefer a simple prefabricated solution.

Kay

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: crossfading images
« Reply #1 on: June 30, 2020, 11:08:44 am »
Set the color of the sprite you want to fade to a progressively more transparent white.
https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Sprite.php#a14def44da6437bfea20c4df5e71aba4c

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: crossfading images
« Reply #2 on: July 06, 2020, 11:16:44 pm »
For "effects" like this shader exist. ;)

SFML doesn't try to be an engine with lots of prefabricated stuff, we just provide a nicer and cross-platform API, so the users can implement their own things on top.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/