Sem 4‎ > ‎CG LAB‎ > ‎

0 Stuff to Know

posted Dec 18, 2011, 3:33 AM by Neil Mathew   [ updated Dec 21, 2011, 9:51 AM ]

initgraph()


InitGraph:

Initializes the graphics system.

Declaration:
void far initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver);

Remarks: To start the graphics system, you must first call initgraph.

initgraph initializes the graphics system by loading a graphics driver from disk (or validating a registered driver) then putting the system into graphics mode.

initgraph also resets all graphics settings (color, palette, current position, viewport, etc.) to their defaults, then resets graphresult to 0.
Arguments:

*graphdriver: 

Integer that specifies the graphics driver to be used. You can give graphdriver a value using a constant of the graphics drivers enumeration type.

*graphmode :

 Integer that specifies the initial graphics mode (unless *graphdriver = DETECT). If *graphdriver = DETECT, initgraph sets *graphmode to the highest resolution available for the detected driver. You can give *graphmode a value using a constant of the graphics_modes enumeration type.

pathtodriver : 

Specifies the directory path where initgraph looks for graphics drivers (*.BGI) first.  If they're not there, initgraph looks in the current directory.  If pathtodriver is null, the driver files must be in the current directory.  This is also the path settextstyle searches for the stroked character font files (*.CHR).

 



Colors

Color Value
BLACK 0
BLUE 1
GREEN 2
CYAN 3
RED 4
MAGENTA 5
BROWN 6
LIGHTGRAY 7
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15

Declaration:
  •  void far setfillstyle(int pattern, int color);
  • void far setcolor(int color);
  • void far setbkcolor(int color);

Remarks:

  • setfillstyle sets the current fill pattern and fill color.
  • setcolor sets the current drawing color to color, 
      • which can range from 0 to getmaxcolor.
  • setbkcolor sets the background to the color specified by color.


        The parameter pattern in setfillstyle is as follows:

 Names Value Means  Fill With...
EMPTY_FILL 0 Background color
SOLID_FILL 1 Solid fill
LINE_FILL 2 ---
LTSLASH_FILL 3 ///
SLASH_FILL 4 ///, thick lines
BKSLASH_FILL 5 \\\, thick lines
LTBKSLASH_FILL 6  \\\
HATCH_FILL 7 Light hatch
XHATCH_FILL 8 Heavy crosshatch
INTERLEAVE_FILL 9 Interleaving lines
WIDE_DOT_FILL 10 Widely spaced dots
CLOSE_DOT_FILL 11 Closely spaced dots
USER_FILL 12 User-defined fill pattern

    setfillstyle function sets the current fill pattern and fill color.

floodfill

void floodfill(int x, int y, int border);

floodfill function is used to fill an enclosed area. 

(x, y) is any point on the screen if (x,y) lies inside the area
 then inside will be filled otherwise outside will be filled.

Border specifies the color of boundary of area. 

To change fill pattern and fill color use setfillstyle.


Text

(setcolor() works for the below)

outtext()
void outtext(char *textstring);
outtextxy()
void outtextxy(int x, int y, char *textstring);

settextstyle()
void settextstyle(int font, int direction, int charsize);
A call to settextstyle affects all text output by outtext and outtextxy.
FONT:

Name Value    Description
DEFAULT_FONT 0 8x8 bit-mapped font
TRIPLEX_FONT 1 Stroked triplex font
SMALL_FONT 2 Stroked small font
SANS_SERIF_FONT 3 Stroked sans-serif font
GOTHIC_FONT 4 Stroked gothic font
SCRIPT_FONT 5 Stroked script font
SIMPLEX_FONT 6 Stroked triplex script font
TRIPLEX_SCR_FONT    7 Stroked triplex script font
COMPLEX_FONT 8 Stroked complex font
EUROPEAN_FONT 9 Stroked European font
BOLD_FONT 10 Stroked bold font

DIRECTION:

The direction can be changed to VERT_DIR from the default HORIZ_DIR

SIZE:

Font size acts like a magnifying factor. Default or 1 is 8x8 bit character. 

Using 2, doubles it, making it 16x16.

EXAMPLE:

settextstyle(5, HORIZ_DIR, 1);




Circles, arc, pieslice


Declaration:
  •  void far arc(int x, int y, int stangle, int endangle, int radius);
  •  void far circle(int x, int y, int radius);
  •  void far pieslice(int x, int y, int stangle, int endangle, int radius);

Remarks:

  • arc draws a circular arc in the current drawing color.
  • circle draws a circle in the current drawing color.
  • pieslice draws a pie slice in the current drawing color, then fills it using
    the current fill pattern and fill color.

Arguments:

  • (x,y): Center point of arc, circlew, or pie slice
  • stangle: Start angle in degrees
  • endangle: End angle in degrees
  • radius: Radius of arc, circle, and pieslice