Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

#ActualHodgman

Posted 09 August 2012 - 12:18 AM

With your suggestion, you don't even need a "conversion" step, assuming that the API that you're using uses RGBA byte ordering.
e.g.
Color* Screen = new Color[1024*768];
Uint32* converted = static_cast<Uint32*>(Screen);//no conversion, just telling fibs about the data type, because they're bitwise equivalents anyway.
If the API uses a different byte-ordering, you can just rearrange the order of the members in your struct, e.g.
struct Color
{
#if defined(API_ARGB)
	   Uint8 alpha;
	   Uint8 red;
	   Uint8 green;
	   Uint8 blue;
#elif defined(API_BRGA)
	   Uint8 blue;
	   Uint8 green;
	   Uint8 red;
	   Uint8 alpha;
#else
#error "todo - more options"
#endif
};

Also, is there a common, generic way to represent images that isn't API specific?

Yep, an array of bytes, like you're suggesting ;)

#2Hodgman

Posted 09 August 2012 - 12:15 AM

With your suggestion, you don't even need a "conversion" step, assuming that the API that you're using uses RGBA byte ordering.
e.g.
Color* Screen = new Color[1024*768];
Uint32* converted = static_cast<Uint32*>(Screen);//no conversion, just telling fibs about the data type, because they're bitwise equivalents anyway.
If the API uses a different byte-ordering, you can just rearrange the order of the members in your struct, e.g.
struct Color
{
	   Uint8 alpha;
	   Uint8 red;
	   Uint8 green;
	   Uint8 blue;
};

Also, is there a common, generic way to represent images that isn't API specific?

Yep, an array of bytes, like you're suggesting ;)

#1Hodgman

Posted 09 August 2012 - 12:12 AM

With your suggestion, you don't even need a "conversion" step, assuming that the API that you're using uses RGBA byte ordering.
e.g.
Color* Screen = new Color[1024*768];
Uint32* converted = static_cast<Uint32*>(Screen);//no conversion, just telling fibs about the data type, because they're bitwise equivalents anyway.
If the API uses a different byte-ordering, you can just rearrange the order of the members in your struct, e.g.
struct Color
{
	   Uint8 alpha;
	   Uint8 red;
	   Uint8 green;
	   Uint8 blue;
};

PARTNERS