• Have Any Question?
  • contact@eitworld.com

Let’s Start





    • Graphics programming is a very crucial feature of the C language.
    • Graphics programming make the C language able to produce images, create projects, generate animation and develop games etc.
    • Various functions are present in the “Graphics.h ” header file in the C language library which enables the user to produce images like circle, rectangle, moving car , faces etc..

 

Demo Program


#include<Graphics.h>

#include<iostream.h>

#include<conio.h>

void main()

{

int gd=DETECT, gm;

initgraph(&gd, &gm, ” “);

closegraph( );

restorecrtmode( );

}

Before understanding the main aim of this program we have to know about all the keywords and statement present in the above program:

Graphics.h Header file

 

    • If user wants to produce any graphical image on the output screen of C compiler then he has to firstly introduce the “Graphics.h” header file.
    • The header file “Graphics.h” contains all the definitions and explanations of the graphics function that user needs in the graphics programming.

Graphics Driver

 

    • To understand the concept of graphics driver you have to understand the concept of device drivers.
    • Device Drivers are some small programs which directly communicate with the hardware.
    • You cannot communicate with any machine directly here are some small programs which are needed to communicate with the machines. These programs are known as Device Drivers.
    • Graphics Drivers are the small parts of the Device drivers and are applicable on the graphics mode.
    • In the given program there is an integer type variable gd which represents the graphics driver. You can also choose any other variable name rather than gd for graphics drivers.
    • Initgraph() function automatically selects the graphics driver. The first argument of initgraph() method represents the address of graphics driver.

Graphics Mode

 

    • User has to switch over the graphics mode just before producing the graphical images.
    • The number of graphics mode present in the user’s computer system depends upon the adapter and monitor which are present in the computer system of user.
    • Every graphics mode has a specific number. Out of all available modes in the computer system one would like to switch over the graphics mode which offers the best resolution.
    • To switch over the graphics mode that offers best resolution one need to call the function initgraph().This function detect the best resolution graphics mode and puts the number corresponding to that mode in the variable gm.
    • In the given program we declared an integer type variable gm which represents the graphics mode. You can also choose any other variable name rather than gm for graphics mode.
    • In the above program initgraph() method includes address of gm or graphics mode as its second argument.

Initgraph() Method

 

    • Initgraph() method is used to decide an appropriate graphics driver , initialize the graphics mode such that to set the maximum screen resolution and to select the appropriate BGI file path.
    • In the above program in initgraph() method there are three arguments. We have already discussed about the first two arguments that are address of graphics driver (&gd) and address of graphics mode (&gm).
    • The third argument of the initgraph() method is used to select the path where your BGI files are present. These BGI files are the extension of the graphics drivers.

Closegraph() method

 

    • Closegraph() method is used to close (or used to exit from) the graphics mode.

 

restorecrtmode( ) method

 

  • restorecrtmode restores the original graphics mode detected by initgraph() method.
  • This function can be used in conjunction with setgraphmode to switch back and forth between text and graphics modes. Textmode should not be used for this purpose, use it only when the screen is in text mode, to change to a different text mode.
  • Now come to the aim of our program,this program initializes graphics mode and then closes it after a key is pressed. Our program has been created on the VGA adapter then we need the EGAVGA.
  • BGI file as our graphics driver.
  • “In our program we initialized the variable gd with the keyword DETECT ,it is used to ask the initgraph() method that which BGI file is needed. This file is then loaded into memory. If we do not initialize the variable gd with DETECT then we have to set up the values of gd and gm but for making programsimple users generally use DETECT macro.”


Real Time Web Analytics