简体   繁体   English

未知像素格式错误SDL2

[英]Unknown pixel format error SDL2

I've been working on a project in SDL, and I've narrowed a problem to a surface being NULL. 我一直在使用SDL开发一个项目,并且将问题缩小为表面为NULL。 The surface is initialized like so: 表面初始化如下:

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

It prints "SURFACE ERROR Unknown pixel format". 打印“ SURFACE ERROR Unknown pixel format”。 I assume its referring to the last four arguments in the SDL_CreateRGBSurface function, but I don't know what could be causing. 我假设它指的是SDL_CreateRGBSurface函数中的最后四个参数,但我不知道可能是什么原因。 Google has been.. unhelpful. Google一直无济于事。 And so I turn to you. 所以我转向你。

The fourth parameter depth can't be NULL. 第四个参数depth不能为NULL。 Try changing it to 32. 尝试将其更改为32。

The function is declared as: 该函数声明为:

SDL_Surface* SDL_CreateRGBSurface(Uint32 flags,
                                  int    width,
                                  int    height,
                                  int    depth,
                                  Uint32 Rmask,
                                  Uint32 Gmask,
                                  Uint32 Bmask,
                                  Uint32 Amask)

See the SDL 2.0 documentation: https://wiki.libsdl.org/SDL_CreateRGBSurface 请参阅SDL 2.0文档: https : //wiki.libsdl.org/SDL_CreateRGBSurface

From http://sdl.beuc.net/sdl.wiki/SDL_CreateRGBSurface 来自http://sdl.beuc.net/sdl.wiki/SDL_CreateRGBSurface

The prototype of SDL_CreateRGBSurface is: SDL_CreateRGBSurface的原型是:

SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int bitsPerPixel, 
                                  Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);

You are passing NULL for the bitsPerPixel argument. 您要为bitsPerPixel参数传递NULL That should be a number like 8, 24 or 32 instead, depending on what you are after. 该数字应改为8、24或32,具体取决于您要处理的内容。

In any case, you can use SDL_GetError() to get the exact error message which will be more helpful: 无论如何,您都可以使用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