【问题标题】:Match SDL 1.2's default palette with SDL_CreateRGBSurface()?将 SDL 1.2 的默认调色板与 SDL_CreateRGBSurface() 匹配?
【发布时间】:2017-05-03 23:00:37
【问题描述】:

我正在将使用 8 位索引颜色表面的 a SDL 1.2 program (repository) 移植到 SDL2。

不幸的是,SDL_CreateRGBSurface() 默认为 8 bpp 表面设置了一个全白、256 项的调色板,而不是 SDL_SetVideoMode() 在 SDL 1.2 中设置的 RGB884 调色板。

如何设置与来自 SDL 1.2 SDL_SetVideoMode(..., ..., 8, SDL_SWSURFACE) 调用的默认调色板相匹配的调色板?

【问题讨论】:

    标签: c sdl sdl-2


    【解决方案1】:

    SDL_SetPaletteColors() 和源自 SDL 1.2 的 SDL_SetVideoMode() 输出的表给了我这个 sn-p:

    surface = SDL_CreateRGBSurface(0, 100, 100, 8, 0, 0, 0, 0);
    Uint8 r[8] = { 0, 36, 73, 109, 146, 182, 219, 255 };
    Uint8 g[8] = { 0, 36, 73, 109, 146, 182, 219, 255 };
    Uint8 b[4] = { 0, 85, 170, 255 };
    int curColor = 0;
    for( unsigned int i = 0; i < 8; ++i )
    for( unsigned int j = 0; j < 8; ++j )
    for( unsigned int k = 0; k < 4; ++k )
    {
        SDL_Color color = { r[i], g[j], b[k], 255 };
        SDL_SetPaletteColors( surface->format->palette, &color, curColor, 1 );
        curColor++;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-06-09
      • 1970-01-01
      • 2015-05-26
      • 2012-01-02
      • 1970-01-01
      • 2018-10-15
      • 1970-01-01
      • 2013-10-20
      相关资源
      最近更新 更多