[英]Unknown pixel format error SDL2
我一直在使用SDL開發一個項目,並且將問題縮小為表面為NULL。 表面初始化如下:
boardSurface = SDL_CreateRGBSurface(0, 780, 480, NULL, 0, 0, 0, 0);
if (boardSurface == NULL)
{
std::cout << "SURFACE ERROR " << SDL_GetError() << std::endl;
}
打印“ SURFACE ERROR Unknown pixel format”。 我假設它指的是SDL_CreateRGBSurface函數中的最后四個參數,但我不知道可能是什么原因。 Google一直無濟於事。 所以我轉向你。
第四個參數depth
不能為NULL。 嘗試將其更改為32。
該函數聲明為:
SDL_Surface* SDL_CreateRGBSurface(Uint32 flags,
int width,
int height,
int depth,
Uint32 Rmask,
Uint32 Gmask,
Uint32 Bmask,
Uint32 Amask)
請參閱SDL 2.0文檔: https : //wiki.libsdl.org/SDL_CreateRGBSurface
來自http://sdl.beuc.net/sdl.wiki/SDL_CreateRGBSurface
SDL_CreateRGBSurface
的原型是:
SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int bitsPerPixel,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
您要為bitsPerPixel
參數傳遞NULL
。 該數字應改為8、24或32,具體取決於您要處理的內容。
無論如何,您都可以使用SDL_GetError()
來獲取確切的錯誤消息,這將更加有用:
surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
rmask, gmask, bmask, amask);
if(surface == NULL) {
fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError());
exit(1);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.