The SDL_bgi Library


Slava Ukraini



   Hopalong

Introduction

This site provides binaries and documentation for SDL_bgi. This is a port of the 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, macOS, GNU/Linux, and WebAssembly via Emscripten.

SDL_bgi can be used to port old programs written for Turbo/Borland C to modern systems. 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.

Documentation and sample BGI programs are available at this address: https://winbgim.codecutter.org/V6_0/doc/. Nearly all programs can be compiled with SDL_bgi.

Download

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

Install the binaries, then install the Python module with:

$ pip install sdl_bgi
sdl_bgi.py lives here.

Building has been tested on GNU/Linux Mint 21, Fedora 39, Windows (MSYS2 + mingw-w64 version 20240113, Code::Blocks 20.03, Dev-C++ 5.11 ), macOS Catalina, Raspios for ARM and i386, and Emscripten 3.1.58.

See latest changes: ChangeLog.


How to Use SDL_bgi

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

On MSYS2 + Mingw64:

gcc -o program.exe program.c -lmingw32 -L/mingw64/bin \
  -lSDL_bgi -lSDL2main -lSDL2 # -mwindows

Instructions are also provided for CodeBlocks and Dev-C++.

Using Emscripten:

emcc -o program.html program.c \
        -std=gnu99 -O2 -Wall -lSDL_bgi -lm \
        -s USE_SDL=2             `# uses SDL2 module` \
        -s ALLOW_MEMORY_GROWTH=1 `# needed for the argb palette` \
        -s ASYNCIFY              `# implement loops` \
        -s SINGLE_FILE           `# standalone html files`

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.


Features

Nearly all graphics functions work correctly; mouse support and ARGB extensions, as described here, are also implemented. Most old programs should compile with no modification; most programs can be compiled to WebAssembly and run in the browser, thanks to Emscripten.

Please consult the enclosed documentation for more information. (also here).

Sample Programs

The following examples are included in the SDL_bgi distribution.

SDL_bgi The original Borland BGI demo, bgidemo.c

SDL_bgi This is sdlbgidemo.c, showing many of SDL_bgi features. Uses logo.bmp and plasma.bmp.

SDL_bgi This is the output of fern.c, an IFS system.

SDL_bgi Conway's Game of life, life.c

SDL_bgi This is the output of fonts.c, showing the new BGI-compatible fonts.

SDL_bgi The ubiquitous mandelbrot.c.

SDL_bgi A nice kaleidoscope. kaleido.c.


Links

Other similar implementations are:


Brought to you by Guido Gonzato, PhD.

To contact me: guido dot gonzato at gmail dot com

Made with Jed Download The SDL_Bgi Library

Last modified: December 12, 2022