我有以下来自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;
}
不时显示图片,但大多数时候它只是一个黑色的窗户(这张照片的细线)。我在同一目录中有名为"hello.bmp"的 BMP 文件。附言。我有ArchLinux。
在显示图像之前,应将其转换为与所选视频模式兼容的格式。因此,您应该实现如下内容:
SDL_Surface *imagef;
imagef = SDL_DisplayFormat(image);
在启动 BMP 之前,请将imagef
用于所有操作。