I have a list of integers, obtained through C ++ code and which representing different D3DCOLORVALUE ambient, etc...
What is the correct method to obtain the same colors, from this numbers, in Delphi?.
For example, using a program in C ++ (Visual Studio 2012), by calling a library routine in C ++ (separate dll file) I can obtain the following values:
-1.44852785e-016 = 2770796799 (represent the color)
1.57844226e+11 = 1376977151 (represent the color)
-1.98938735e+034 = 4168431103 (represent the color)
3.39617733e+038 = 4294967295 (represent the color)
@Rudy Velthuis, The original code is: (some values contained in the array are those shown above)
int32_t index = ifcObject->indicesForFaces[0];
uint32_t ambient = ((int32_t*) vertices)[index * (vertexElementSize / sizeof(float)) + 6],
diffuse = ((int32_t*) vertices)[index * (vertexElementSize / sizeof(float)) + 7],
emissive = ((int32_t*) vertices)[index * (vertexElementSize / sizeof(float)) + 8],
specular = ((int32_t*) vertices)[index * (vertexElementSize / sizeof(float)) + 9];
Then in Delphi XE6 using
PInteger (@ColorsArray [index * sizeOfVertices + 6])^
I get the same values but, in delphi the colors are black or null. Sometimes negative numbers are obtained, it is understood that in C ++ it is possible to represent a color with a negative value but in delphi does not work.
How can I convert a color value, obtained in D3DCOLORVALUE format, to a Delphi's TColor?
That the values are used to obtain the colors of objects in D3DMATERIAL9, D3DCOLORVALUE Ambient (Ambient color RGB)
FLOAT r;
FLOAT g;
FLOAT b;
FLOAT a;
This function make the color:
void SetColor(
D3DCOLORVALUE * iColor,
uint32_t color
)
{
iColor->r = (float) (color & ((unsigned int) 255 * 256 * 256 * 256)) / (256 * 256 * 256);
iColor->r /= 255.f;
iColor->g = (float) (color & (255 * 256 * 256)) / (256 * 256);
iColor->g /= 255.f;
iColor->b = (float) (color & (255 * 256)) / 256;
iColor->b /= 255.f;
iColor->a = (float) (color & (255));
iColor->a /= 255.f;
}
But in Delphi it does not work, the color obtained is wrong.
Comparison of colors with the @Dsm solution:
Left: Color obtained Right: Desired color
I have made a simple example to illustrate the differences:
The first color corresponds to the foot of the column and the second color corresponds to the column. The figure with the platform is the example with the library viewer, with the correct colors for that version and the figure on the right is an image of the watch in Visual Studio 2012 to show that the content of the array is the same and the value obtained with the cast is also the same but, when converting these numbers to colors they do not give the same result.
int32_t *
(IOW, to a pointer!) is pretty suspicious. Who on earth wrote that code? – Rudy VelthuisAmbient light color takes the form of an RGBA value, where each component is an integer value from 0 to 255. This is unlike most color values in Direct3D.
– LU RDint32*
? The original code casts a pointer to, well, a pointer, assuming thatvertices
is an array, and not a float to a pointer. – Rudy Velthuis