Jump to content
  • Advertisement
Sign in to follow this  

SDL: Logo fade in out?

This topic is 3976 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

you know that fade in - fade out in games where logos of the developers are shown at the beginning. however i tried to create this in SDL. my idea was a black background and the fade in fade out with alpha but it fades in but it doesn't fade out and it fades in a little to fast. normally a picture is fully opaque with alpha 255 but somehow the logo is opaque with alpha at 10. Here's my code
#include "SDL/SDL.h"
#include <string>
#include "sdltimer.h"

#ifdef main
#undef main

#include <windows.h>

using namespace std;

SDL_Surface *screen;
SDL_Surface *logo;
Uint8 *keys;

#include "useful_sdl_functions.cpp"

void Msg(string text) {

void CleanUp() {
     if(logo == NULL) { SDL_FreeSurface(logo); }

int loadfiles() {
    //SDL Logo
    logo = loadbmp("logo.bmp");
    if(logo == NULL) {
         return 1;
    return 0;

int main(int argc, char* argv[]) {
    bool game_running = true;
    bool showlogo = true;
    int alpha = 0;
    int dir = 1;
    SDL_Rect offset;
    SDL_Rect screenrect;
    SDLTimer alphaswitch;
    SDL_Event event;
    logo = NULL;
    screen = NULL;
    if(SDL_Init(SDL_INIT_VIDEO) == -1) {
         Msg("Could not initialize SDL!");

    screen = SDL_SetVideoMode(800,600,32,SDL_HWSURFACE | SDL_DOUBLEBUF);
    if(screen == NULL) {
         Msg("Error while setting sdl video mode!");
    if(loadfiles() != 0) {
         Msg("Error loading required files!");
    offset = CenterInScreen(screen,logo);
    screenrect = screen->clip_rect;
    while(game_running) {
         while(SDL_PollEvent(&event)) {
              if(event.type == SDL_QUIT) {
                   game_running = false;
         keys = SDL_GetKeyState(NULL);
         if(keys[SDLK_ESCAPE]) {
              game_running = false;
         if(alpha == SDL_ALPHA_OPAQUE && dir > 0) {
              dir = -1;
         if(alpha == SDL_ALPHA_TRANSPARENT && dir < 0) {
              game_running = false;
         if(alphaswitch.time() > 20) {
              alpha += dir;
              printf("alpha: %d",alpha);
    return 0;          

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!