How to setup graphics.h in Dev C++
What is graphics.h file?
The graphic.h file is a header file that contains declarations of functions and variables for graphics programming in C or C++. It is part of the Borland Graphics Interface (BGI) library, which was originally developed for Turbo C and Turbo C++ compilers.
The graphics.h file provides access to simple graphics functions, such as drawing lines, circles, rectangles, polygons, and text on a graphical window. It also supports keyboard and mouse input, color manipulation, and loading and displaying images. To use the graphics.h file, you need to include it in your program with #include<graphics.h>
and link the appropriate graphics driver and mode with the initgraph
function.
What is initgraph function?
The initgraph function is a graphics function in C or C++ that initializes the graphics system by loading a graphics driver and putting the system into graphics mode. It can be used to create graphical applications, such as drawing shapes, displaying images, and animating objects. The initgraph function has the following syntax:
Copied!#include<graphics.h> void initgraph(int *graphdriver, int *graphmode, char *pathtodriver);
The parameters of the initgraph function are :
Graphdriver : 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. For example, DETECT means to autodetect the graphics mode, and VGA means to use the VGA drive r.
Graphmode : an integer that specifies the initial graphics mode. You can give it a value using a constant of the graphics_modes enumeration type, which is also defined in graphics.h. For example, VGALO means to use the low-resolution VGA mode, and VGAHI means to use the high-resolution VGA mode.
Pathtodriver : a string that specifies the directory path where the graphics driver files are located. If it is NULL, the current directory is used.
Here are the steps for how to add graphics.h and libbgi.a file in Dev C++:
Step 1 :- Download the latest version of Dev C++ from here and install it on your computer.
follow the given step to add header file in your pc if you Stuck any where You can take help of video

Step 2 :- Download the graphics library files from here and extract them. You will get three files: graphics.h, winbgim.h, and libbgi.a.

Step 3 :- Copy graphics.h and winbgim.h to the include folder of Dev C++. The default location is C:\Program Files (x86)\Dev-Cpp\MinGW64\include.

Step 4 :- Copy libbgi.a to the lib folder of Dev C++. The default location is C:\Program Files (x86)\Dev-Cpp\MinGW64\lib.

Step 5 :- Open Dev C++ and go to Tools -> Compiler Options. Select the Parameters tab and check the box for “Add the following commands when calling the linker”.
Step 6 :- In the linker text area, paste the following commands:
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32. These are the required linkers for graphics.h file.
Step 7 :- Click OK to save the changes and close the window.
Step 8 :- To test if graphics.h file is working, you can create a new project and write a simple program that uses graphics functions. For example:
Copied!#include<graphics.h> int main() { int gd = DETECT, gm; initgraph(&gd, &gm,(char*)"C:\\TC\\BGI"); circle(200, 200, 100); getch(); closegraph(); return 0; }
Step 9 :- Compile and run the program. You should see a graphical window with a circle drawn on it.

FAQs (Frequently Asked Questions) for Adding Graphics.h in Dev C++:
- What is graphics.h file in C or C++ programming?
- The graphics.h file is a header file containing declarations of functions and variables for graphics programming, providing access to functions for drawing shapes, handling input, and manipulating colors.
- Which library is graphics.h part of, and for which compilers was it originally developed?
- graphics.h is part of the Borland Graphics Interface (BGI) library, initially developed for Turbo C and Turbo C++ compilers.
- What functions does the graphics.h file offer for graphics programming?
- It provides functions for drawing lines, circles, rectangles, polygons, text, as well as supporting keyboard and mouse input, color manipulation, and image loading and display.
- What is the purpose of the initgraph function in graphics programming?
- The initgraph function initializes the graphics system by loading a graphics driver and putting the system into graphics mode, allowing for the creation of graphical applications.
- Can you explain the syntax of the initgraph function?
- The syntax is
void initgraph(int *graphdriver, int *graphmode, char *pathtodriver);
. It takes parameters such as graphdriver (graphics driver), graphmode (initial graphics mode), and pathtodriver (directory path for graphics driver files).
- What are the parameters of the initgraph function and how are they used?
- Parameters include Graphdriver (integer specifying the graphics driver), Graphmode (integer specifying the initial graphics mode), and Pathtodriver (string specifying the directory path for graphics driver files).
- How do you add graphics.h to Dev C++?
- Download graphics.h, winbgim.h, and libbgi.a files, then copy graphics.h and winbgim.h to the Dev C++ include folder and libbgi.a to the lib folder. Adjust compiler options in Dev C++ and add required linker commands.
- What are the steps for adding graphics.h and libbgi.a in Dev C++?
- The steps involve downloading Dev C++, graphics library files, copying files to Dev C++ folders, adjusting compiler options, and testing with a sample program.
- How do you check if graphics.h is working in Dev C++?
- Write a simple program using graphics functions (e.g., drawing a circle), compile, and run. If the window displays the expected graphical output, graphics.h is working.
- Can I refer to a video for additional guidance on adding header files in Dev C++?
- Yes, the article suggests referring to a video for more guidance if you encounter difficulties during the process of adding the header file.
Comments
Post a Comment