【问题标题】:Unknown pixel format error SDL2未知像素格式错误 SDL2
【发布时间】:2014-02-10 10:36:29
【问题描述】:

我一直在从事 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 函数中的最后四个参数,但我不知道可能是什么原因。谷歌一直……没有帮助。所以我转向你。

【问题讨论】:

    标签: c++ sdl-2 pixelformat


    【解决方案1】:

    第四个参数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

    【讨论】:

      【解决方案2】:

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

      您将 NULL 传递给 bitsPerPixel 参数。那应该是 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);
      }
      

      【讨论】:

        猜你喜欢
        • 2015-04-11
        • 1970-01-01
        • 2017-04-03
        • 1970-01-01
        • 2020-07-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-16
        相关资源
        最近更新 更多