SDL2 纹理的像素格式和表面颜色遮罩
SDL2 texture's pixel format and surface color mask
我试图创建一个用于像素操作的SDL_Surface,但是当设置表面的颜色蒙版时,因为填充颜色缓冲区时颜色不正确(请参阅评论,我试图将u8vec4解释为RGBA颜色):
const int win_width = 640;
const int win_height = 480;
std::vector<glm::u8vec4> colors{ win_width * win_height, glm::u8vec4{ 0, 0, 0, 0 } };
SDL_Surface* render_surface = SDL_CreateRGBSurfaceFrom(&colors[0], win_width, win_height, 32,
sizeof(glm::u8vec4) * win_width, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
SDL_Texture* render_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_STREAMING, win_width, win_height);
// { 255, 0, 0, 255 } = Red
// { 255, 0, 0, 100 } = Darker red, alpha seems to be working
// { 0, 255, 0, 255 } = Purple!? Should be green?
// { 0, 0, 255, 255 } = Yellow, expecting blue
std::fill(colors.begin(), colors.end(), glm::u8vec4{ 0, 0, 0, 255 }); // Red
SDL_UpdateTexture(render_texture, nullptr, render_surface->pixels, render_surface->pitch);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, render_texture, nullptr, nullptr);
SDL_RenderPresent(renderer);
您应该尝试根据端位数设置位标记。我是这样做的:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const uint32_t R_MASK = 0xff000000;
const uint32_t G_MASK = 0x00ff0000;
const uint32_t B_MASK = 0x0000ff00;
const uint32_t A_MASK = 0x000000ff;
#else
const uint32_t R_MASK = 0x000000ff;
const uint32_t G_MASK = 0x0000ff00;
const uint32_t B_MASK = 0x00ff0000;
const uint32_t A_MASK = 0xff000000;
#endif
在你的例子中,你得到了颜色蒙版的另一种方式。
我认为Jongware是正确的,格式是ABGR。
// { 255, 0, 0, 100 } = Darker red, alpha seems to be working
我猜这里的alpha看起来是正确的,因为背景是黑色的,通过减少红色的数量到100,它会自然地与背景融合。
我还认为你没有设置SDL_BlendMode
相关文章:
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 如何在内核C++中使用1920x1080x16M图形或类似的16M颜色?(VGA)
- 如何在24位SDL_Surface上设置像素的颜色
- 如何从SDL_Surface获取特定像素的颜色
- 列表视图更改选择颜色
- GtkTreeView 交替行颜色
- 如何在C++中为表面制作邻接矩阵
- dx11 渲染到纹理仅显示透明颜色
- 使用 OpenGL 4.5 更改所选顶点的颜色
- 为什么我的 LEGACY OPENGL 颜色反转了?
- 双击更改 mfc 中列表控件中的行的颜色
- 更改 QT 中按钮的颜色
- 当我使用CHAR_INFO结构时,控制台会无缘无故地改变颜色
- 列表视图项的替代颜色
- GLSL 将 uint 转换为浮点颜色
- std::带有颜色和标题的 clog 包装器无法正确打印整数
- Vec3b:r/g/b 颜色的最大值为 254,而不是 255
- 如何将矢量对象更改为不同的颜色?
- 开放式颜色多边形表面的最简单方法
- SDL2 纹理的像素格式和表面颜色遮罩