Subsections

- 1 Introduction
  - 1 Requirements
  - 2 A word about mode selection
- 2 Constants, Types and Variables
  - 1 Types
- 3 Function list by category
  - 1 Initialization
  - 2 screen management
  - 3 Color management
  - 4 Drawing primitives
  - 5 Filled drawings
  - 6 Text and font handling
- 4 Functions and procedures
  - 1 Arc
  - 2 Bar
  - 3 Bar3D
  - 4 Circle
  - 5 ClearDevice
  - 6 ClearViewPort
  - 7 CloseGraph
  - 8 DetectGraph
  - 9 DrawPoly
  - 10 Ellipse
  - 11 FillEllipse
  - 12 FillPoly
  - 13 FloodFill
  - 14 GetArcCoords
  - 15 GetAspectRatio
  - 16 GetBkColor
  - 17 GetColor
  - 18 GetDefaultPalette
  - 19 GetDriverName
  - 20 GetFillPattern
  - 21 GetFillSettings
  - 22 GetGraphMode
  - 23 GetImage
  - 24 GetLineSettings
  - 25 GetMaxColor
  - 26 GetMaxMode
  - 27 GetMaxX
  - 28 GetMaxY
  - 29 GetModeName
  - 30 GetModeRange
  - 31 GetPalette
  - 32 GetPaletteSize
  - 33 GetPixel
  - 34 GetTextSettings
  - 35 GetViewSettings
  - 36 GetX
  - 37 GetY
  - 38 GraphDefaults
  - 39 GraphErrorMsg
  - 40 GraphResult
  - 41 ImageSize
  - 42 InitGraph
  - 43 InstallUserDriver
  - 44 InstallUserFont
  - 45 Line
  - 46 LineRel
  - 47 LineTo
  - 48 MoveRel
  - 49 MoveTo
  - 50 OutText
  - 51 OutTextXY
  - 52 PieSlice
  - 53 PutImage
  - 54 PutPixel
  - 55 Rectangle
  - 56 RegisterBGIDriver
  - 57 RegisterBGIFont
  - 58 RestoreCRTMode
  - 59 Sector
  - 60 SetActivePage
  - 61 SetAllPallette
  - 62 SetAspectRatio
  - 63 SetBkColor
  - 64 SetColor
  - 65 SetFillPattern
  - 66 SetFillStyle
  - 67 SetGraphBufSize
  - 68 SetGraphMode
  - 69 SetLineStyle
  - 70 SetPalette
  - 71 SetRGBPalette
  - 72 SetTextJustify
  - 73 SetTextStyle
  - 74 SetUserCharSize
  - 75 SetViewPort
  - 76 SetVisualPage
  - 77 SetWriteMode
  - 78 TextHeight
  - 79 TextWidth
- 5 Target specific issues
  - 1 DOS
  - 2 WINDOWS
  - 3 LINUX

# 8 The GRAPH unit.

graphex This document describes the `GRAPH` unit for Free Pascal, for all platforms. The unit was first written for DOS by Florian klämpfl, but was later completely rewritten by Carl-Eric Codere to be completely portable.

This chapter is divided in 4 sections.

- The first section gives an introduction to the graph unit.
- The second section lists the pre-defined constants, types and variables.
- The second section describes the functions which appear in the interface part of the GRAPH unit.
- The last part describes some system-specific issues.

#
1 Introduction

## 1 Requirements

The unit Graph exports functions and procedures for graphical output. It requires at least a VGA-compatible Card or a VGA-Card with software-driver (min. 512Kb video memory).

## 2 A word about mode selection

The graph unit was implemented for compatibility with the old graph unit. For this reason, the mode constants as they were defined in the graph unit are retained.

However, since

1. Video cards have evolved very much
2. Free Pascal runs on multiple platforms

it was decided to implement new mode and graphic driver constants, which are more independent of the specific platform the program runs on.

In this section we give a short explanation of the new mode system. the following drivers were defined:

    D1bit = 11;
    D2bit = 12;
    D4bit = 13;
    D6bit = 14;  { 64 colors Half-brite mode - Amiga }
    D8bit = 15;
    D12bit = 16; { 4096 color modes HAM mode - Amiga }
    D15bit = 17;
    D16bit = 18;
    D24bit = 19; { not yet supported }
    D32bit = 20; { not yet supported }
    D64bit = 21; { not yet supported }

    lowNewDriver = 11;
    highNewDriver = 21;

Each of these drivers specifies a desired color-depth.

The following modes have been defined:

    detectMode = 30000;
    m320x200 = 30001;
    m320x256 = 30002; { amiga resolution (PAL) }
    m320x400 = 30003; { amiga/atari resolution }
    m512x384 = 30004; { mac resolution }
    m640x200 = 30005; { vga resolution }
    m640x256 = 30006; { amiga resolution (PAL) }
    m640x350 = 30007; { vga resolution }
    m640x400 = 30008;
    m640x480 = 30009;
    m800x600 = 30010;
    m832x624 = 30011; { mac resolution }
    m1024x768 = 30012;
    m1280x1024 = 30013;
    m1600x1200 = 30014;
    m2048x1536 = 30015;

    lowNewMode = 30001;
    highNewMode = 30015;

