2013-08-31 21 views
0

我需要将传递到我的函数移位双alpha的0到1之间的整数RGB颜色转换为它,然后将其推回到浮点数组中。整数RGB和双alpha到DWORD,然后强制浮点数

#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; 
} 
+0

你不应该在你的名字中有两个下划线,也不能用下划线 - 大写字母开头。这些是保留的,你可能会造成难以发现的细微错误。只需选择正常的名字。 –

+0

是的,我真的无法做任何事情,这是一个开源项目,而其他人最初在我们的OpenGL图形系统中编写了颜色定义,但我一定会在将来删除这些颜色定义,谢谢。 – Goombert

回答

1

以下应该工作:

int result = __GETR(x) * alpha; 

右手侧是浮点运算,所以__GETR(x)转换为乘法之前浮点值;最后结果被截断以适合int

+0

这看起来像我的DX代码http://www.gophoto.it/view.php?i=http://oi40.tinypic.com/or54kx.jpg – Goombert

+0

这应该看起来像它的样子我的OpenGL版本http://oi39.tinypic.com/2w53cqv.jpg – Goombert

+0

此代码的完整版本可在线获取我的开源项目https://github.com/RobertBColton/enigma-dev/blob/master/ENIGMAsystem /SHELL/Graphics_Systems/Direct3D9/DX9model.cpp – Goombert