What is graphics.h?
graphics.h is a C/C++ header file that provides simple functions for drawing shapes, lines, circles, text, and colors on screen. It was originally part of the Borland Graphics Interface (BGI) included with Turbo C/C++ in the late 1980s and early 1990s.
Despite being over three decades old, graphics.h is still widely used in computer graphics lab courses at universities across India and other countries. Functions like initgraph(), circle(), line(), rectangle(), and closegraph() are standard in these courses.
The problem? graphics.h was designed for 16-bit DOS. It does not work natively on modern 64-bit operating systems like Windows 10/11, macOS, or Linux. That is why setting it up can be so frustrating — and why students often spend more time configuring their environment than actually learning graphics programming.
Below are five ways to run graphics.h programs, ordered from easiest to most complex.
Method 1: Online Compiler (Zero Setup)
The graphics.h Online Compiler lets you write, compile, and run graphics.h programs directly in your web browser. There is nothing to download or install. It works on Windows, macOS, Linux, Chromebooks, and even phones.
How it works
The online compiler runs a full Turbo C 3.0 environment inside a WebAssembly-based DOS emulator (JS-DOS). When you click "Compile & Run", your code is compiled by the real Turbo C compiler (TCC.EXE) inside the emulator, and the graphics output is rendered on a standard HTML5 canvas.
Because it uses the actual Turbo C compiler under the hood, every standard graphics.h function works natively — including initgraph(), circle(), line(), setcolor(), floodfill(), delay(), and all 40+ functions documented in the function reference.
Steps
- Open graphicsh.online/compiler in any modern browser.
- Write or paste your C/C++ graphics.h program in the editor.
- Click Compile & Run.
- View the graphics output in the integrated DOS canvas.
Features
- Modern code editor with syntax highlighting and autocomplete.
- Built-in code templates for common programs.
- Optional Google Sign-In for cloud file saving and sync.
- Works on any operating system — Windows, macOS, Linux, ChromeOS.
- No installation, no downloads, no configuration. Just open and code.
✓ Pros
- Zero setup — works instantly
- Cross-platform (any browser)
- Uses real Turbo C compiler
- All graphics.h functions supported
- Cloud save with Google Sign-In
✗ Cons
- Requires internet connection
- Emulation is slower than native
Method 2: VS Code Extension
If you prefer working locally with a modern code editor, the graphics.h Compiler VS Code extension gives you one-click compile and run inside Visual Studio Code — no DOSBox, no linker flags, no path configuration.
Steps
- Open Visual Studio Code.
- Go to the Extensions panel (
Ctrl+Shift+X). - Search for "graphics.h compiler" and install the extension by AlbatrossC.
- Open any
.cor.cppfile that uses#include <graphics.h>. - Click the Compile & Run button in the editor toolbar.
- The graphics output opens in an integrated panel inside VS Code.
✓ Pros
- Modern editor with IntelliSense
- One-click compile & run
- No manual configuration
- Works on Windows, macOS, Linux
- Syntax highlighting & autocomplete
✗ Cons
- Requires VS Code installed
- Requires internet for the extension runtime
Method 3: Turbo C++ with DOSBox
Turbo C++ is the original IDE that ships with graphics.h. Since it is a 16-bit DOS application, it cannot run natively on modern 64-bit Windows. You need DOSBox (a DOS emulator) to run it.
Steps
- Download Turbo C++ 3.0 (commonly available as a zip archive from educational sites).
- Download and install DOSBox.
- Extract the Turbo C++ folder to a location like
C:\TURBOC3. - Open DOSBox and mount the drive:
mount c c:\TURBOC3 c: cd BIN TC.EXE - Write your program in the Turbo C++ editor and press
Ctrl+F9to compile and run. - Press
Alt+F5to view the graphics output.
Known problems
- Outdated editor: The Turbo C++ editor has no syntax highlighting, no autocomplete, no tabs, and no undo history. It uses a tiny fixed-resolution window that is difficult to use on modern high-DPI screens.
- DOSBox issues: Screen resolution scaling glitches, fullscreen problems, and mouse capture issues are common.
- No modern features: No autosave, no file tree, no copy-paste from external sources.
- Path errors: The BGI path (
C:\\TURBOC3\\BGI) must be set correctly ininitgraph()or the program will crash.
✓ Pros
- Uses the original Turbo C compiler
- 100% compatibility with graphics.h
- Works offline
✗ Cons
- Extremely outdated editor
- DOSBox setup is confusing
- Resolution and scaling issues
- No modern editing features
- Only works on Windows
Method 4: Dev-C++ with WinBGIm
Dev-C++ is a free C/C++ IDE for Windows. It does not include graphics.h by default, but you can add it using the WinBGIm library — a Windows port of the Borland Graphics Interface.
Steps
- Download and install Dev-C++ (Orwell or Embarcadero edition).
- Download the WinBGIm library files:
graphics.h,winbgim.h, andlibbgi.a. - Copy
graphics.handwinbgim.hinto the Dev-C++MinGW64\includefolder. - Copy
libbgi.ainto the Dev-C++MinGW64\libfolder. - Create a new project in Dev-C++ (File → New → Project).
- Go to Project → Project Options → Parameters → Linker and add:
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 - Write your program, save it as
.cpp, and compile withF11.
Important notes
- Always create a project, not a single file. Linker settings are project-level.
- Use a 32-bit compiler (TDM-GCC 32-bit) — the WinBGIm library may not work with 64-bit compilers.
- Use
initwindow(800, 600)instead ofinitgraph()with a BGI path for easier setup. - Some graphics.h functions behave slightly differently under WinBGIm compared to the original Turbo C implementation.
✓ Pros
- Free and lightweight IDE
- Runs natively on Windows
- Better editor than Turbo C
- Works offline
✗ Cons
- Manual file and linker setup
- Must use 32-bit compiler
- WinBGIm is not 100% compatible
- Windows only
- Linker flag errors are common
Method 5: Code::Blocks with WinBGIm
Code::Blocks is another free C/C++ IDE. Like Dev-C++, it requires the WinBGIm library to support graphics.h.
Steps
- Download and install Code::Blocks (with MinGW bundled).
- Download the WinBGIm files:
graphics.h,winbgim.h, andlibbgi.a. - Copy
graphics.handwinbgim.hto the Code::BlocksMinGW\includefolder. - Copy
libbgi.ato the Code::BlocksMinGW\libfolder. - Open Code::Blocks and go to Settings → Compiler → Linker settings.
- Click Add and browse to the
libbgi.afile. - In Other linker options, paste:
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 - Click OK. Create a new project, write your program as
.cpp, and compile.
Important notes
- Always save files with the
.cppextension, not.c. - If you encounter errors in
graphics.haround line 302, you may need to manually edit the header file (known WinBGIm bug on newer compilers). - Ensure your MinGW installation path is correctly set under Settings → Compiler → Toolchain executables.
✓ Pros
- Free and feature-rich IDE
- Better project management
- Active community support
- Works offline
✗ Cons
- Manual setup required
- WinBGIm compatibility issues
- Header file bugs on newer compilers
- Windows only
- Confusing for beginners
Comparison table
Here is a side-by-side comparison of all five methods:
| Feature | Online Compiler | VS Code Extension | Turbo C++ | Dev-C++ | Code::Blocks |
|---|---|---|---|---|---|
| Setup time | 0 minutes | 2 minutes | 15+ minutes | 20+ minutes | 20+ minutes |
| Platform | Any (browser) | Win / Mac / Linux | Windows only | Windows only | Windows only |
| Compiler used | Turbo C (real) | Turbo C (emulated) | Turbo C (native) | GCC + WinBGIm | GCC + WinBGIm |
| 100% compatible | Yes | Yes | Yes | Partial | Partial |
| Modern editor | Yes | Yes | No | Basic | Basic |
| Works offline | No | No | Yes | Yes | Yes |
| Cost | Free | Free | Free | Free | Free |
Which method should you use?
- Just need to run a program quickly? Use the online compiler. Open it, paste your code, click run. Done.
- Working on multiple programs regularly? Install the VS Code extension for the best editing experience with one-click compile.
- Your college specifically requires Turbo C++? Use Method 3, but be prepared for the old-school editor experience.
- Need a native Windows IDE without DOSBox? Try Dev-C++ or Code::Blocks with WinBGIm, but note that not all functions may behave identically to the original.
Test program
Use this simple program to verify your setup works, regardless of which method you chose:
#include <graphics.h>
#include <conio.h>
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setcolor(YELLOW);
circle(320, 240, 100);
setcolor(GREEN);
rectangle(220, 140, 420, 340);
setcolor(WHITE);
outtextxy(260, 230, "graphics.h works!");
getch();
closegraph();
return 0;
}
Try it instantly: Open the graphics.h online compiler, paste this code, and click Compile & Run to see the output.