The*_*n54 4 c palette color-palette sdl-2
我正在将程序从SDL 1更新为SDL 2并需要使用调色板.最初,我使用SDL_SetColors(screen, color, 0, intColors);但在SDL 2中不起作用.我正在尝试使用:
SDL_Palette *palette = (SDL_Palette *)malloc(sizeof(color)*intColors);
SDL_SetPaletteColors(palette, color, 0, intColors);
SDL_SetSurfacePalette(surface, palette);
Run Code Online (Sandbox Code Playgroud)
但SDL_SetPaletteColors()返回-1并失败.SDL_GetError没有给我任何信息.
如何从a制作调色板SDL_Color然后将其设置为我的表面调色板?
很难说出你的变量是什么以及你打算如何使用它们而不看你的声明.
以下是我在SDL_gpu中设置灰度调色板的方法:
SDL_Color colors[256];
int i;
for(i = 0; i < 256; i++)
{
colors[i].r = colors[i].g = colors[i].b = (Uint8)i;
}
#ifdef SDL_GPU_USE_SDL2
SDL_SetPaletteColors(result->format->palette, colors, 0, 256);
#else
SDL_SetPalette(result, SDL_LOGPAL, colors, 0, 256);
#endif
Run Code Online (Sandbox Code Playgroud)
该resultSDL_Surface已经有一个调色板,因为它是有一个8位像素深度(见注在https://wiki.libsdl.org/SDL_Palette).
| 归档时间: |
|
| 查看次数: |
3156 次 |
| 最近记录: |