SDL displaying .bmp

This is a discussion on SDL displaying .bmp within the C++ Programming forums, part of the General Programming Boards category; I am learning SDL from a tutorial on youtube and one lesson is displaying bitmaps, I types in the code ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 11:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21