These modes start at 30000 because Borland specified that the mode number should be ascending with increasing X resolution, and the new constants shouldn't interfere with the old ones.

The above constants can be used to set a certain color depth and resultion, as demonstrated in the following example:

Example

      Program inigraph1;

      { Program to demonstrate static graphics mode selection }

      uses graph;

      const
        TheLine = 'We are now in 640 x 480 x 256 colors!'+
                  ' (press <Return> to continue)';

      var
        gd, gm, lo, hi, error,tw,th: integer;
        found: boolean;

      begin
        { We want an 8 bit mode }
        gd := D8bit;
        gm := m640x480;
        initgraph(gd,gm,'');
        { Make sure you always check graphresult! }
        error := graphResult;
        if (error <> grOk) Then
          begin
          writeln('640x480x256 is not supported!');
          halt(1)
          end;
        { We are now in 640x480x256 }
        setColor(cyan);
        rectangle(0,0,getmaxx,getmaxy);
        { Write a nice message in the center of the screen }
        setTextStyle(defaultFont,horizDir,1);
        tw:=TextWidth(TheLine);
        th:=TextHeight(TheLine);
        outTextXY((getMaxX - TW) div 2,
                  (getMaxY - TH) div 2,TheLine);
        { Wait for return }
        readln;
        { Back to text mode }
        closegraph;
      end.

If other modes than the ones above are supported by the graphics card, you will not be able to select them with this mechanism.

For this reason, there is also a 'dynamic' mode number, which is assigned at run-time. This number increases with increasing X resolution. It can be queried with the `getmoderange` call. This call will return the range of modes which are valid for a certain graphics driver. The numbers are guaranteed to be consecutive, and can be used to search for a certain resolution, as in the following example:

Example

      Program inigraph2;

      { Program to demonstrate dynamic graphics mode selection }

      uses graph;

      const
        TheLine = 'We are now in 640 x 480 x 256 colors!'+
                  ' (press <Return> to continue)';

      var
        th,tw,gd, gm, lo, hi, error: integer;
        found: boolean;

      begin
        { We want an 8 bit mode }
        gd := D8bit;
        { Get all available resolutions for this bitdepth }
        getmoderange(gd,lo,hi);
        { If the highest available mode number is -1,
          no resolutions are supported for this bitdepth  }
        if hi = -1 then
          begin
          writeln('no 8 bit modes supported!');
          halt
          end;
        found := false;
        { Search all resolutions for 640x480 }
        for gm := lo to hi do
          begin
          initgraph(gd,gm,'');
          { Make sure you always check graphresult! }
          error := graphResult;
          if (error = grOk) and
             (getmaxx = 639) and (getmaxy = 479) then
            begin
            found := true;
            break;
            end;
          end;
        if not found then
          begin
          writeln('640x480x256 is not supported!');
          halt(1)
          end;
        { We are now in 640x480x256 }
        setColor(cyan);
        rectangle(0,0,getmaxx,getmaxy);
        { Write a nice message in the center of the screen }
        setTextStyle(defaultFont,horizDir,1);
        TW:=TextWidth(TheLine);
        TH:=TextHeight(TheLine);
        outTextXY((getMaxX - TW) div 2,
                  (getMaxY - TH) div 2,TheLine);
        { Wait for return }
        readln;
        { Back to text mode }
        closegraph;
      end.

Thus, the `getmoderange` function can be used to detect all available modes and drivers, as in the following example:

Example

      Program GetModeRange_Example;

      { This program demonstrates how to find all available graph modes }

      uses graph;

      const
        { Currently, only 4, 8, 15 and 16 bit modes are supported
          but this may  change in the future }
        gdnames: array[D4bit..D16bit] of string[6] =
          ('4 bit','6 bit','8 bit','12 bit','15 bit','16 bit');

      var
        t: text;
        line : string;
        gd, c, low, high, res: integer;
      begin
        assign(t,'modes.txt');
        rewrite(t);
        close(t);
        for gd := D4bit to D16bit do
          begin
          { Get the available mode numbers for this driver }
          getModeRange(gd,low,high);
          append(t);
          write(t,gdnames[gd]);
          Writeln(t,': low modenr = ',low,', high modenr = ',high);
          close(t);
          { If high is -1,
             no resolutions are supported for this bitdepth }
          if high = -1 then
            begin
            append(t);
            writeln(t,'  No modes supported!');
            writeln(t);
            close(t);
            end
          else
            { Enter all supported resolutions for this bitdepth
              and write their characteristics to the file }
            for c := low to high do
              begin
              append(t);
              writeln(t,'  testing mode nr ',c);
              close(t);
              initgraph(gd,c,'');
              res := graphresult;
              append(t);
              { An error occurred when entering the mode? }
              if res <> grok then
                writeln(t,grapherrormsg(res))
              else
                begin
                write(t,'maxx: ',getmaxx,', maxy: ',getmaxy);
                Writeln(t,', maxcolor: ',getmaxcolor);
                closegraph;
                end;
              writeln(t);
              close(t);
              end;
          append(t);
          writeln(t);
          close(t);
          end;
        Writeln('All supported modes are listed in modes.txt files');
      end.

