Skip to content

olc::Pixel

Javidx9 edited this page Apr 16, 2020 · 2 revisions

A struct that represents a single pixel in "engine" space. Pixels have a width and a height value and are rendered in "screen space". Therefore, the minimum useful size of a pixel is 1x1, which then maps directly onto display pixels on-screen.

Pixels consist of 4 components, red, green, blue and alpha. The configuration of a pixel can be set in various ways. By default Pixel alpha values are set to 255 (no transparency).

// Set explicitly
olc::Pixel p;
p.r = 100;
p.g = 200;
p.b = 150;
p.a = 255;

// Set via constructor (alpha is default)
olc::Pixel p(100,200,150);

// Set via constructor with alpha
olc::Pixel p(100,200,150,255);

// Set via HEX
olc::Pixel p(0xFF96C864);
p.n = 0xFF96C864 // Note order is ABGR

// Set Via Float
olc::Pixel p = olc::PixelF(0.1f, 0.2f, 0.3f, 1.0f);

A variety of convenience constants have been created:

  • WHITE(255, 255, 255)
  • GREY(192, 192, 192)
  • DARK_GREY(128, 128, 128)
  • VERY_DARK_GREY(64, 64, 64)
  • RED(255, 0, 0)
  • DARK_RED(128, 0, 0)
  • VERY_DARK_RED(64, 0, 0)
  • YELLOW(255, 255, 0)
  • DARK_YELLOW(128, 128, 0)
  • VERY_DARK_YELLOW(64, 64, 0)
  • GREEN(0, 255, 0)
  • DARK_GREEN(0, 128, 0)
  • VERY_DARK_GREEN(0, 64, 0)
  • CYAN(0, 255, 255)
  • DARK_CYAN(0, 128, 128)
  • VERY_DARK_CYAN(0, 64, 64)
  • BLUE(0, 0, 255)
  • DARK_BLUE(0, 0, 128)
  • VERY_DARK_BLUE(0, 0, 64)
  • MAGENTA(255, 0, 255)
  • DARK_MAGENTA(128, 0, 128)
  • VERY_DARK_MAGENTA(64, 0, 64)
  • BLACK(0, 0, 0)
  • BLANK(0, 0, 0, 0)

These can be used in place of a olc::Pixel argument, for example:

Draw(10, 10, olc::DARK_BLUE); // Draws a dark blue pixel at location (10,10)
Clone this wiki locally