以下是一个示例代码:
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <stdio.h>
int main()
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
printf("SDL ERROR: %s", SDL_GetError());
return 1;
}
SDL_Surface *screen;
screen = SDL_SetVideoMode(128, 128, 32, SDL_SWSURFACE);
SDL_Surface *img;
img = IMG_Load("./debug.png");
SDL_BlitSurface(img, NULL, screen, NULL);
SDL_Flip(screen);
SDL_Delay(1000);
SDL_FreeSurface(img);
SDL_Quit();
return 0;
}
编译很好,但是当我运行它时,它有时会起作用,大多数时候只显示部分图像。我真的无法想象是什么导致了......
编辑: 这是我用来测试程序的图像:
答案 0 :(得分:0)
如果debug.png与main.cpp位于同一个文件夹中,只需调用IMG_Load(“debug.png”),就不需要前面的./。
就像旁边一样,在一条线上初始化表面并没有错:
SDL_Surface* screen = SDL_SetVideoMode(128, 128, 32, SDL_SWSURFACE);
//and
SDL_Surface* img = IMG_Load("debug.png");