# 2 Constants, Types and Variables

## 1 Types

    ArcCoordsType = record
     X,Y,Xstart,Ystart,Xend,Yend : Integer;
    end;
    FillPatternType = Array [1..8] of Byte;
    FillSettingsType = Record
     Pattern,Color : Word
    end;
    LineSettingsType = Record
      LineStyle,Pattern, Width : Word;
    end;
    PaletteType = Record
     Size : Byte;
     Colors : array[0..MAxColor] of shortint;
    end;
    PointType = Record
      X,Y : Integer;
    end;
    TextSettingsType = Record
     Font,Direction, CharSize, Horiz, Vert : Word
    end;
    ViewPortType = Record
      X1,Y1,X2,Y2 : Integer;
      Clip : Boolean
    end;

# 3 Function list by category

What follows is a listing of the available functions, grouped by category. For each function there is a reference to the page where you can find the function.

## 1 Initialization

Initialization of the graphics screen. ClearDevice Empty the graphics screen]

CloseGraph Finish drawing session, return to text mode
DetectGraph Detect graphical modes
GetAspectRatio Get aspect ratio of screen
GetModeRange Get range of valid modes for current driver
GraphDefaults Set defaults
GetDriverName Return name of graphical driver
GetGraphMode Return current or last used graphics mode
GetMaxMode Get maximum mode for current driver
GetModeName Get name of current mode
GraphErrorMsg String representation of graphical error
GraphResult Result of last drawing operation
InitGraph Initialize graphics drivers
InstallUserDriver Install a new driver
RegisterBGIDriver Register a new driver
RestoreCRTMode Go back to text mode
SetGraphBufSize Set buffer size for graphical operations
SetGraphMode Set graphical mode

## 2 screen management

General drawing screen management functions. ClearViewPort Clear the current viewport]

GetImage Copy image from screen to memory
GetMaxX Get maximum X coordinate
GetMaxY Get maximum Y coordinate
GetX Get current X position
GetY Get current Y position
ImageSize Get size of selected image
GetViewSettings Get current viewport settings
PutImage Copy image from memory to screen
SetActivePage Set active video page
SetAspectRatio Set aspect ratio for drawing routines
SetViewPort Set current viewport
SetVisualPage Set visual page
SetWriteMode Set write mode for screen operations

## 3 Color management

All functions related to color management. GetBkColor Get current background color]

GetColor Get current foreground color
GetDefaultPalette Get default palette entries
GetMaxColor Get maximum valid color
GetPaletteSize Get size of palette for current mode
GetPixel Get color of selected pixel
GetPalette Get palette entry
SetAllPallette Set all colors in palette
SetBkColor Set background color
SetColor Set foreground color
SetPalette Set palette entry
SetRGBPalette Set palette entry with RGB values

## 4 Drawing primitives

Functions for simple drawing. Arc Draw an arc]

Circle Draw a complete circle
DrawPoly Draw a polygone with N points
Ellipse Draw an ellipse
GetArcCoords Get arc coordinates
GetLineSettings Get current line drawing settings
Line Draw line between 2 points
LineRel Draw line relative to current position
LineTo Draw line from current position to absolute position
MoveRel Move cursor relative to current position
MoveTo Move cursor to absolute position
PieSlice Draw a pie slice
PutPixel Draw 1 pixel
Rectangle Draw a non-filled rectangle
Sector Draw a sector
SetLineStyle Set current line drawing style

## 5 Filled drawings

Functions for drawing filled regions. Bar3D Draw a filled 3D-style bar]

Bar Draw a filled rectangle
FloodFill Fill starting from coordinate
FillEllipse Draw a filled ellipse
FillPoly Draw a filled polygone
GetFillPattern Get current fill pattern
GetFillSettings Get current fill settings
SetFillPattern Set current fill pattern
SetFillStyle Set current fill settings

## 6 Text and font handling

Functions to set texts on the screen. GetTextSettings Get current text settings]

InstallUserFont Install a new font
OutText Write text at current cursor position
OutTextXY Write text at coordinates X,Y
RegisterBGIFont Register a new font
SetTextJustify Set text justification
SetTextStyle Set text style
SetUserCharSize Set text size
TextHeight Calculate height of text
TextWidth Calculate width of text

# 4 Functions and procedures

##
1 Arc

Declaration
  `Procedure Arc (X,Y : Integer; start,stop, radius : Word);`

  ``

Description
  `Arc` draws part of a circle with center at `(X,Y)`, radius `radius`, starting from angle `start`, stopping at angle `stop`. These angles are measured counterclockwise.
Errors
  None.
See also
  Circle,Ellipse GetArcCoords,PieSlice, Sector

##
2 Bar

Declaration
  `Procedure Bar (X1,Y1,X2,Y2 : Integer);`

  ``

Description
  Draws a rectangle with corners at `(X1,Y1)` and `(X2,Y2)` and fills it with the current color and fill-style.
Errors
  None.
See also
  Bar3D, Rectangle

##
3 Bar3D

Declaration
  `Procedure Bar3D (X1,Y1,X2,Y2 : Integer; depth : Word; Top : Boolean);`

  ``

