Re: C++ fixed width and strange 0 truncation

2020-03-22 Thread AudioGames . net Forum — Developers room : Kyleman123 via Audiogames-reflector


  


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

2020-03-21 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


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

2020-03-21 Thread AudioGames . net Forum — Developers room : Kyleman123 via Audiogames-reflector


  


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

2020-03-21 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


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


C++ fixed width and strange 0 truncation

2020-03-21 Thread AudioGames . net Forum — Developers room : Kyleman123 via Audiogames-reflector


  


C++ fixed width and strange 0 truncation

Long story short, I am trying to save a 32 bit or 4 byte unsigned int. This is being used as hex values for colors that take the following form:0xRRGGBBAAwhere RR is the amount of red from 0 - 255where GG is the amount of green from 0 - 255where BB is the amount of blue from 0 - 255where AA is the alpha or transparency from 0 - 255see my code below.The problem arises when there are leading zeros such as in the colors green (0x00ff00ff) and blue (0x). I know those aren't the precise names, but stay with me. The zeros get truncated off leaving me with 0xff00ff and 0x respectively. these do not draw as colors on the screen as they don't have the required bits. How can I ensure that my values retain all of the bits? I have tried storing them in unsigned int, Uint32, uint32_t, uint_fast32_t, and uint_least32_t. all of these seem to drop the leading zeros even though the constant width values say they should keep all 32 bits. Is this a compiler optimization I can turn off? I should say I intend on using clang for cross platform compatibility. Currently I'm on my Mac in Xcode and I get the same results with g++ in terminal.My example code is not at all representative of what I'm actually doing with the colors. I know I could manipulate the stream with std::showcase, std::internal, and std::set fill('0') to this play the hex correctly, but that is only fixing the display and not solving the underlying issue.Any help would be appreciated.#include 
using namespace std;

int main()
{
 uint32_t red = 0xffff;
 uint32_t green = 0x00ff00ff;
 uint32_t blue = 0x;

 cout << red << ", " << green << ", " << blue << endl;
 cout << hex << red << ", " << green << ", " << blue << endl;

  return 0;
}

URL: https://forum.audiogames.net/post/510921/#p510921




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector