User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:graphics.h:initgraph

initgraph

Syntax of initgraph

#include <graphics.h>
void initgraph(int *graphdriver, int *graphmode, char *pathtodriver);
 

Description of initgraph

initgraph initializes the graphics system by loading a graphics driver
from disk (or validating a registered driver), and putting the system
into graphics mode.
To start the graphics system, first call the initgraph function.
initgraph loads the graphics driver and puts the system into graphics
mode. You can tell initgraph to use a particular graphics driver and
mode, or to autodetect the attached video adapter at run time and pick
the corresponding driver.
If you tell initgraph to autodetect, it calls detectgraph to select a
graphics driver and mode. initgraph also resets all graphics settings to
their defaults (current position, palette, color, viewport, and so on)
and resets graphresult to 0.
Normally, initgraph loads a graphics driver by allocating memory for the
driver (through _graphgetmem), then loading the appropriate .BGI file
from disk. As an alternative to this dynamic loading scheme, you can link
a graphics driver file (or several of them) directly into your executable
program file.
pathtodriver specifies the directory path where initgraph looks for
graphics drivers. initgraph first looks in the path specified in
pathtodriver, then (if they are not there) in the current directory.
Accordingly, if pathtodriver is null, the driver files (*.BGI) must be in
the current directory. This is also the path settextstyle searches for
the stroked character font files (*.CHR).
*graphdriver is an integer that specifies the graphics driver to be used.
You can give it a value using a constant of the graphics_drivers
enumeration type, which is defined in graphics.h and listed below.
graphics_drivers constant  Numeric value
DETECT0 (requests autodetect)
CGA   1
MCGA  2
EGA   3
EGA64 4
EGAMONO     5
IBM8514     6
HERCMONO    7
ATT4008
VGA   9
PC327010
*graphmode is an integer that specifies the initial graphics mode (unless
*graphdriver equals DETECT; in which case, *graphmode is set by initgraph
to the highest resolution available for the detected driver). You can
give *graphmode a value using a constant of the graphics_modes
enumeration type, which is defined in graphics.h and listed below.
graphdriver and graphmode must be set to valid values from the following
tables, or you will get unpredictable results. The exception is
graphdriver = DETECT.
Palette listings C0, C1, C2, and C3 refer to the four predefined four-
color palettes available on CGA (and compatible) systems. You can select
the background color (entry #0) in each of these palettes, but the other
colors are fixed.
Palette Number  Three Colors
0     LIGHTGREEN LIGHTRED YELLOW
1     LIGHTCYAN    LIGHTMAGENTA WHITE
2     GREEN  REDBROWN
3     CYAN   MAGENTA  LIGHTGRAY
After a call to initgraph, *graphdriver is set to the current graphics
driver, and *graphmode is set to the current graphics mode.
Graphics        Columns   
Drivergraphics_mode  Value   x Rows   Palette  Pages
CGA   CGAC00  320 x 200  C0   1
CGAC11  320 x 200  C1   1
CGAC22  320 x 200  C2   1
CGAC33  320 x 200  C3   1
CGAHI4  640 x 200  2 color    1
 
MCGA  MCGAC0     0  320 x 200  C0   1
 
MCGAC1     1  320 x 200  C1   1
MCGAC2     2  320 x 200  C2   1
MCGAC3     3  320 x 200  C3   1
MCGAMED    4  640 x 200  2 color    1
MCGAHI     5  640 x 480  2 color    1
 
EGA   EGALO0  640 x 200  16 color   4
 
EGAHI1  640 x 350  16 color   2
 
EGA64 EGA64LO    0  640 x 200  16 color   1
 
EGA64HI    1  640 x 350  4 color    1
 
EGA-MONO    EGAMONOHI  3  640 x 350  2 color    1 w/64K
EGAMONOHI  3  640 x 350  2 color    2 w/256K
 
HERC  HERCMONOHI 0  720 x 348  2 color    2
 
ATT400ATT400C0   0  320 x 200  C0   1
ATT400C1   1  320 x 200  C1   1
ATT400C2   2  320 x 200  C2   1
ATT400C3   3  320 x 200  C3   1
ATT400MED  4  640 x 200  2 color    1
ATT400HI   5  640 x 400  2 color    1
 
VGA   VGALO0  640 x 200  16 color   2
VGAMED     1  640 x 350  16 color   2
VGAHI2  640 x 480  16 color   1
 
PC3270PC3270HI   0  720 x 350  2 color    1
IBM8514     IBM8514HI  0  640 x 480  256 color  ?
IBM8514LO  0  1024 x 768 256 color  ?

Example of initgraph

/* initgraph example */
 
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
 
int main(void)
{
   /* request autodetection */
   int gdriver = DETECT, gmode, errorcode;
 
   /* initialize graphics mode */
   initgraph(&gdriver, &gmode, "");
 
   /* read result of initialization */
   errorcode = graphresult();
 
   if (errorcode != grOk)    /* an error occurred */
   {
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
 
getch();
exit(1);   /* return with error code */
   }
 
   /* draw a line */
   line(0, 0, getmaxx(), getmaxy());
 
   /* clean up */
   getch();
   closegraph();
   return 0;
}

See also

output of initgraph example

  no output of example at the moment
  do not hesitate and add it...  
advertising
c/graphics.h/initgraph.txt · Last modified: 2015/05/06 23:06 (external edit)

Impressum Datenschutz