Description
  Draws a 3-dimensional Bar with corners at `(X1,Y1)` and `(X2,Y2)` and fills it with the current color and fill-style. `Depth` specifies the number of pixels used to show the depth of the bar. If `Top` is true; then a 3-dimensional top is drawn.
Errors
  None.
See also
  Bar, Rectangle

##
4 Circle

Declaration
  `Procedure Circle (X,Y : Integer; Radius : Word);`

  ``

Description
  `Circle` draws part of a circle with center at `(X,Y)`, radius `radius`.
Errors
  None.
See also
  Ellipse,Arc GetArcCoords,PieSlice, Sector

##
5 ClearDevice

Declaration
  `Procedure ClearDevice ;`

  ``

Description
  Clears the graphical screen (with the current background color), and sets the pointer at `(0,0)`
Errors
  None.
See also
  ClearViewPort, SetBkColor

##
6 ClearViewPort

Declaration
  `Procedure ClearViewPort ;`

  ``

Description
  Clears the current viewport. The current background color is used as filling color. The pointer is set at `(0,0)`
Errors
  None.
See also
  ClearDevice,SetViewPort, SetBkColor

##
7 CloseGraph

Declaration
  `Procedure CloseGraph ;`

  ``

Description
  Closes the graphical system, and restores the screen modus which was active before the graphical modus was activated.
Errors
  None.
See also
  InitGraph

##
8 DetectGraph

Declaration
  `Procedure DetectGraph (Var Driver, Modus : Integer);`

  ``

Description
  Checks the hardware in the PC and determines the driver and screen-modus to be used. These are returned in `Driver` and `Modus`, and can be fed to `InitGraph`. See the `InitGraph` for a list of drivers and modi.
Errors
  None.
See also
  InitGraph

##
9 DrawPoly

Declaration
  `Procedure DrawPoly (NumberOfPoints : Word; Var PolyPoints;`

  ``

Description

  Draws a polygone with `NumberOfPoints` corner points, using the current color and line-style. PolyPoints is an array of type `PointType`.

Errors
  None.
See also
  Bar, seepBar3D, Rectangle

##
10 Ellipse

Declaration
  `Procedure Ellipse (X,Y : Integer; Start,Stop,XRadius,YRadius : Word);`

  ``

