【发布时间】:2014-04-03 12:36:05
【问题描述】:
我想我可能遇到了与 SDL 版本 1.2 和 2.0 的兼容性问题:当使用 SDL_MapRGB 和 SDL_FillRect 绘制到 Surface 时,SDL 2.0 显然交换了 RGB 红色和蓝色通道,而 SDL 1.2 没有。以下 C 代码是演示该问题的最小工作示例:
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
int main(void)
{
const unsigned height = 16;
const unsigned widthpercolour = 16;
SDL_Surface *surface;
SDL_Rect rect;
rect.x = 0;
rect.y = 0;
rect.w = widthpercolour;
rect.h = height;
if (SDL_Init(0) != 0) {
fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError());
return EXIT_FAILURE;
}
surface = SDL_CreateRGBSurface(0, 3 * widthpercolour, height, 24, 0x0000ff, 0x00ff00, 0xff0000, 0);
if (surface == NULL) {
fprintf(stderr, "Could not create SDL Surface: %s\n", SDL_GetError());
return EXIT_FAILURE;
}
SDL_FillRect(surface, NULL, 0);
SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format, 255, 0, 0));
rect.x += widthpercolour;
SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format, 0, 255, 0));
rect.x += widthpercolour;
SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format, 0, 0, 255));
if (SDL_SaveBMP(surface, "colourtest.bmp") != 0) {
SDL_FreeSurface(surface);
SDL_Quit();
fprintf(stderr, "Could not save SDL Surface: %s\n", SDL_GetError());
return EXIT_FAILURE;
}
SDL_FreeSurface(surface);
SDL_Quit();
return EXIT_SUCCESS;
}
编译时使用
gcc $(sdl-config --cflags --libs) colourtest.c -o colourtest
(使用 SDL 1.2 头文件和库),代码生成(如我所料)以下位图文件:
但是,当用
编译时gcc $(sdl2-config --cflags --libs) colourtest.c -o colourtest
(使用 SDL 2.0),代码生成(意外)以下位图文件:
我尝试更改 (r,g,b) 掩码,但没有任何改变。
据我所知,包括迁移指南在内的文档都没有提到这一点,我无法找到关于此事的任何其他内容。这导致我假设这是一个错误,或者我没有正确使用这些功能。
【问题讨论】:
-
这里有问题吗?如果是“我该怎么办?”我建议一个错误报告。
标签: sdl