HEX$ 32 Bit Values

From QB64 Wiki
Revision as of 06:13, 25 May 2011 by imported>Clippy
Jump to navigation Jump to search

Hexadecimal values can be used to set a _PALETTECOLOR instead of using _RGB32 or _RGBA32 values.

The hex value for bright white(attribute 15) is &HFFFFFFFF or:

Alpha = FF (255), Red = FF (255), Green = FF (255), Blue = FF (255)

_RGB32 will always return an alpha value of 255 for fully opaque colors only. Values can range from &HFF000000 to &HFFFFFFFF.

_RGBA can set the transparency so hexadecimal values can range from &H000000 (zero alpha) to &HFFFFFFFF (full alpha).

So expanding on the principle above allows us to easily make up our own hex color values:

_PALETTECOLOR 1, &HFFFF0000 'is full red
_PALETTECOLOR 2, &HFFFF00FF 'is purple

Example: Converting the color port RGB intensity palette values 0 to 63 to 32 bit hexadecimal values.

SCREEN 12 FOR attribute = 1 TO 15 OUT &H3C7, attribute 'set color attribute to read red = INP(&H3C9) * 4 'convert port setting to 32 bit values grn = INP(&H3C9) * 4 blu = INP(&H3C9) * 4 hex32$ = HEX$(_RGB32(red, grn, blu)) 'always returns the 32 bit value PRINT "COLOR" + STR$(_RGB(red, grn, blu)) + " = &H" + hex32$ 'returns closest attribute NEXT

Note: This procedure also shows how the returns from _RGB and _RGB32 differ in a non-32 bit screen mode.

See also:

Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page