Thread: SDL displaying .bmp

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    151

    SDL displaying .bmp

    I am learning SDL from a tutorial on youtube and one lesson is displaying bitmaps, I types in the code in code::blocks but it only displays the image when I am about to close it.

    Here is my code.
    Code:
    #include <SDL/SDL.h>
    
    SDL_Surface *buffer = 0;
    SDL_Surface *bitmap = 0;
    
    int main(int argc, char *argv[]){
        SDL_Init(SDL_INIT_VIDEO);
        buffer = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
    
        bool run = true;
        SDL_Event event;
    
        bitmap = SDL_LoadBMP("smile.bmp");
    
        if(bitmap == 0){
            return -1;
        }
    
        SDL_Rect pos;
        pos.x = 0;
        pos.y = 0;
    
        while(run){
            while(SDL_PollEvent(&event)){
                if(event.type == SDL_QUIT)
                {
                    run = false;
                }
            }
        }
    
        SDL_BlitSurface(bitmap, 0, buffer, &pos);
        SDL_Flip(buffer);
    
        SDL_Quit();
        return(0);
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    SDL_BlitSurface(bitmap, 0, buffer, &pos);
    SDL_Flip(buffer);

    Move these before your loop?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL project setup
    By rogster001 in forum C Programming
    Replies: 22
    Last Post: 08-28-2009, 08:05 AM
  2. Problems compiling this SDL app
    By Rider in forum C++ Programming
    Replies: 3
    Last Post: 03-27-2007, 12:22 PM
  3. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  4. sdl in c++
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-07-2002, 07:46 AM
  5. Loading a .bmp and displaying into a dialog?
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 01-30-2002, 12:49 PM