QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The _RGB function returns the closest palette attribute index (legacy SCREEN modes) OR the LONG 32-bit color value (32-bit screens).

Syntax

colorIndex~& = _RGB(red&, green&, blue&[, imageHandle&])

Description

Example(s)

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


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


COLOR 1 = &HFF0000A8
COLOR 2 = &HFF00A800
COLOR 3 = &HFF00A8A8
COLOR 4 = &HFFA80000
COLOR 5 = &HFFA800A8
COLOR 6 = &HFFA85400
COLOR 7 = &HFFA8A8A8
COLOR 8 = &HFF545454
COLOR 9 = &HFF5454FC
COLOR 10 = &HFF54FC54
COLOR 11 = &HFF54FCFC
COLOR 12 = &HFFFC5454
COLOR 13 = &HFFFC54FC
COLOR 14 = &HFFFCFC54
COLOR 15 = &HFFFCFCFC

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

See Also