2014-02-10 54 views
1

我一直在SDL項目中工作,並且我已經將問題範圍縮小到表面爲NULL。 表面被初始化,像這樣:未知的像素格式錯誤SDL2

boardSurface = SDL_CreateRGBSurface(0, 780, 480, NULL, 0, 0, 0, 0); 
    if (boardSurface == NULL) 
    { 
     std::cout << "SURFACE ERROR " << SDL_GetError() << std::endl; 
    } 

它打印「表面誤差未知像素格式」。 我假定它引用了SDL_CreateRGBSurface函數中的最後四個參數,但我不知道可能會導致什麼。谷歌一直......沒有幫助。所以我轉向你。

回答

1

第四個參數depth不能爲空。嘗試將其更改爲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

0

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); 

你傳入NULLbitsPerPixel說法。這應該是一個像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); 
}