Previous: 4.51.2.4.43. ogRect() To the Table of Contents Next: 4.51.2.4.45. ogRGBA()
4.51.2.4.43. ogRect() Table of Contents 4.51.2.4.45. ogRGBA()

- 4.51.2.4.44. -
Table of Contents
4. Standard Units
4.51. ObjGfx40 - ObjectGraphics 4.0 Unit
4.51.2. ObjGfx40 Unit Object Types
4.51.2.4. ogSurface object
4.51.2.4.44. ogRGB()


4.51.2.4.44. ogRGB()

Targets: MS-DOS, Win32 console


ObjGfx40 Unit

Converts an RGB triplet into a packed pixel.

Declaration:
  function ogRGB(red, green, blue:uInt8):uInt32;
Remarks:

For all high-colour and true-colour surfaces, this will pack the pixel based on the pixel format of the surface. Different surface can have different RGB orderings and sizes, so it is advised one use this function to generate colour values for other functions. For 8BPP buffers, this function will return the closest colour to the requested RGB value using an imperfect colour matching algorithm.

If the surface has an alpha channel, the default alpha will be encoded into the pixel.
A totally opaque pixel has an alpha level of 255.
A totally transparent pixel has an alpha level of 0.
How the pixel is rendered to the surface depends on the drawing function and whether or not blending is enabled.

Restrictions:

RGB channels are at most 8-bits wide. This will be changed in a future revision. Will only return a packed pixel for surfaces with a bitdepth of 8, 15, 16, 24, and 32.

See also: Sample code:
{ogRGB.pas}

uses
  ObjGfx40, CRT;

var 
  xx, yy, zz:uInt32;

begin
  if not screen^.ogCreate(800, 600, OG_PIXFMT_32BPP) then
    begin
      writeln('Error setting video mode');
      halt
    end;

  {Set up an optimized palette for 256 colours if dealing with
   8bpp}
  with screen^ do
    if (ogGetBPP = 8) then
      begin
        for xx:=0 to 15 do
          ogSetRGBPalette(xx, (xx+1)*16-1, 255, 0);
        for xx:=0 to 15 do	  
          ogSetRGBPalette(xx+16, 255, 255-((xx+1)*16-1), 0);
        for xx:=0 to 15 do	  
          ogSetRGBPalette(xx+32, 255, 0, (xx+1)*16-1);
        for xx:=0 to 15 do
          ogSetRGBPalette(xx+48, 255-((xx+1)*16-1), 0, 255);
        for xx:=0 to 15 do
          ogSetRGBPalette(xx+64, 0, ((xx+1)*16-1), 255);
        for xx:=0 to 15 do
          ogSetRGBPalette(xx+80, 0 ,255, 255-((xx+1)*16-1));

        for xx:=0 to 15 do
          ogSetRGBPalette(xx+96, 255-((xx+1)*16-1), 255, 255);
        for xx:=0 to 15 do
          ogSetRGBPalette(xx+112, 255, 255-((xx+1)*16-1), 255);
        for xx:=0 to 15 do
          ogSetRGBPalette(xx+128, 255, 255, 255-((xx+1)*16-1));

        for xx:=0 to 15 do
          ogSetRGBPalette(xx+144, 255, (xx+1)*16-1, (xx+1)*16-1);
        for xx:=0 to 15 do
          ogSetRGBPalette(xx+160, (xx+1)*16-1, 255,(xx+1)*16-1);
        for xx:=0 to 15 do
          ogSetRGBPalette(xx+176, (xx+1)*16-1, (xx+1)*16-1,255);

        for xx:=0 to 15 do
          ogSetRGBPalette(xx+192, (xx+1)*16-1, 255-((xx+1)*16-1), 255);
        for xx:=0 to 15 do
          ogSetRGBPalette(xx+208, 255, (xx+1)*16-1, 255-((xx+1)*16-1));
        for xx:=0 to 15 do
          ogSetRGBPalette(xx+224, (xx+1)*16-1, 255, 255-((xx+1)*16-1));

        for xx:=0 to 15 do
          ogSetRGBPalette(xx+240, (xx+1)*16-1, (xx+1)*16-1, (xx+1)*16-1);

        ogSetRGBPalette(0, 0, 0, 0);
        for xx:=0 to 255 do
          ogVLine(xx, 0, 63, xx);
      end; {if bpp=8}

  zz := 1;
  repeat
    with screen^ do
      for yy:=0 to 255 do    
        for xx:=0 to 255 do    
          if (yy=0) or (xx=255) or (zz=255) then
          ogSetPixel(256+128+xx-(zz div 2), 128+yy+(zz div 2),
                     ogRGB(xx, 255-yy, zz));
    inc(zz,2);
  until (keyPressed) or (zz > 255);
  
  while keyPressed do readKey;
  ReadKey;
end.



Previous: 4.51.2.4.43. ogRect() To the Table of Contents Next: 4.51.2.4.45. ogRGBA()
4.51.2.4.43. ogRect() Table of Contents 4.51.2.4.45. ogRGBA()

- 4.51.2.4.44. -