我目前正在使用 SDL 将图像绘制到屏幕上,它加载图像时没有错误。但是当我将图像绘制到屏幕上时,什么都没有显示。这是我的代码:
图片加载功能:
SDL_Surface *d2Sprite::Load(char *file)
{
SDL_Surface *temp = NULL;
SDL_Surface *opt = NULL;
if((temp = SDL_LoadBMP(file)) == NULL)
{
cout << "Unable to load image '" << file << "'. " << SDL_GetError() << endl;
return NULL;
}
opt = SDL_DisplayFormatAlpha(temp);
SDL_FreeSurface(temp);
return opt;
}
绘图功能:
bool d2Sprite::Draw(SDL_Surface *dest, SDL_Surface *src, int x, int y)
{
if(dest == NULL || src == NULL)
{
cout << "Unable draw sprite! " << SDL_GetError() << endl;
return false;
}
SDL_Rect destR;
destR.x = x;
destR.y = y;
SDL_BlitSurface(src, NULL, dest, &destR);
return true;
}