[edit 1] DOOOOH. I accidentally placed my color code above allegro_init. UHGGGHHH.
[edit 2] WAIT. Now THIS is still really confusing. If I printf with floats, they display correctly:
(RGBA) 0.501961 0.250980 0.501961 1.000000 0.501961 0.250980 0.501961 1.000000 0.501961 0.250980 0.501961 1.000000
Now watch what happens when I use printf unsigned int:
1056997505 1056997505 255 2011460928 0 0 2013416856 0 1056997505 1056997505 2013416888 2011460928
What the heck is going on? Are there multiple "float" values for the same thing? Why would they change going from one variable to another, and why ONLY when using printf with integer output?
Here's both output, at the same time, so you can be sure there's no other data changes:
printf("%12u %12u %12u %12u - %12f %12f %12f %12f \n", c.r, c.g, c.b, c.a, c.r, c.g, c.b, c.a);
1056997505 1056997505 255 991089984 - 0.501961 0.250980 0.501961 1.000000 0 0 993045912 0 - 0.501961 0.250980 0.501961 1.000000 1056997505 1056997505 993045944 991089984 - 0.501961 0.250980 0.501961 1.000000
Using ul instead of u (unsigned long) doesn't help either.
[orignal post:]
I keep getting strange problems. One is, printf doesn't seem to always output.
But the DAllegro specific issue...
Output:
--------------- 0 0 255 0 0 -111424104 0 0 -111424072 ---------------
First, why is R=0, G=0 in the first line?
Secondly, why does the color data explode when I store it in a struct?
I'm looking into this problem because I'm writing something super-simple and trying to draw my "players" with a set color. And whenever I pass the data, they go invisible.
I thought structs were value-types, so they should copy in just fine. And if they're going out of scope, shouldn't that be a segfault?
Hmm...
Why would they change going from one variable to another, and why ONLY when using printf with integer output?
You're running into the gnarly details of the calling convention (probably optlink, if you're on Windows). Floating point values and integer values are probably placed in different memory locations, and by asking it to decode integers when you're passing floats, you're likely reading garbage.
I'm running Linux, but the same may apply. It's certainly a head scratcher for me.
I've never used D, but
Float: 0.501961
Actual float value stored in memory: 0.5019609928131103515625
Breakdown:
float = sign : exponent : mantissa
sign: 0
exp: 01111110
mantissa: 00000001000000010000100
Binary: 00111111000000001000000010000100
Hex: 0x3f008084
Integer: 1056997508
Yes! But perhaps I didn't make it clearer. Why does the value change... once it's stored into a class method?
The only possibility (which I don't think exists on further exploration) was that there were multiple bitfield values that equal a float value and somehow it was "converted" to the second one in some kind of casting or something. But I think that's false.