It(==graphics.h==) is called ==BGI==(Borland Graphics Interface).It is an olden 32-bit real-mode DOS library, included with ==Borland's Turbo C and C++ products==. And basically graphics.h, conio.h can be inferred as windows headerfiles. So It'll ==run only one windows==.
The last Borland's C++ IDE for DOS is Borland C++ 3.1 (1992). The last C++ environment which supports BGI is Borland C++ 5.02 (1997), which works under Windows but can compile DOS programs. BGI was accessible in C/C++ with graphics.lib / graphics.h, and in Pascal via the graph unit.
BGI was less powerful than modern graphics libraries such as SDL or OpenGL, since it was designed for 2D presentation graphics instead of event-based 3D applications. However, it has been considered simpler to code. BGI and Turbo C++, although obsolete, are still widely used in education in India.
This repo is for practising C++ graphics (turbo c++) using
graphics.hfile.
- How to run BGI in dev c++ IDE
- How to run BGI in CodeBlocks IDE
- How to run BGI in VS Code
- Other web resources
- Small guide on c++ graphics
-
Download
Dev-cpp 5.11 TDM-GCC 4.9.2from sourceForge. -
Install
Dev-cpp. -
Download Graphics Files For Dev C++ from GDrive - without consoleAppGraphics template or studyReadEducate or GDrive for studyReadEducate and unzip.
-
Copy the following files to appropriate Dev-cpp folders
- 🟢 This step is optional only: copy
6-ConsoleAppGraphics.templateandConsoleApp_cpp_graph.txtfromGraphics in Dev C++toC:\Program Files (x86)\Dev-Cpp\Templates\. - ✔️ Copy
graphics.handwinbgim.hfromGraphics in Dev C++toC:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\. - ✔️ Copy
libbgi.afromGraphics in Dev C++toC:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\.
- 🟢 This step is optional only: copy
-
Choose 32-bit GCC compiler:
-
Choose compiler & add linkers as shown below:
-
⚠️ Click onToolsand chooseCompiler and Options -
Other Linker Options required for the setup
graphics.h
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
-
- File -> New -> Project
- then select
Console Graphics Applicationunderbasictab - then choose your desired name & hit
ok. - prompt will open file explorer, save the
.devfile where you want to save your project. - --- OR ---
- Click on
Fileicon -> source file orctr + N
-
To execute:
- Click on
executein the main ribbon, then chooseCompile & Runor pressF11.
- Click on
-
Video references:
-
Test program
#include<graphics.h>
main(){
initwindow(800, 800);
// creating line
// line(200, 210, 400, 410);
// creating circle (x, y, radius)
circle(300, 300, 20);
getch();
}-
Download
codeblocks-20.03mingw-setup(64 bit) from here. -
Just install
codeblocks setup. -
As we've 64-bit version, we've to set up 32-bit GCC. Because our graphics library(
graphics.h) is compatible with 32-bit. -
Before moving on, to find the gcc version, Please do the below steps: -> This step is optional
- 🟢 Cpp code to find the
gccversion
#include<stdlib.h> // c++ program to know the gcc version int main() { system("gcc -v"); return 0; }
- 🟢 Cpp code to find the
-
Download
32-bit compilerfrom here and install it. -
Download Graphics Files from here and unzip it.
-
Copy the following files form downloaded zip folder to the appropriate
TDM-GCC-32folders- ✔️ Copy
graphics.handwinbgim.hfromdownloaded Graphics foldertoC:\TDM-GCC-32\include\. - ✔️ Copy
libbgi.afromdownloaded Graphics foldertoC:\TDM-GCC-32\lib.
- ✔️ Copy
-
Add the appropriate linkers
-
🟢 The click on
settingsfrom the main ribbon, then chooseCompiler... -
🟢 Then click on
Toolchain executablesin the tab from the dialog and choose the new 32-bit gcc compiler as shown below:

-
🟢 Then click on
Linker settingsand add the following linker tags underOther linker optionsand then hitsaveas shown below:

