Fade In/out Screen In Sdl 2.0

Started by
3 comments, last by Khatharr 7 years, 8 months ago

hi all,

we are trying to shift our old SDL 2D framework to SDL 2.0, now we will use SDL_renderer and SDL Texture instead of the old SDL_Surface, but

our screen transition is done thru fade-in/out of the main SDL_Surface.

Now since the main render surface is represented by the SDL_Renderer taken from the Window, how can we do our fade in/out transition where it seem that the SDL_Renderer structure does not have a mechanism to manipulate the alpha of that surface.

my options are,

1. rendered the scene to a texture and manipulate the alpha of that texture BEFORE rendering the texture to the SDL_Renderer, which is an extra overhead process.

2. render a black rect on top of the scene that draws from alpha 0 to 255 (full) opacity to simulate fade.

what is the best option you guys can suggest?

Advertisement

Not an expert in this, but it seems to me you already solved the problem, in two different ways already.

What exactly are you asking us? Do you expect us to say "1" or "2" ?

The answer lies in what you want to achieve (against how much work) in your shifted "our old SDL 2D framework to SDL 2.0" framework, and in my opinion, you're the best qualified person to answer that. None of us knows what "our old SDL 2D framework" does, or aims to do, except you.

Personally, I would just pick one, implement it, and see if it does what you want it to do.

I generally take this approach:


class Scene {
public:
  //return 'this' to continue, return a new scene to switch, return nullptr to quit
  virtual Scene* update(float dt) = 0;
  virtual void draw(whatever args are needed to render crap in the scene) = 0;
};

In the main loop there's a stanza that checks whether the returned Scene* is equal to the existing one. If it's not then I enter the replacement section, which loops drawing the scene with a black rect on top of it, but not calling the update() function of the scene. When the rect is fully opaque the scene object is destroyed and replaced with the new one. If it's nullptr then quit, otherwise call scene.update(0) and then reverse the fading process until the rect is fully transparent, then go back to the main loop, which updates and draws every frame.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.
What Khatharr wanted to say is "2" :)


"1" sounds overly complicated, and will incur a heavy speed penalty if you actually read the texture data from the graphics card.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Well, putting the fader stuff outside the scene is also worth mentioning, since it means you don't have to bother with it and/or replicate the code in each scene. I usually have my main loop inside of a "Game" object, which also stores state that persists between scenes. If you wanted to get fancy and do custom transitions then it would be easy to signal what kind of transition you wanted to the Game object and then just quit the scene normally.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

This topic is closed to new replies.

Advertisement