Whilst there is sample code for separating a 32-bit value into its corresponding red, green and blue variants, the code is rather more complicated than it needs to be.
Thus, I present the simpler version :
FUNCTION RGBR%:colour%
INLINE
return (DGNat) colour & 255;
ENDINLINE
ENDFUNCTION
FUNCTION RGBG%:colour%
INLINE
return (DGNat) ((colour>>8) & 255);
ENDINLINE
ENDFUNCTION
FUNCTION RGBB%:colour%
INLINE
return (DGNat) ((colour>>16) & 255);
ENDINLINE
ENDFUNCTION
Try to use:
FUNCTION Get_R_G_B: color, BYREF R, BYREF G, BYREF B
INLINE
R = (DGNat) colour & 255;
G = (DGNat) ((colour>>8) & 255);
B = (DGNat) ((colour>>16) & 255);
ENDINLINE
ENDFUNCTION
Thats useful if you want to get the three components in one go, or you don't want to use the return value as a parameter for a function :)
What is DGNat? - it's not documented in GLBasic or on the online helpfile.
GLB knows what it is, but it's not in uppercase...
DGInt = Float variable
DGNat = Integer variable
in INLINE blocks
Quote from: Quentin on 2009-Sep-26
DGInt = Float variable
DGNat = Integer variable
in INLINE blocks
@ Quentin:
Thats right!
@ MrTAToad:
Thats true, but you need normaly all 3 values :)
But nice work!
Thanks for sharing this!
No problem :good:
Quote from: Quentin on 2009-Sep-26
DGInt = Float variable
DGNat = Integer variable
in INLINE blocks
OK. Cheers :)
there is GLBasic code for that.
http://www.glbasic.com/forum/index.php?topic=1637.0 (http://www.glbasic.com/forum/index.php?topic=1637.0)
Mine is/should be a bit more efficient =D