-
-
Create a new project
- Click on File -> New -> Project -> Console Application, then click on
Go - Click on
Next, then chooseC++and go on with the prompt. - After writing a program, click on
compile and run
- Click on File -> New -> Project -> Console Application, then click on
-
Test program
#include <graphics.h>
int main(){
int gd=DETECT, gm;
initgraph(&gd, &gm, (char*)"");
circle(320, 240, 200);
getch();
closegraph();
return 0;
}-
Changing indentation: settings -> Editor
-
Video references:
-
Download VS Code and Install it
-
Download
32-bit compilerfrom here and install it. -
Download Graphics Files from here and unzip it.
-
Copy the following files form downloaded zip folder to the appropriate
TDM-GCC-32folders- ✔️ Copy
graphics.handwinbgim.hfromdownloaded Graphics foldertoC:\TDM-GCC-32\include\. - ✔️ Copy
libbgi.afromdownloaded Graphics foldertoC:\TDM-GCC-32\lib.
- ✔️ Copy
-
Go to extensions search bar,
- search for c++, and choose the extension from
Microsoftand install it. - Install code runner from extension
- search for c++, and choose the extension from
-
Click on view -> command palette or
Ctr + Shift + Pand typec++:uias shown below:

-
Add the below configurations as shown in screenshot:
- Select a configuration set to edit:
win32 - Compiler path:
C:/TDM-GCC-32/bin/g++.exe - Compiler arguments:
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
- Select a configuration set to edit:
-
Build the program: Click on Terminal -> Run Build Task or
Ctr + Shift + B

- You'll see the following success info.
* Executing task: C/C++: g++.exe build active file Starting build... C:/TDM-GCC-32/bin/g++.exe -fdiagnostics-color=always -g D:\AR_prog\rnd\c-cpp\cppGraphicsExamples\main.cpp -o D:\AR_prog\rnd\c-cpp\cppGraphicsExamples\main.exe -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 Build finished successfully. * Terminal will be reused by tasks, press any key to close it.
- Then run the following command (
./filename)
./main
-
Video reference:
-
Programming example:
#include <graphics.h>
int main(int argc, char const *argv[])
{
int gd = DETECT, gm;
initgraph(&gd, &gm, (char *)"");
circle(320, 240, 200);
getch();
closegraph();
return 0;
}- Guide to setup 'graphics.h' - github
- Guide to setup BGI - github
- Practical examples to BGI
- Graphics (graphics.h) - C Programming tutorial site
- Graphics in C Language - My C Plus
- The below content was taken from here
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void main(void) {
int gdriver = DETECT, gmode;
int x1 = 200, y1 = 200;
int x2 = 300, y2 = 300;
clrscr();
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
line(x1, y1, x2, y2);
getch();
closegraph();
}-
Include
graphics.hheader file. -
Initialize the graphics drivers on the computer using
initgraph.void initgraph(int *graphicsDriver, int *graphicsMode, char *driverDirectoryPath);
- graphicsDriver : It is a pointer to an integer specifying the graphics driver to be used. It tells the compiler that what graphics driver to use or to automatically detect the drive. In all our programs we will use
DETECTmacro of graphics.h library that instruct compiler for auto detection of graphics driver. - graphicsMode : It is a pointer to an integer that specifies the graphics mode to be used. If
*gdriveris set toDETECT, theninitgraphsets*gmodeto the highest resolution available for the detected driver. - driverDirectoryPath : It specifies the directory path where graphics driver files (
BGI files) are located. If directory path is not provided, then it will search for driver files in current working directory directory. In all our sample graphics programs, you have to change path of BGI directory accordingly where you Turbo C++ compiler is installed.
- graphicsDriver : It is a pointer to an integer specifying the graphics driver to be used. It tells the compiler that what graphics driver to use or to automatically detect the drive. In all our programs we will use
-
At the end of our graphics program, we have to unloads the graphics drivers and sets the screen back to text mode by calling closegraph function.
-
Colors in C Graphics Programming
COLOR MACRO INTEGER 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




