Jump to content
  • Advertisement
Sign in to follow this  
cebugdev

Fade In/out Screen In Sdl 2.0

This topic is 713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

 

 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!