2

I've got following code from Lazy:

#include <iostream>
#include "SDL/SDL.h"

using namespace std;

int main()
{
    //Start SDL
    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_Surface *hello = NULL;
    SDL_Surface *screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

    hello = SDL_LoadBMP("hello.bmp");
    SDL_BlitSurface(hello, NULL, screen, NULL);
    SDL_Flip(screen);
    SDL_Delay(3000);
    SDL_FreeSurface(hello);

    //Quit SDL
    SDL_Quit();
    return 0;
}

From time to time the picture is shown, but most of time it's just a black window (with slim string of this picture). And I've got the BMP file with name "hello.bmp" in the same directory. PS.I've got ArchLinux.

4

1 回答 1

2

Before displaying your image you should convert it to a format compatible to the video mode you selected. Therefore you should implement something like this:

SDL_Surface *imagef;
imagef = SDL_DisplayFormat(image);

Before bliting your BMP and use imagef for all of your operations.

于 2012-05-24T15:42:25.943 回答