Description
  `Ellipse` draws part of an ellipse with center at `(X,Y)`. `XRadius` and `Yradius` are the horizontal and vertical radii of the ellipse. `Start` and `Stop` are the starting and stopping angles of the part of the ellipse. They are measured counterclockwise from the X-axis (3 o'clock is equal to 0 degrees). Only positive angles can be specified.
Errors
  None.
See also
  Arc Circle, FillEllipse

##
11 FillEllipse

Declaration
  `Procedure FillEllipse (X,Y : Integer; Xradius,YRadius: Word);`

  ``

Description
  `Ellipse` draws an ellipse with center at `(X,Y)`. `XRadius` and `Yradius` are the horizontal and vertical radii of the ellipse. The ellipse is filled with the current color and fill-style.
Errors
  None.
See also
  Arc Circle, GetArcCoords,PieSlice, Sector

##
12 FillPoly

Declaration
  `Procedure FillPoly (NumberOfPoints : Word; Var PolyPoints);`

  ``

Description

  Draws a polygone with `NumberOfPoints` corner points and fills it using the current color and line-style. PolyPoints is an array of type `PointType`.

Errors
  None.
See also
  Bar, seepBar3D, Rectangle

##
13 FloodFill

Declaration
  `Procedure FloodFill (X,Y : Integer; BorderColor : Word);`

  ``

Description

  Fills the area containing the point `(X,Y)`, bounded by the color `BorderColor`.

Errors
  None
See also
  SetColor, SetBkColor

##
14 GetArcCoords

Declaration
  `Procedure GetArcCoords (Var ArcCoords : ArcCoordsType);`

  ``

Description
  GetArcCoords returns the coordinates of the latest `Arc` or `Ellipse` call.
Errors
  None.
See also
  Arc, Ellipse

##
15 GetAspectRatio

Declaration
  `Procedure GetAspectRatio (Var Xasp,Yasp : Word);`

  ``

Description
  GetAspectRatio determines the effective resolution of the screen. The aspect ration can the be calculated as `Xasp/Yasp`.
Errors
  None.
See also
  InitGraph,SetAspectRatio

##
16 GetBkColor

Declaration
  `Function GetBkColor : Word;`

  ``

Description
  GetBkColor returns the current background color (the palette entry).
Errors
  None.
See also
  GetColor,SetBkColor

##
17 GetColor

Declaration
  `Function GetColor : Word;`

  ``

Description
  GetColor returns the current drawing color (the palette entry).
Errors
  None.
See also
  GetColor,SetBkColor

##
18 GetDefaultPalette

Declaration
  `Procedure GetDefaultPalette (Var Palette : PaletteType);`

  ``

Description
  Returns the current palette in `Palette`.
Errors
  None.
See also
  GetColor, GetBkColor

##
19 GetDriverName

Declaration
  `Function GetDriverName : String;`

  ``

Description
  GetDriverName returns a string containing the name of the current driver.
Errors
  None.
See also
  GetModeName, InitGraph

##
20 GetFillPattern

Declaration
  `Procedure GetFillPattern (Var FillPattern : FillPatternType);`

  ``

Description
  GetFillPattern returns an array with the current fill-pattern in `FillPattern`
Errors
  None
See also
  SetFillPattern

##
21 GetFillSettings

Declaration
  `Procedure GetFillSettings (Var FillInfo : FillSettingsType);`

  ``

Description
  GetFillSettings returns the current fill-settings in `FillInfo`
Errors
  None.
See also
  SetFillPattern

##
22 GetGraphMode

Declaration
  `Function GetGraphMode : Integer;`

  ``

Description
  GetGraphMode returns the current graphical modus
Errors
  None.
See also
  InitGraph

##
23 GetImage

Declaration
  `Procedure GetImage (X1,Y1,X2,Y2 : Integer, Var Bitmap;`

  ``

Description
  GetImage Places a copy of the screen area `(X1,Y1)` to `X2,Y2` in `BitMap`
Errors
  Bitmap must have enough room to contain the image.
See also
  ImageSize, PutImage

##
24 GetLineSettings

Declaration
  `Procedure GetLineSettings (Var LineInfo : LineSettingsType);`

  ``

Description
  GetLineSettings returns the current Line settings in `LineInfo`
Errors
  None.
See also
  SetLineStyle

##
25 GetMaxColor

Declaration
  `Function GetMaxColor : Word;`

  ``

Description
  GetMaxColor returns the maximum color-number which can be set with `SetColor`. Contrary to , this color isn't always guaranteed to be white (for instance in 256+ color modes).
Errors
  None.
See also
  SetColor, GetPaletteSize

##
26 GetMaxMode

Declaration
  `Function GetMaxMode : Word;`

  ``

Description
  GetMaxMode returns the highest modus for the current driver.
Errors
  None.
See also
  InitGraph

##
27 GetMaxX

Declaration
  `Function GetMaxX : Word;`

  ``

Description
  GetMaxX returns the maximum horizontal screen length
Errors
  None.
See also
  GetMaxY

##
28 GetMaxY

Declaration
  `Function GetMaxY : Word;`

  ``

Description
  GetMaxY returns the maximum number of screen lines
Errors
  None.
See also
  GetMaxY

##
29 GetModeName

Declaration
  `Function GetModeName (Var modus : Integer) : String;`

  ``

Description

  Returns a string with the name of modus `Modus`

Errors
  None.
See also
  GetDriverName, InitGraph

##
30 GetModeRange

Declaration
  `Procedure GetModeRange (Driver : Integer;
  LoModus, HiModus: Integer);`
Description
  GetModeRange returns the Lowest and Highest modus of the currently installed driver. If no modes are supported for this driver, HiModus will be -1.
Errors
  None.
See also
  InitGraph

##
31 GetPalette

Declaration
  `Procedure GetPalette (Var Palette : PaletteType);`

  ``

Description
  GetPalette returns in `Palette` the current palette.
Errors
  None.
See also
  GetPaletteSize, SetPalette

##
32 GetPaletteSize

Declaration
  `Function GetPaletteSize : Word;`

  ``

Description
  GetPaletteSize returns the maximum number of entries in the current palette.
Errors
  None.
See also
  GetPalette, SetPalette

##
33 GetPixel

Declaration
  `Function GetPixel (X,Y : Integer) : Word;`

  ``

Description
  GetPixel returns the color of the point at `(X,Y)`
Errors
  None.
See also

##
34 GetTextSettings

Declaration
  `Procedure GetTextSettings (Var TextInfo : TextSettingsType);`

  ``

Description
  GetTextSettings returns the current text style settings : The font, direction, size and placement as set with `SetTextStyle` and `SetTextJustify`
Errors
  None.
See also
  SetTextStyle, SetTextJustify

##
35 GetViewSettings

Declaration
  `Procedure GetViewSettings (Var ViewPort : ViewPortType);`

  ``

Description
  GetViewSettings returns the current viewport and clipping settings in `ViewPort`.
Errors
  None.
See also
  SetViewPort

##
36 GetX

Declaration
  `Function GetX : Integer;`

  ``

Description
  GetX returns the X-coordinate of the current position of the graphical pointer
Errors
  None.
See also
  GetY

##
37 GetY

Declaration
  `Function GetY : Integer;`

  ``

Description
  GetY returns the Y-coordinate of the current position of the graphical pointer
Errors
  None.
See also
  GetX

##
38 GraphDefaults

Declaration
  `Procedure GraphDefaults ;`

  ``

Description
  GraphDefaults resets all settings for viewport, palette, foreground and background pattern, line-style and pattern, filling style, filling color and pattern, font, text-placement and text size.
Errors
  None.
See also
  SetViewPort, SetFillStyle, SetColor, SetBkColor, SetLineStyle

##
39 GraphErrorMsg

Declaration
  `Function GraphErrorMsg (ErrorCode : Integer) : String;`

  ``

Description
  GraphErrorMsg returns a string describing the error `Errorcode`. This string can be used to let the user know what went wrong.
Errors
  None.
See also
  GraphResult

##
40 GraphResult

Declaration
  `Function GraphResult : Integer;`

  ``

Description
  GraphResult returns an error-code for the last graphical operation. If the returned value is zero, all went well. A value different from zero means an error has occurred. besides all operations which draw something on the screen, the following procedures also can produce a `GraphResult` different from zero:

  - InstallUserFont
  - SetLineStyle
  - SetWriteMode
  - SetFillStyle
  - SetTextJustify
  - SetGraphMode
  - SetTextStyle

Errors
  None.
See also
  GraphErrorMsg

##
41 ImageSize

Declaration
  `Function ImageSize (X1,Y1,X2,Y2 : Integer) : Word;`

  ``

Description
  ImageSize returns the number of bytes needed to store the image in the rectangle defined by `(X1,Y1)` and `(X2,Y2)`.
Errors
  None.
See also
  GetImage

##
42 InitGraph

Declaration
  `Procedure InitGraph (var GraphDriver,GraphModus : integer;
  const PathToDriver : string);`

  ``

Description

  `InitGraph` initializes the `graph` package. `GraphDriver` has two valid values: `GraphDriver=0` which performs an auto detect and initializes the highest possible mode with the most colors. 1024x768x64K is the highest possible resolution supported by the driver, if you need a higher resolution, you must edit MODES.PPI. If you need another mode, then set `GraphDriver` to a value different from zero and `graphmode` to the mode you wish (VESA modes where 640x480x256 is `101h` etc.). `PathToDriver` is only needed, if you use the BGI fonts from Borland.

Errors
  None.
See also
  Introduction, (page ), DetectGraph, CloseGraph, GraphResult

Example:

    var
       gd,gm : integer;
       PathToDriver : string;
    begin
       gd:=detect; { highest possible resolution }
       gm:=0; { not needed, auto detection }
       PathToDriver:='C:\PP\BGI'; { path to BGI fonts,
                                    drivers aren't needed }
       InitGraph(gd,gm,PathToDriver);
       if GraphResult<>grok then
         halt; ..... { whatever you need }
       CloseGraph; { restores the old graphics mode }
    end.

##
43 InstallUserDriver

Declaration
  `Function InstallUserDriver (DriverPath : String;
  AutoDetectPtr: Pointer) : Integer;`

  ``

Description
  InstallUserDriver adds the device-driver `DriverPath` to the list of .BGI drivers. `AutoDetectPtr` is a pointer to a possible auto-detect function.
Errors
  None.
See also
  InitGraph, InstallUserFont

##
44 InstallUserFont

Declaration
  `Function InstallUserFont (FontPath : String) : Integer;`

  ``

Description
  InstallUserFont adds the font in `FontPath` to the list of fonts of the .BGI system.
Errors
  None.
See also
  InitGraph, InstallUserDriver

##
45 Line

Declaration
  `Procedure Line (X1,Y1,X2,Y2 : Integer);`

  ``

Description
  Line draws a line starting from `(X1,Y1` to `(X2,Y2)`, in the current line style and color. The current position is put to `(X2,Y2)`
Errors
  None.
See also
  LineRel,LineTo

##
46 LineRel

Declaration
  `Procedure LineRel (DX,DY : Integer);`

  ``

Description
  LineRel draws a line starting from the current pointer position to the point`(DX,DY`, relative to the current position, in the current line style and color. The Current Position is set to the endpoint of the line.
Errors
  None.
See also
  Line, LineTo

##
47 LineTo

Declaration
  `Procedure LineTo (DX,DY : Integer);`

  ``

Description
  LineTo draws a line starting from the current pointer position to the point`(DX,DY`, relative to the current position, in the current line style and color. The Current position is set to the end of the line.
Errors
  None.
See also
  LineRel,Line

##
48 MoveRel

Declaration
  `Procedure MoveRel (DX,DY : Integer;`

  ``

Description
  MoveRel moves the pointer to the point `(DX,DY)`, relative to the current pointer position
Errors
  None.
See also
  MoveTo

##
49 MoveTo

Declaration
  `Procedure MoveTo (X,Y : Integer;`

  ``

Description
  MoveTo moves the pointer to the point `(X,Y)`.
Errors
  None.
See also
  MoveRel

##
50 OutText

Declaration
  `Procedure OutText (Const TextString : String);`

  ``

Description
  OutText puts `TextString` on the screen, at the current pointer position, using the current font and text settings. The current position is moved to the end of the text.
Errors
  None.
See also
  OutTextXY

##
51 OutTextXY

Declaration
  `Procedure OutTextXY (X,Y : Integer; Const TextString : String);`

  ``

Description
  OutText puts `TextString` on the screen, at position `(X,Y)`, using the current font and text settings. The current position is moved to the end of the text.
Errors
  None.
See also
  OutText

##
52 PieSlice

Declaration
  `Procedure PieSlice (X,Y : Integer;
  Start,Stop,Radius : Word);`

  ``

Description
  PieSlice draws and fills a sector of a circle with center `(X,Y)` and radius `Radius`, starting at angle `Start` and ending at angle `Stop`.
Errors
  None.
See also
  Arc, Circle, Sector

##
53 PutImage

Declaration
  `Procedure PutImage (X1,Y1 : Integer; Var Bitmap; How : word) ;`

  ``

Description
  PutImage Places the bitmap in `Bitmap` on the screen at `(X1,Y1)`. `How` determines how the bitmap will be placed on the screen. Possible values are :

  - CopyPut
  - XORPut
  - ORPut
  - AndPut
  - NotPut
Errors
  None
See also
  ImageSize,GetImage

##
54 PutPixel

Declaration
  `Procedure PutPixel (X,Y : Integer; Color : Word);`

  ``

Description
  Puts a point at `(X,Y)` using color `Color`
Errors
  None.
See also
  GetPixel

##
55 Rectangle

Declaration
  `Procedure Rectangle (X1,Y1,X2,Y2 : Integer);`

  ``

Description
  Draws a rectangle with corners at `(X1,Y1)` and `(X2,Y2)`, using the current color and style.
Errors
  None.
See also
  Bar, Bar3D

##
56 RegisterBGIDriver

Declaration
  `Function RegisterBGIDriver (Driver : Pointer) : Integer;`

  ``

Description
  Registers a user-defined BGI driver
Errors
  None.
See also
  InstallUserDriver, RegisterBGIFont

##
57 RegisterBGIFont

Declaration
  `Function RegisterBGIFont (Font : Pointer) : Integer;`

  ``

Description
  Registers a user-defined BGI driver
Errors
  None.
See also
  InstallUserFont, RegisterBGIDriver

##
58 RestoreCRTMode

Declaration
  `Procedure RestoreCRTMode ;`

  ``

Description
  Restores the screen modus which was active before the graphical modus was started.

  To get back to the graph mode you were last in, you can use `SetGraphMode(GetGraphMode)`

Errors
  None.
See also
  InitGraph

##
59 Sector

Declaration
  `Procedure Sector (X,Y : Integer;
  Start,Stop,XRadius,YRadius : Word);`

  ``

Description
  Sector draws and fills a sector of an ellipse with center `(X,Y)` and radii `XRadius` and `YRadius`, starting at angle `Start` and ending at angle `Stop`.
Errors
  None.
See also
  Arc, Circle, PieSlice

##
60 SetActivePage

Declaration
  `Procedure SetActivePage (Page : Word);`

  ``

Description
  Sets `Page` as the active page for all graphical output.
Errors
  None.
See also

##
61 SetAllPallette

Declaration
  `Procedure SetAllPallette (Var Palette);`

  ``

Description
  Sets the current palette to `Palette`. `Palette` is an untyped variable, usually pointing to a record of type `PaletteType`
Errors
  None.
See also
  GetPalette

##
62 SetAspectRatio

Declaration
  `Procedure SetAspectRatio (Xasp,Yasp : Word);`

  ``

Description
  Sets the aspect ratio of the current screen to `Xasp/Yasp`.
Errors
  None
See also
  InitGraph, GetAspectRatio

##
63 SetBkColor

Declaration
  `Procedure SetBkColor (Color : Word);`

  ``

Description
  Sets the background color to `Color`.
Errors
  None.
See also
  GetBkColor, SetColor

##
64 SetColor

Declaration
  `Procedure SetColor (Color : Word);`

  ``

Description
  Sets the foreground color to `Color`.
Errors
  None.
See also
  GetColor, SetBkColor

##
65 SetFillPattern

Declaration
  `Procedure SetFillPattern (FillPattern : FillPatternType,
  Color : Word);`

  ``

Description
  SetFillPattern sets the current fill-pattern to `FillPattern`, and the filling color to `Color` The pattern is an 8x8 raster, corresponding to the 64 bits in `FillPattern`.
Errors
  None
See also
  GetFillPattern, SetFillStyle

##
66 SetFillStyle

Declaration
  `Procedure SetFillStyle (Pattern,Color : word);`

  ``

Description
  SetFillStyle sets the filling pattern and color to one of the predefined filling patterns. `Pattern` can be one of the following predefined constants :

  - `EmptyFill` Uses backgroundcolor.
  - `SolidFill` Uses filling color
  - `LineFill` Fills with horizontal lines.
  - `ltSlashFill` Fills with lines from left-under to top-right.
  - `SlashFill` Idem as previous, thick lines.
  - `BkSlashFill` Fills with thick lines from left-Top to bottom-right.
  - `LtBkSlashFill` Idem as previous, normal lines.
  - `HatchFill` Fills with a hatch-like pattern.
  - `XHatchFill` Fills with a hatch pattern, rotated 45 degrees.
  - `InterLeaveFill`
  - `WideDotFill` Fills with dots, wide spacing.
  - `CloseDotFill` Fills with dots, narrow spacing.
  - `UserFill` Fills with a user-defined pattern.

Errors
  None.
See also
  SetFillPattern

##
67 SetGraphBufSize

Declaration
  `Procedure SetGraphBufSize (BufSize : Word);`

  ``

Description
  SetGraphBufSize is a dummy function which does not do anything; it is no longer needed.
Errors
  None.
See also

##
68 SetGraphMode

Declaration
  `Procedure SetGraphMode (Mode : Integer);`

  ``

Description
  SetGraphMode sets the graphical mode and clears the screen.
Errors
  None.
See also
  InitGraph

##
69 SetLineStyle

Declaration
  `Procedure SetLineStyle (LineStyle,Pattern,Width : Word);`

  ``

Description
  SetLineStyle sets the drawing style for lines. You can specify a `LineStyle` which is one of the following pre-defined constants:

  - `Solidln=0;` draws a solid line.
  - `Dottedln=1;` Draws a dotted line.
  - `Centerln=2;` draws a non-broken centered line.
  - `Dashedln=3;` draws a dashed line.
  - `UserBitln=4;` Draws a User-defined bit pattern.
  If `UserBitln` is specified then `Pattern` contains the bit pattern. In all another cases, `Pattern` is ignored. The parameter `Width` indicates how thick the line should be. You can specify one of the following pre-defined constants:

  - `NormWidth=1`
  - `ThickWidth=3`

Errors
  None.
See also
  GetLineSettings

##
70 SetPalette

Declaration
  `Procedure SetPalette (ColorNr : Word; NewColor : ShortInt);`

  ``

Description
  SetPalette changes the `ColorNr`-th entry in the palette to `NewColor`
Errors
  None.
See also
  SetAllPallette,SetRGBPalette

##
71 SetRGBPalette

Declaration
  `Procedure SetRGBPalette (ColorNr,Red,Green,Blue : Integer);`

  ``

Description
  SetRGBPalette sets the `ColorNr`-th entry in the palette to the color with RGB-values `Red, Green Blue`.
Errors
  None.
See also
  SetAllPallette, SetPalette

##
72 SetTextJustify

Declaration
  `Procedure SetTextJustify (Horizontal,Vertical : Word);`

  ``

Description
  SetTextJustify controls the placement of new text, relative to the (graphical) cursor position. `Horizontal` controls horizontal placement, and can be one of the following pre-defined constants:

  - `LeftText=0;` Text is set left of the pointer.
  - `CenterText=1;` Text is set centered horizontally on the pointer.
  - `RightText=2;` Text is set to the right of the pointer.
  `Vertical` controls the vertical placement of the text, relative to the (graphical) cursor position. Its value can be one of the following pre-defined constants :

  - `BottomText=0;` Text is placed under the pointer.
  - `CenterText=1;` Text is placed centered vertically on the pointer.
  - `TopText=2;`Text is placed above the pointer.

Errors
  None.
See also
  OutText, OutTextXY

##
73 SetTextStyle

Declaration
  `Procedure SetTextStyle (Font,Direction,Magnitude : Word);`

  ``

Description
  SetTextStyle controls the style of text to be put on the screen. pre-defined constants for `Font` are:

  - `DefaultFont=0;`
  - `TriplexFont=2;`
  - `SmallFont=2;`
  - `SansSerifFont=3;`
  - `GothicFont=4;`
  Pre-defined constants for `Direction` are :

  - `HorizDir=0;`
  - `VertDir=1;`
Errors
  None.
See also
  GetTextSettings

##
74 SetUserCharSize

Declaration
  `Procedure SetUserCharSize (Xasp1,Xasp2,Yasp1,Yasp2 : Word);`

  ``

Description
  Sets the width and height of vector-fonts. The horizontal size is given by `Xasp1/Xasp2`, and the vertical size by `Yasp1/Yasp2`.
Errors
  None.
See also
  SetTextStyle

##
75 SetViewPort

Declaration
  `Procedure SetViewPort (X1,Y1,X2,Y2 : Integer; Clip : Boolean);`

  ``

Description
  Sets the current graphical viewport (window) to the rectangle defined by the top-left corner `(X1,Y1)` and the bottom-right corner `(X2,Y2)`. If `Clip` is true, anything drawn outside the viewport (window) will be clipped (i.e. not drawn). Coordinates specified after this call are relative to the top-left corner of the viewport.
Errors
  None.
See also
  GetViewSettings

##
76 SetVisualPage

Declaration
  `Procedure SetVisualPage (Page : Word);`

  ``

Description
  SetVisualPage sets the video page to page number `Page`.
Errors
  None
See also
  SetActivePage

##
77 SetWriteMode

Declaration
  `Procedure SetWriteMode (Mode : Integer);`

  ``

Description
  SetWriteMode controls the drawing of lines on the screen. It controls the binary operation used when drawing lines on the screen. `Mode` can be one of the following pre-defined constants:

  - CopyPut=0;
  - XORPut=1;
Errors
  None.
See also

##
78 TextHeight

Declaration
  `Function TextHeight (S : String) : Word;`

  ``

Description
  TextHeight returns the height (in pixels) of the string `S` in the current font and text-size.

Errors
  None.
See also
  TextWidth

##
79 TextWidth

Declaration
  `Function TextWidth (S : String) : Word;`

  ``

Description
  TextHeight returns the width (in pixels) of the string `S` in the current font and text-size.
Errors
  None.
See also
  TextHeight

# 5 Target specific issues

In what follows we describe some things that are different on the various platforms:

## 1 DOS

## 2 WINDOWS

## 3 LINUX