The SDL_bgi and libXbgi Libraries



This site provides binaries and documentation for SDL_bgi and libXbgi. These are ports of old Borland Graphics Interface (graphics.h), originally written for DOS, to modern systems.

SDL_bgi is based on SDL2, and is portable to any platform supported by SDL2 (Windows, OS X, GNU/Linux, Android). libXbgi is based on Xlib, so it only runs under X11.

These compatibility libraries can be used to port old programs written for Turbo/Borland C to Linux, other Unix-like systems, and Windows (SDL_bgi). And, of course, to write new graphics programs with minimal effort: BGI, once extremely popular, was probably the simplest way to implement presentation graphics in C programs. The same ease of programming can be obtained on modern systems. Programming fractals, cellular automata, geometry, physics models etc. is a breeze with SDL_bgi or libXbgi.

libXbgi is part of Ptoc, a Pascal to C converter written by Dr. Konstantin Knizhnik. SDL_bgi was written by me, Dr. Guido Gonzato.

Documentation and sample BGI programs are available at this address: Nearly all programs can be compiled with SDL_bgi and libXbgi.

SDL_bgi is licensed under the Zlib license. libXbgi is released under a generic free software license; please read License.txt.

Which library should you use? Well, it depends:

Please note that libXbgi is unsupported, and it's only provided in its present state. Bugs will not be fixed unless you provide the fix!



The current release of SDL_bgi is 2.1.0. To compile it from sources, you will need a compiler (gcc or clang are fine), make, and SDL2. On Debian and Ubuntu-like distributions, you will need the package 'libsdl2-dev' and its dependencies.

Building has been tested on GNU/Linux Mint 18.*, Fedora 26, Windows (MSYS2 + mingw-w64), and Mac OS X Yosemite.

See latest changes: ChangeLog.

These packages were built on a GNU/Linux Mint 18.1 box and on Fedora 26.


The current release of libXbgi is version 364. To compile it from sources, you will need a compiler (gcc or clang are fine) and the X11 development packages; on Debian-like distributions, it's 'libx11-dev' and its depencencies.

How to Use SDL_bgi and libXbgi

To compile a program using SDL_bgi, make sure that it includes the 'graphics.h' header file. Then:

gcc -o program program.c -lSDL_bgi -lSDL2

To compile a program using libXbgi, make sure that it includes the 'graphics.h' header file. Then:

gcc -o program program.c /usr/lib/libXbgi.a -lX11 -lm

In most cases, all you have to do to compile an old program is comment out the lines

#include <conio.h>
#include <dos.h>

if they're present. Alternatively, you may create dummy (empty) conio.h and dos.h file, if you wish.

Please consult the enclosed documentation for more information.


Nearly all graphics functions work correctly; basic mouse support and RGB extensions, as described here, are also implemented. Most old programs should compile with no modification.

Please consult the enclosed documentation for more information.

Sample Programs

Both libraries come with a few demo programs, including a turtle graphics mini library. The following examples are taken from the SDL_bgi distribution.

borland The original Borland BGI demo (bgidemo.c). Source not included (it's not free software, sorry.)
turtledemo This is sdlbgidemo.c, showing many of SDL_bgi features.
fern This is the output of fern.c, an IFS system.
mandelbrot The ubiquitous mandelbrot.c.
mousetest Mouse and RGB colours demonstration, mousetest.c.
turtledemo Turtle graphics demonstration, turtledemo.c.


Other similar implementations are:

Brought to you by Guido Gonzato, PhD.

To contact me: guido dot gonzato at gmail dot com

Made with Jed libxbgi at

Last modified: January 3rd, 2018