繁体   English   中英

未知像素格式错误SDL2

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM