Re: C++ fixed width and strange 0 truncation
Re: C++ fixed width and strange 0 truncation SDL_Color is provided by SDL2. As I'm already using SDL2 I thought I should go ahead and use what is provided. I'm just story my colors in SDL_Color structs and getting the r, g, b, and a values when needed.I'm not as familiar with the bitwise operators as I should be, mostly due to lakck of use, but I will also keep that in mind. URL: https://forum.audiogames.net/post/511097/#p511097 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: C++ fixed width and strange 0 truncation
Re: C++ fixed width and strange 0 truncation I'm not offhand familiar with that struct, but you can pack them as well yourself, assuming each is an int from 0 to 255:int color = (x.r<<24)+(x.g<<16)+(x.b<<8)+x.a;You may already know this one though. URL: https://forum.audiogames.net/post/510990/#p510990 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: C++ fixed width and strange 0 truncation
Re: C++ fixed width and strange 0 truncation I'm just going to use struct SDL_Color {r, g, b, a}. I didn't necessarily want to have to use that and have to unpack the components every time, but its way more clear, compatible with many more systems, and easier to manipulate the individual elements.neat trick though to get each component. I'll keep that in my back pocket. URL: https://forum.audiogames.net/post/510987/#p510987 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: C++ fixed width and strange 0 truncation
Re: C++ fixed width and strange 0 truncation Your issue is that the formatting ignores leading zero bits because it's for human-friendly output. You will need to ask it to print fixed width hex.The C++ streams are complicated and massively overdesigned. I always use printf for these cases. I don't know the specifier offhand, but you want to find the hex-formatted output one, then you want to set the field width to 8 characters, and then it will pad with leading zeros.Alternatively, since I feel like the question you're also trying to ask is how do you get the bytes separated for analysis:int color = 0x12345678; unsigned char red, green, blue, alpha; red = color & 0xff00; green = color & 0x00ff; blue = color & 0xff00; alpha = color & 0x00ff;Which works on any architecture irregardless of endianness, and doesn't break at -O3 because you ran afoul of the pointer aliasing rules either. URL: https://forum.audiogames.net/post/510927/#p510927 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector