Thread: BGI Error: Graphics not initialized

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    1

    BGI Error: Graphics not initialized

    I am facing problem of

    BGI Error: Graphics not initialized (use 'initgraph')

    In fact i have provided correct invocation of initgraph method

    initgraph(....,"C:\\Turboc3\\bgi");

    i found that there is no file like bgi in Turboc3..

    please help me how can i initialize graphics.

    Help me.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by rahul_shilps View Post
    I am facing problem of

    BGI Error: Graphics not initialized (use 'initgraph')

    In fact i have provided correct invocation of initgraph method

    initgraph(....,"C:\\Turboc3\\bgi");

    i found that there is no file like bgi in Turboc3..

    please help me how can i initialize graphics.

    Help me.
    In Turbo C/C++, the graphics driver files are in the C:\TC\BGI directory, by default.

    This is how you use it, and an example program (which just draws a white line on a black graphics screen).


    initgraph Initializes the graphics system.


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

    Prototype in:
    graphics.h

    Remarks:
    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.
    See UTIL.DOC (included with your distribution disks) for more information on
    BGIOBJ.

    þ pathtodriver specifies the directory path
    where initgraph looks for graphics
    drivers.

    initgraph first looks in the path
    specified in pathtodriver, then (if
    they're 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,
    defined in graphics.h and listed in the
    table below.

    graphics_drivers ³
    constant ³ Numeric value
    ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍØÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ ÍÍÍÍÍÍÍ
    DETECT ³ 0 (requests autodetection)
    CGA ³ 1
    MCGA ³ 2
    EGA ³ 3
    EGA64 ³ 4
    EGAMONO ³ 5
    IBM8514 ³ 6
    HERCMONO ³ 7
    ATT400 ³ 8
    VGA ³ 9
    PC3270 ³ 10

    þ *graphmode is an integer that specifies
    the initial graphics mode (unless
    *graphdriver equals DETECT. In this
    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, defined in graphics.h
    and listed in the table above.

    graphdriver and graphmode must be set to valid values from or you'll get
    unpredictable results.

    The exception is graphdriver = DETECT.

    In the following table, the 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.

    These palettes are described in greater detail in Chapter video, "videott,"
    in book3 (in the section titled "Color control," toward the end of the
    chapter) and summarized in Table palette.

    Palette ³ Color assigned to pixel value
    number ³ 1 2 3
    ÍÍÍÍÍÍÍÍÍÍØÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ ÍÍÍÍÍÍÍ
    0 ³ LIGHTGREEN ³ LIGHTRED ³ YELLOW
    1 ³ LIGHTCYAN ³ LIGHTMAGENTA ³ WHITE
    2 ³ GREEN ³ RED ³ BROWN
    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³ ³ ³ Column ³ ³
    driver ³ graphics_modes ³ Value ³ x row ³ Palette ³ Pages
    ÍÍÍÍÍÍÍÍÍØÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍØÍÍÍÍÍÍÍØÍÍÍÍÍÍÍÍÍÍÍØÍÍÍ ÍÍÍÍÍÍÍÍÍØÍÍÍÍÍÍÍÍÍÍ
    CGA ³ CGAC0 ³ 0 ³ 320 x 200³ C0 ³ 1
    ³ CGAC1 ³ 1 ³ 320 x 200³ C1 ³ 1
    ³ CGAC2 ³ 2 ³ 320 x 200³ C2 ³ 1
    ³ CGAC3 ³ 3 ³ 320 x 200³ C3 ³ 1
    ³ CGAHI ³ 4 ³ 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 ³ EGALO ³ 0 ³ 640 x 200³ 16 color³ 4
    ³ EGAHI ³ 1 ³ 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*
    ³ EGAMONOHI ³ 3 ³ 640 x 350³ 2 color³ 2**
    HERC ³ HERCMONOHI ³ 0 ³ 720 x 348³ 2 color³ 2
    ATT400 ³ ATT400C0 ³ 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 ³ VGALO ³ 0 ³ 640 x 200³ 16 color³ 2
    ³ VGAMED ³ 1 ³ 640 x 350³ 16 color³ 2
    ³ VGAHI ³ 2 ³ 640 x 480³ 16 color³ 1
    PC3270 ³ PC3270HI ³ 0 ³ 720 x 350³ 2 color³ 1
    IBM8514 ³ IBM8514HI ³ 1 ³ 1024 x 760³ 256 color³
    ³ IBM8514LO ³ 0 ³ 640 x 480³ 256 color³

    * 64K on EGAMONO card
    ** 256K on EGAMONO card

    Return Value:
    initgraph always sets the internal error code.

    On success, it sets the code to 0. If an error occurred, *graphdriver is set
    to -2, -3, -4, or -5, and graphresult returns the same value as listed in
    the following table:

    grNotDetected ³ -2 ³ Cannot detect a graphics card
    grFileNotFound ³ -3 ³ Cannot find driver file
    grInvalidDriver ³ -4 ³ Invalid driver
    grNoLoadMem ³ -5 ³ Insufficient memory to load driver

    Portability:
    This function is unique to Turbo C++.

    It works only with IBM PCs and compatibles equipped with supported graphics
    display adapters.

    See Also:
    closegraph graphresult
    detectgraph installuserdriver
    getdefaultpalette registerbgidriver
    getdrivername registerbgifont
    getgraphmode restorecrtmode
    getmoderange setgraphbufsize
    graphdefaults setgraphmode
    _graphgetmem

    Example:
    Code:
     #include <graphics.h>
     #include <stdlib.h>
     #include <stdio.h>
     #include <conio.h>
    
     int main(void)
     {
        /* request auto detection */
        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;
     }
    This runs on two of my graphics cards, in Windows XP. The aspect ratio may distort things, depending on your monitor' and graphics cards settings.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BGI Error:
    By it4_saravana in forum C Programming
    Replies: 4
    Last Post: 04-12-2008, 02:48 AM
  2. How tell if pointer has been initialized?
    By 6tr6tr in forum C++ Programming
    Replies: 6
    Last Post: 04-11-2008, 04:50 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. BGI and text cursor
    By Somnambulist in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2004, 07:54 PM
  5. BGI Error: Graphics not initialized (use 'initgraph');
    By Jasin14 in forum C Programming
    Replies: 4
    Last Post: 10-02-2002, 12:58 PM