Byte manipulation question. I *should* know this...

Started by
10 comments, last by MarkS 14 years, 1 month ago
Or you could maybe use a union:

union {    unsigned char components[4];    unsigned long rgba;}PixelUnion;// "texture" is of type unsigned long...offset = (tv * tex_width) + tu;PixelUnion.rgba = texture[offset];// PixelUnion.components[0], PixelUnion.components[1], PixelUnion.components[2] and PixelUnion.components[3] are the components
Advertisement
Quote:Original post by Vortez
Why not simply do this?

offset = ((tv * tex_width) + tu) * 4;
memcpy(buffer, &texture[offset], 4);

or even

UINT *pData = (UINT*)&texture[offset];
*buffer = *pData;


That's great if all I'm doing is copying from the texture to the offscreen bitmap. However, if I want to do any blending or filtering of the texture, I need the components.

Quote:Original post by BigJim
Or you could maybe use a union:

*** Source Snippet Removed ***


Interesting...

No, I am not a professional programmer. I'm just a hobbyist having fun...

This topic is closed to new replies.

Advertisement