Previous: 4.51.2.4.17. ogFillCircle() To the Table of Contents Next: 4.51.2.4.19. ogFillPolygon()
4.51.2.4.17. ogFillCircle() Table of Contents 4.51.2.4.19. ogFillPolygon()

- 4.51.2.4.18. -
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.18. ogFillGouraudPolygon()


4.51.2.4.18. ogFillGouraudPolygon()

Targets: MS-DOS, Win32 console


ObjGfx40 Unit

Draws a Gouraud shaded polygon.

Declaration:
  procedure ogFillGouraudPolygon(numPoints:uInt32; var polyPoints: array of
                      ogPoint2d; varcolours:array of ogRGBA8);
Remarks:

PolyPoints is an array of ogPoint2d that contains the coordinates of each intersection in the polygon. NumPoints specifies the number of coordinates in PolyPoints. Colours is an array of ogRGBA8, which contains the colour for each vertex. Complex Gouraud shaded polygons are possible, but not very useful.

See also: Sample code:
{ogFillGouraudPolygon.pas}

uses
  ObjGfx40, CRT;

const 
  MAX_POINTS=4;
  
var 
  points: array[ 0..MAX_POINTS-1 ] of ogPoint2d;
  pointsDir: array[ 0..MAX_POINTS-1 ] of ogPoint2d;
  colours: array[ 0..MAX_POINTS-1 ] of ogRGBA8;
  colourDirs: array[ 0..MAX_POINTS-1 ] of record rDir, gDir, bDir:int32 end;
  count:integer;
  buf:^ogSurface;
    
begin

  randomize;

  new(buf, ogInit);

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

  buf^.ogClone(screen^);

  for count:=0 to MAX_POINTS-1 do
    with points[count] do
      begin
        x := random(screen^.ogGetMaxX-1)+1;
        y := random(screen^.ogGetMaxY-1)+1;
      end;

  for count:=0 to MAX_POINTS-1 do
    with pointsDir[count] do
      begin
        if (random(100) > 50) then x := -1 else x := 1;
        if (random(100) > 50) then y := -1 else y := 1;
      end;

  for count:=0 to MAX_POINTS-1 do
    with colours[count], colourDirs[count] do
      begin
        red := random(254)+1;
        green := random(254)+1;
        blue := random(254)+1;

        rdir := 1;
        gdir := -1;
        bdir := 1;
      end;

  repeat
    for count:=0 to MAX_POINTS-1 do
      begin
        with colours[count], colourDirs[count] do
          begin
            if (red = 0) or (red=255) then rdir := -rdir else
              if (random(100) > 97) then rdir:=-rdir;
            if (green = 0) or (green=255) then gdir := -gdir else
              if (random(100) > 97) then gdir:=-gdir;
            if (blue = 0) or (blue=255) then bdir := -bdir else
              if (random(100) > 97) then bdir := -bdir;
            inc(red, rDir);
            inc(green, gDir);
            inc(blue, bDir);
          end;

        inc(points[count].x, pointsDir[count].x);
        if ((points[count].x = 0) or (points[count].x = screen^.ogGetMaxX)) then
          pointsDir[count].x := -pointsDir[count].x;

        inc(points[count].y, pointsDir[count].y);
        if ((points[count].y = 0) or (points[count].y = screen^.ogGetMaxY)) then
          pointsDir[count].y := -pointsDir[count].y;
      end;

    buf^.ogFillGouraudPolygon(MAX_POINTS, points, colours);
    for count:=0 to MAX_Points-1 do
      with points[count], colours[count] do
        buf^.ogFillCircle(x, y, 5, buf^.ogRGB(red, green, blue));
    screen^.ogCopy(buf^);
    buf^.ogClear(buf^.ogRGB(0, 0, 0));
  until keyPressed;
  while keyPressed do readKey;

  dispose(buf, ogDone);
end.



Previous: 4.51.2.4.17. ogFillCircle() To the Table of Contents Next: 4.51.2.4.19. ogFillPolygon()
4.51.2.4.17. ogFillCircle() Table of Contents 4.51.2.4.19. ogFillPolygon()

- 4.51.2.4.18. -