gpt4 book ai didi

c++ - 整数 RGB 和双 alpha 到 DWORD,然后转换为 float

转载 作者:行者123 更新时间:2023-11-28 07:27:15 30 4
gpt4 key购买 nike

我需要将传递给函数的整数 RGB 颜色转换为介于 0 和 1 之间的 double shift double alpha,然后将其推回 float 组。

#define __GETR(x) ((x & 0x0000FF))
#define __GETG(x) ((x & 0x00FF00)>>8)
#define __GETB(x) ((x & 0xFF0000)>>16)

// NOTE: The vertex format for this class should be written so that color is an integer and not float.
void AddColor(int col, double alpha)
{
vertices.push_back(D3DCOLOR_RGBA(__GETR(col), __GETG(col), __GETB(col), (int)alpha*255));
useColors = true;
}

最佳答案

以下应该有效:

int result = __GETR(x) * alpha;

右边是浮点运算,所以__GETR(x)在乘法前先转换为浮点值;最后,结果被截断以适应 int

关于c++ - 整数 RGB 和双 alpha 到 DWORD,然后转换为 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18546355/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com