├── .gitignore ├── AUTHORS ├── BUGS ├── CMakeLists.txt ├── ChangeLog ├── INSTALL_Emscripten.md ├── INSTALL_GNU-Linux.md ├── INSTALL_Python.md ├── INSTALL_Windows.md ├── INSTALL_macOS.md ├── LICENSE ├── README.md ├── TODO ├── VERSION ├── demo ├── .gitignore ├── Makefile ├── Makefile.emcc ├── README.md ├── assets │ ├── SDL_BGI_RATE │ ├── SDL_BGI_RES │ ├── logo.bmp │ ├── logo.png │ └── plasma.bmp ├── boo.c ├── boo.py ├── buffers.c ├── buffers.py ├── buffers_numpy.py ├── cellular.c ├── cellular.py ├── conio.h ├── dla.c ├── dla.py ├── dos.h ├── emcc.sh ├── f90_test.f90 ├── fern.c ├── fern.py ├── floodfilltest.c ├── floodfilltest.py ├── fonts.c ├── fonts.py ├── hopalong.c ├── hopalong.py ├── kaleido.c ├── kaleido.py ├── life.c ├── life.py ├── linebuffers.c ├── linebuffers.py ├── loadimage.c ├── logo.bmp ├── mandelbrot.c ├── mandelbrot.py ├── minimal.c ├── minimal.py ├── mousetest.c ├── mousetest.py ├── multiwin.c ├── multiwin.py ├── pages.c ├── pages.py ├── pdj.c ├── pdj.py ├── plasma.bmp ├── plasma.c ├── plasma.py ├── psychedelia.c ├── psychedelia.py ├── rgbpalette.c ├── rgbpalette.py ├── sdlbgidemo.c ├── shells │ ├── canvas_only.html │ ├── fullwindow.html │ ├── sdl_bgi.html │ └── shell_minimal.html ├── simple.c ├── simple.py ├── speedtest.md ├── tccrun ├── turtle.c ├── turtle.h └── turtledemo.c ├── doc ├── C.png ├── Makefile ├── Python.png ├── README.md ├── SDL_bgi_logo.png ├── SDL_bgi_logo.svg ├── compatibility.html ├── compatibility.md ├── compatibility.pdf ├── fonts.html ├── fonts.md ├── fonts.pdf ├── functions.html ├── functions.md ├── functions.pdf ├── graphics.3.gz ├── graphics.3.md ├── howto_AppImage.html ├── howto_AppImage.md ├── howto_AppImage.pdf ├── howto_CodeBlocks.html ├── howto_CodeBlocks.md ├── howto_CodeBlocks.pdf ├── howto_Dev-Cpp.html ├── howto_Dev-Cpp.md ├── howto_Dev-Cpp.pdf ├── howto_Emscripten.html ├── howto_Emscripten.md ├── howto_Emscripten.pdf ├── howto_Python.html ├── howto_Python.md ├── howto_Python.pdf ├── sdl_bgi-quickref.pdf ├── sdl_bgi-quickref.tex ├── turtlegraphics.pdf ├── turtlegraphics.tex ├── using.html ├── using.md └── using.pdf ├── icon.bmp ├── mkpkg.sh ├── pypi ├── LICENSE ├── README.md ├── pyproject.toml ├── src │ └── sdl_bgi │ │ ├── __init__.py │ │ └── sdl_bgi.py └── test │ ├── boo.py │ ├── buffers.py │ ├── buffers_numpy.py │ ├── cellular.py │ ├── dla.py │ ├── fern.py │ ├── floodfilltest.py │ ├── fonts.py │ ├── hopalong.py │ ├── kaleido.py │ ├── life.py │ ├── linebuffers.py │ ├── mandelbrot.py │ ├── minimal.py │ ├── mousetest.py │ ├── multiwin.py │ ├── pdj.py │ ├── plasma.py │ ├── psychedelia.py │ ├── rgbpalette.py │ └── simple.py ├── sdl_bgi.spec ├── src ├── Makefile ├── Makefile.CodeBlocks ├── Makefile.DevCpp ├── SDL_bgi.c ├── SDL_bgi.h ├── bold.h ├── euro.h ├── goth.h ├── graphics.h ├── lcom.h ├── litt.h ├── sans.h ├── scri.h ├── sdl_bgi.py ├── simp.h ├── trip.h └── tscr.h ├── test ├── .gitignore ├── Makefile ├── README.md ├── USER.CHR ├── arc.c ├── bar.c ├── bar3d.c ├── circle.c ├── cleardevice.c ├── clearviewport.c ├── closegraph.c ├── conio.h ├── delay.c ├── detectgraph.c ├── dos.h ├── drawpoly.c ├── ellipse.c ├── fillellipse.c ├── fillpoly.c ├── floodfill.c ├── getactivepage.c ├── getarccoords.c ├── getaspectratio.c ├── getbkcolor.c ├── getcolor.c ├── getdefaultpalette.c ├── getdrivername.c ├── getfillpattern.c ├── getfillsettings.c ├── getgraphmode.c ├── getimage.c ├── getlinesettings.c ├── getmaxcolor.c ├── getmaxmode.c ├── getmaxx.c ├── getmaxy.c ├── getmodename.c ├── getmoderange.c ├── getpalette.c ├── getpalettesize.c ├── getpixel.c ├── gettextsettings.c ├── getviewsettings.c ├── getvisualpage.c ├── getx.c ├── gety.c ├── graphdefaults.c ├── grapherrormsg.c ├── graphresult.c ├── imagesize.c ├── initgraph.c ├── installuserfont.c ├── kbhit.c ├── line.c ├── linerel.c ├── lineto.c ├── moverel.c ├── moveto.c ├── outtext.c ├── outtextxy.c ├── pieslice.c ├── putimage.c ├── putpixel.c ├── rectangle.c ├── restorecrtmode.c ├── sector.c ├── setactivepage.c ├── setallpalette.c ├── setaspectratio.c ├── setbkcolor.c ├── setcolor.c ├── setfillpattern.c ├── setfillstyle.c ├── setgraphbufsize.c ├── setgraphmode.c ├── setlinestyle.c ├── setpalette.c ├── settextjustify.c ├── settextstyle.c ├── setusercharsize.c ├── setviewport.c ├── setvisualpage.c ├── setwritemode.c ├── textheight.c └── textwidth.c └── tmp ├── README.md ├── bgi_palette.png ├── chr_decoder.c ├── dumpchar.c ├── icon.c └── truncate.c /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *.dSYM 3 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Main library: 2 | 3 | Guido Gonzato, PhD 4 | 5 | Automatic refresh patch, CHR font support: 6 | 7 | Marco Diego Aurélio Mesquita, 8 | -------------------------------------------------------------------------------- /BUGS: -------------------------------------------------------------------------------- 1 | BUGS 2 | ---- 3 | 4 | - automatic refresh does not work on NVIDIA GK208BM (GeForce 920M) with 5 | nvidia-driver-* on GNU/Linux. As far as I can say, this is an NVIDIA 6 | driver problem. 7 | 8 | - on MSYS2, keyboard-related functions may cause the program to hang. 9 | I've tried hard to find out, but I give up: I assume that it's a bug 10 | in MSYS2 and/or Mingw64. 11 | 12 | - in Raspbian 10 for ARM, the 'p' letter is drawn incorrectly in 13 | SCRIPT_FONT. The bug does not affect Raspbian 10 for i386. 14 | Reported by Ioulianos Kakoulidis. 15 | 16 | Please report bugs if you find any. 17 | -------------------------------------------------------------------------------- /INSTALL_Emscripten.md: -------------------------------------------------------------------------------- 1 | # `SDL_bgi` and Emscripten 2 | 3 | Unmodified `SDL_bgi` programs can be compiled to WebAssembly using the 4 | [Emscripten](https://emscripten.org/) compiler `emcc`. The following 5 | tools are used to produce standalone `html` files that can be run in 6 | supported browsers: 7 | 8 | - `src/Makefile` provides a `wasm` target, only available when the 9 | `EMSDK` environment variable is defined; 10 | - `test/emcc.sh` can be used to compile a program; 11 | - `test/Makefile.emcc` compiles the sample programs. 12 | 13 | Emscripten support was tested with `emcc` 3.1.22 (latest git version) 14 | and `clang'' 14.0.0 on GNU/Linux Mint 20.2 and MSYS2 20220906. 15 | 16 | 17 | ## Installing Emscripten Support 18 | 19 | Emscripten must be properly installed, and the `EMSDK` environment 20 | variable must be defined; please consult the Emscripten [Download and 21 | install](https://emscripten.org/docs/getting_started/downloads.html) 22 | page. 23 | 24 | To compile `SDL_bgi` and install Emscripten support: 25 | 26 | ``` 27 | $ cd src/ 28 | src/$ make wasm 29 | *** Building on Linux *** 30 | ... 31 | src/$ make clean 32 | ``` 33 | 34 | Files will be installed in appropriate directories: 35 | 36 | ``` 37 | graphics.h -> $EMSDK/upstream/emscripten/cache/sysroot/include 38 | SDL_bgi.h -> $EMSDK/upstream/emscripten/cache/sysroot/include/SDL2 39 | libSDL_bgi.a -> $EMSDK/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten 40 | ``` 41 | 42 | To uninstall: 43 | 44 | ``` 45 | $ cd src/ 46 | src/$ make unwasm 47 | ``` 48 | 49 | -------------------------------------------------------------------------------- /INSTALL_GNU-Linux.md: -------------------------------------------------------------------------------- 1 | # Installing `SDL_bgi` on GNU/Linux 2 | 3 | The easiest way to install `SDL_bgi` is by using the binary packages 4 | provided at in `.deb` and 5 | `.rpm` format. 6 | 7 | Alternatively, you can easily compile `SDL_bgi` yourself, as shown 8 | below. 9 | 10 | 11 | ## Compiling from sources 12 | 13 | Please make sure you have SDL2 development packages. On Debian, Mint, 14 | Ubuntu and similar distributions, please install `libsdl2-dev` and its 15 | dependencies; in Fedora, please install `SDL2-devel`. Obviously, 16 | you'll also need `make` and a C compiler; `gcc` or `clang` are fine. 17 | 18 | 19 | ### Using `make` 20 | 21 | To compile and install `SDL_bgi`, run the following commands: 22 | 23 | $ VERSION=3.0.0 24 | $ tar zxvf SDL_bgi-$VERSION.tar.gz 25 | $ cd SDL_bgi-$VERSION/src 26 | $ make 27 | $ sudo make install 28 | 29 | Files will be installed in appropriate directories: 30 | 31 | SDL_bgi.h -> /usr/include/SDL2/ 32 | graphics.h -> /usr/include/ 33 | libSDL_bgi.so -> /usr/lib/ 34 | sdl_bgi.py -> last entry in Python sys.path 35 | 36 | 37 | ### Using `cmake` 38 | 39 | This only works if `cmake` and `cpack` are installed. 40 | 41 | To compile the `SDL_bgi` library and make `.deb` or `.rpm` packages: 42 | 43 | $ VERSION=3.0.0 44 | $ tar zxvf SDL_bgi-$VERSION.tar.gz 45 | $ cd SDL_bgi-$VERSION 46 | $ ./mkpkg.sh 47 | 48 | which creates a subdirectory called `build/`, moves to it, runs 49 | `cmake`, then `cpack`. In a few seconds, in directory `build/` you 50 | will find a package that should be suitable for your system (`.deb` or 51 | `.rpm`). You'll want to install that. 52 | 53 | If you prefer the usual way: 54 | 55 | $ mkdir build && cd build 56 | $ cmake .. 57 | $ make && sudo make install 58 | 59 | To uninstall: 60 | 61 | $ make uninstall 62 | 63 | 64 | ## Test Programs 65 | 66 | Once `SDL_bgi` is installed, you can compile some test programs you 67 | can find in the `test/` directory. Type: 68 | 69 | $ cd test && make 70 | 71 | Please file see file `doc/using.pdf`. 72 | 73 | Enjoy! 74 | 75 | Guido =8-) 76 | -------------------------------------------------------------------------------- /INSTALL_Python.md: -------------------------------------------------------------------------------- 1 | # Installing `SDL_bgi` for Python 2 | 3 | The `sdl_bgi.py` Python module has been tested with Python 3.10.6 4 | (GNU/Linux, Windows, MSYS2) using the standard interpreter, IDLE, 5 | IPython, ptpython, and Pyston. It uses standard modules `ctypes`, 6 | `sysconfig`, and `random`; `PySDL2` is not required. 7 | 8 | To use `sdl_bgi.py` in Python programs, first you must install the 9 | `SDL_bgi` binaries; please follow the instructions for your operating 10 | system. When you're done, choose one of the following options. 11 | 12 | 13 | ## GNU/Linux, macOS 14 | 15 | Install `sdl_bgi.py` the usual way: 16 | 17 | ``` 18 | $ pip install sdl_bgi 19 | ``` 20 | 21 | Alternatively, you can install `sdl_bgi.py` with: 22 | 23 | ``` 24 | $ cd src/ 25 | src $ make python 26 | ``` 27 | 28 | which installs `sdl_bgi.py` in the user's site package directory (e.g. 29 | `$HOME/.local/lib/python3.10/site-packages/`). 30 | 31 | Now `sdl_bgi.py` can be used in scripts, in the default Python 32 | interpreter, in IDLE, and IPython. 33 | 34 | 35 | ## Windows: Native Python and `cmd` 36 | 37 | This method employs Python, installed from 38 | , and the standard Windows 39 | command prompt (`cmd`). 40 | 41 | Copy `SDL2.dll`, `bin/Mingw64/SDL_bgi.dll`, and `src/sdl_bgi.py` to 42 | your Python directory, i.e. the directory where you save your Python 43 | programs. let's assume its path is `C:\Users\yourname\MyPython`. 44 | `SDL2.dll` is included in package `SDL2-X.Y.ZZ-win32-x64.zip` from the 45 | SDL2 download page. 46 | 47 | To run a program, start `cmd` and type: 48 | 49 | ``` 50 | C:\Documents and Settings\yourname>cd MyPython 51 | 52 | C:\Documents and Settings\yourname\MyPython>python program.py 53 | ``` 54 | 55 | Please note that the Python console, IPython, and ptpython won't work; 56 | the graphical window will freeze and won't respond anymore. Go figure. 57 | 58 | 59 | ## Windows: IDLE 60 | 61 | As above, copy `SDL_bgi.dll`, `SDL2.dll`, and `sdl_bgi.py` to your 62 | Python directory; let's assume its path is 63 | `C:\Users\yourname\MyPython`. Start IDLE, then run the following 64 | commands: 65 | 66 | ``` 67 | from os import chdir 68 | chdir ("MyPython") 69 | from sdl_bgi import * 70 | # write your Python code... 71 | ``` 72 | 73 | ## Windows: MSYS/Mingw64 74 | 75 | This method uses one of the native Python packages for MSYS2, i.e. 76 | `mingw-w64-x86_w64-python`. 77 | 78 | Install `sdl_bgi.py` the usual way: 79 | 80 | ``` 81 | $ pip install sdl_bgi 82 | ``` 83 | 84 | You can also install `sdl_bgi.py` with: 85 | 86 | ``` 87 | $ cd src/ 88 | src $ make python 89 | ``` 90 | 91 | which installs `sdl_bgi.py` in `sys.path[-3]`, that is 92 | `$HOME/.local/lib/python3*/site-packages/`. 93 | 94 | As above, interactive Python shells will not work; scripts and IDLE 95 | work fine. 96 | 97 | Please also see `doc/howto_Python.md`. 98 | 99 | Enjoy! 100 | 101 | Guido =8-) 102 | -------------------------------------------------------------------------------- /INSTALL_macOS.md: -------------------------------------------------------------------------------- 1 | # Installing `SDL_bgi` on macOS 2 | 3 | The easiest way to install `SDL_bgi` requires the Terminal, the 4 | `clang` compiler, the Homebrew package manager, and the SDL2 library. 5 | Full Xcode is not needed. 6 | 7 | - open the Terminal and type `clang`. If it's missing, you'll be 8 | prompted to install it, as part of Xcode's Command Line Tools. 9 | 10 | - go to and install Homebrew using the provided 11 | command. It will take a few minutes. 12 | 13 | - type `brew install SDL2` to install the SDL2 library. 14 | 15 | - optional: unless you are prepared to use `vim` to edit your 16 | programs, install a text editor of your liking. See list of 17 | available options at 18 | 19 | You're now ready to compile `SDL_bgi`. 20 | 21 | 22 | ## Compiling from sources 23 | 24 | To compile and install `SDL_bgi`, start Terminal and run the following 25 | commands: 26 | 27 | % VERSION=3.0.0 28 | % tar xvf SDL_bgi-$VERSION.tar 29 | % cd SDL_bgi-$VERSION/src 30 | % make 31 | % make install 32 | 33 | Files will be installed in these directories: 34 | 35 | SDL_bgi.h -> /usr/local/include/SDL2/ 36 | graphics.h -> /usr/local/include/ 37 | libSDL_bgi.so -> /usr/local/lib/ 38 | sdl_bgi.py -> last entry in Python3 sys.path 39 | 40 | To uninstall: 41 | 42 | % make uninstall 43 | 44 | 45 | ## Test Programs 46 | 47 | Once `SDL_bgi` is installed, you can compile some test programs you 48 | can find in the `test/` directory. Type: 49 | 50 | % cd test && make 51 | 52 | Please file see file `doc/using.pdf`. 53 | 54 | Enjoy! 55 | 56 | Guido =8-) 57 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | // ZLib License 2 | 3 | Copyright (c) 2014-2022 Guido Gonzato, PhD 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | `SDL_bgi` is a graphics library (`GRAPHICS.H`) for C, C++, 4 | WebAssembly, and Python. It's based on SDL2 and it's portable on many 5 | platforms. 6 | 7 | Its name refers to BGI, the Borland Graphics Interface that was the 8 | 'de facto' standard in PC graphics back in DOS days; it was made 9 | popular by Borland Turbo C/C++ compilers. I wrote `SDL_bgi` because I 10 | wanted a simple to use but fast graphics library for my experiments 11 | with fractals and cellular automata, using the BGI syntax I'm used to. 12 | 13 | `SDL_bgi` is functionally compatible with the BGI implementation in 14 | Turbo C 2.01 and Borland C++ 1.0; for instance, it compiles and runs 15 | the original `bgidemo.c`. `SDL_bgi` also provides nearly full 16 | compatibility with another BGI implementation, WinBGIm (see links 17 | below). One of the aims of `SDL_bgi` is the preservation of old 18 | software written for BGI; but not only that. 19 | 20 | `SDL_bgi` provides graphics primitives, and is much easier to use than 21 | plain SDL2; it should be especially useful for beginners, i.e. in 22 | introductory programming courses. `SDL_bgi` is pretty fast, and in 23 | addition to BGI compatibility it provides extensions for ARGB colours, 24 | mouse support, vector fonts, and multiple windows. Native SDL2 25 | functions can be used alongside `SDL_bgi` functions. `SDL_bgi` can 26 | also be used in programs written in C++ or Python. 27 | 28 | `SDL_bgi` is written in C, and it should compile on any platform 29 | supported by SDL2. It has been tested on GNU/Linux, MS Windows (MSYS2 30 | and Mingw-w64, CodeBlocks, Dev-C++), macOS (High Sierra and Catalina), 31 | Raspios (ARM, i386), and WebAssembly (Emscripten). A few example 32 | programs in C and Python are provided in the `demo/` directory. 33 | 34 | 35 | ## Links: 36 | 37 | 0. `SDL_bgi` home page: 38 | 39 | 40 | 1. The SDL library: 41 | 42 | 43 | 2. BGI on Wikipedia: 44 | 45 | 46 | 3. WinBGIm, a BGI port for Windows: 47 | 48 | 49 | 4. Xbgi, a BGI XLib port: 50 | 51 | 52 | 5. Borland Turbo C 2.01 online emulator: 53 | 54 | 55 | This library is released under the Zlib license; please see the 56 | enclosed file LICENSE. 57 | 58 | Brought to you by Guido Gonzato, PhD 59 | 60 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | TODO 2 | ---- 3 | 4 | - colours as negative numbers (undocumented TC feature): add 16? 5 | - documentation: provide an example for each function 6 | 7 | Your suggestions are welcome! 8 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 3.0.0 2 | -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | boo 2 | buffers 3 | cellular 4 | floodfilltest 5 | fonts 6 | linebuffers 7 | mandelbrot 8 | minimal 9 | mousetest 10 | multiwin 11 | plasma 12 | psychedelia 13 | rgbpalette 14 | sdlbgidemo 15 | simple 16 | -------------------------------------------------------------------------------- /demo/assets/SDL_BGI_RATE: -------------------------------------------------------------------------------- 1 | auto 2 | -------------------------------------------------------------------------------- /demo/assets/SDL_BGI_RES: -------------------------------------------------------------------------------- 1 | VGA 2 | -------------------------------------------------------------------------------- /demo/assets/logo.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/demo/assets/logo.bmp -------------------------------------------------------------------------------- /demo/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/demo/assets/logo.png -------------------------------------------------------------------------------- /demo/assets/plasma.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/demo/assets/plasma.bmp -------------------------------------------------------------------------------- /demo/boo.c: -------------------------------------------------------------------------------- 1 | /* boo.c -*- C -*- 2 | * 3 | * To compile: 4 | * gcc -o boo boo.c -lSDL_bgi -lSDL2 5 | * 6 | * boo.c shows how to make a window transparent and change some of 7 | * its properties. 8 | * By Guido Gonzato, August 2020 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 | * 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | // ----- 30 | 31 | int main (int argc, char *argv[]) 32 | { 33 | 34 | char 35 | *boo = "BOOO!"; 36 | int 37 | winid, 38 | x, y, 39 | stop = 0; 40 | 41 | // physical screen size, regardless of window dimensions 42 | getscreensize (&x, &y); 43 | 44 | setwinoptions ("", SDL_WINDOWPOS_CENTERED, 45 | SDL_WINDOWPOS_CENTERED, SDL_WINDOW_BORDERLESS); 46 | initwindow (32 * strlen (boo), 32); // 4 times the usual size 47 | setbkcolor (BLACK); 48 | cleardevice (); 49 | winid = getcurrentwindow (); 50 | 51 | // make the window opaque 52 | SDL_SetWindowOpacity (bgi_window, 1.0); 53 | setcolor (RED); 54 | settextstyle (DEFAULT_FONT, HORIZ_DIR, 4); 55 | outtextxy (0, 0, boo); 56 | refresh (); 57 | 58 | while (! stop) { 59 | 60 | srand (time(NULL)); 61 | stop = edelay (random (1000)); 62 | if (stop) 63 | break; 64 | 65 | // make the window transparent (disappear) 66 | SDL_SetWindowOpacity (bgi_window, 0.0); 67 | refresh (); 68 | stop = edelay (random (1500)); 69 | 70 | // opaque again - reappear 71 | resetwinoptions (winid, "", random (x), random (y)); 72 | SDL_SetWindowOpacity (bgi_window, 1.0); 73 | refresh (); 74 | 75 | } // while 76 | 77 | closegraph (); 78 | return 0; 79 | 80 | } 81 | 82 | // ----- end of file boo.c 83 | -------------------------------------------------------------------------------- /demo/boo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | boo.py: shows how to make a window transparent and change some of its 5 | properties. 6 | 7 | By Guido Gonzato, September 2022. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | """ 23 | 24 | from sdl_bgi import * 25 | 26 | try: 27 | from sdl2 import * 28 | except: 29 | print ("Sorry, I need the sdl2 module.") 30 | exit () 31 | 32 | boo = "BOOO!" 33 | stop = 0 34 | 35 | # physical screen size, regardless of window dimensions 36 | x, y = getscreensize () 37 | 38 | setwinoptions ("", SDL_WINDOWPOS_CENTERED, 39 | SDL_WINDOWPOS_CENTERED, SDL_WINDOW_BORDERLESS) 40 | initwindow (32 * len (boo), 32) # 4 times the usual size 41 | setbkcolor (BLACK) 42 | cleardevice () 43 | winid = getcurrentwindow () 44 | 45 | # make the window opaque 46 | SDL_SetWindowOpacity (bgi_window, 1.0) 47 | setcolor (RED) 48 | settextstyle (DEFAULT_FONT, HORIZ_DIR, 4) 49 | outtextxy (0, 0, boo) 50 | refresh () 51 | 52 | while (stop != 1): 53 | 54 | stop = edelay (random (1000)) 55 | if (stop): 56 | break 57 | 58 | # make the window transparent (disappear) 59 | SDL_SetWindowOpacity (bgi_window, 0.0) 60 | refresh () 61 | stop = edelay (random (1500)) 62 | 63 | # opaque again - reappear 64 | resetwinoptions (winid, "", random (x), random (y)) 65 | SDL_SetWindowOpacity (bgi_window, 1.0) 66 | refresh () 67 | 68 | closegraph () 69 | 70 | # ----- end of file boo.py 71 | -------------------------------------------------------------------------------- /demo/buffers.c: -------------------------------------------------------------------------------- 1 | /* buffers.c -*- C -*- 2 | * 3 | * To compile: 4 | * gcc -o buffers buffers.c -lSDL_bgi -lSDL2 5 | * 6 | * getbuffer() / putbuffer() demonstration. 7 | * 8 | * !!! Does not work in Emscripten: 9 | * "Uncaught RuntimeError: memory access out of bounds" 10 | * 11 | * By Guido Gonzato, January 2020. 12 | * 13 | * This program is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with this program; if not, write to the Free Software 25 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 | * 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | #define WIDTH 256 33 | #define HEIGHT 256 34 | 35 | int main (int argc, char *argv[]) 36 | { 37 | // buffers 38 | Uint32 39 | red[HEIGHT][WIDTH], 40 | tmp[HEIGHT][WIDTH], 41 | hues[HEIGHT][WIDTH]; 42 | 43 | Uint8 44 | alpha; 45 | 46 | int x, y; 47 | 48 | // initialise the buffers 49 | for (y = 0; y < HEIGHT; y++) 50 | for (x = 0; x < WIDTH; x++) { 51 | red[y][x] = 0xffff0000; 52 | hues[y][x] = colorRGB (x, y, abs (x - y)); 53 | } 54 | 55 | setwinoptions ("Using putbuffer()", -1, -1, -1); 56 | initwindow (WIDTH, HEIGHT); 57 | setcolor (BLACK); 58 | setbkcolor (WHITE); 59 | cleardevice (); 60 | outtextxy (0, 0, "Click to continue:"); 61 | refresh (); 62 | 63 | getclick (); 64 | putbuffer (red[0]); 65 | getbuffer (tmp[0]); // tmp == red 66 | setcolor (WHITE); 67 | outtextxy (0, 0, "Left click to continue:"); 68 | refresh (); 69 | getclick (); 70 | 71 | for (alpha = 0; alpha < 128; alpha++) { 72 | 73 | for (int y = 0; y < HEIGHT; y++) 74 | for (int x = 0; x < WIDTH; x++) { 75 | hues[y][x] &= 0x00ffffff; // clear alpha 76 | hues[y][x] |= (alpha << 24); // set alpha 77 | } 78 | 79 | putbuffer (tmp[0]); // red screen 80 | putbuffer (hues[0]); // hues + alpha on red 81 | refresh (); 82 | delay (10); 83 | 84 | } // for alpha 85 | 86 | outtextxy (0, 0, "Left click to finish:"); 87 | refresh (); 88 | getclick (); 89 | 90 | closegraph (); 91 | 92 | } 93 | 94 | // ----- end of file buffers.c 95 | -------------------------------------------------------------------------------- /demo/buffers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | buffers.py: getbuffer() / putbuffer() demonstration. 5 | This program is equivalent to 'buffers_numpy.py', but it does not use 6 | matrix and vector facilities provided by Numpy. 7 | 8 | By Guido Gonzato, September 2022. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 | """ 24 | 25 | from sdl_bgi import * 26 | 27 | WIDTH = 256 28 | HEIGHT = 256 29 | SIZE = WIDTH * HEIGHT * sizeofint () 30 | 31 | """ 32 | These are byte buffers, i.e. one-dimensional 'arrays'. 33 | Function create_string_buffer() is provided by ctypes. 34 | """ 35 | 36 | red = create_string_buffer (SIZE) 37 | tmp = create_string_buffer (SIZE) 38 | hues = create_string_buffer (SIZE) 39 | 40 | # ----- 41 | 42 | def bufferxy (buf, width, x, y, value): 43 | """ 44 | Given a byte buffer 'buf 'simulating an array of 'width' 45 | columns, set (x, y) element as 'value'. 46 | """ 47 | # bytes, from lowest to highest 48 | SOI = sizeofint () 49 | vtb = value.to_bytes (4, 'little') 50 | for j in range (SOI): 51 | buf [y * width * SOI + x + j] = vtb[j] 52 | 53 | # ----- 54 | 55 | # initialise the buffers 56 | for y in range (HEIGHT): 57 | for x in range (0, WIDTH * sizeofint (), 4): 58 | """ 59 | each value in 'x' must have room for a C integer, given by 60 | sizeof (int): 4 bytes. Therefore, the real 'x' column is 61 | given by x // 4. 62 | """ 63 | bufferxy (red, WIDTH, x, y, 0xffff0000) 64 | bufferxy (hues, WIDTH, x, y, colorRGB (x//4, y, abs ((x//4) - y))) 65 | 66 | setwinoptions ("Using putbuffer()", -1, -1, -1) 67 | initwindow (WIDTH, HEIGHT) 68 | setcolor (BLACK) 69 | setbkcolor (WHITE) 70 | cleardevice () 71 | outtextxy (0, 0, "Click to continue:") 72 | refresh () 73 | 74 | getclick () 75 | putbuffer (red) 76 | 77 | getbuffer (tmp) # tmp == red 78 | setcolor (WHITE) 79 | outtextxy (0, 0, "Left click to continue:") 80 | refresh () 81 | getclick () 82 | 83 | for alpha in range (128): 84 | 85 | for n in range (0, SIZE, 4): 86 | hues[n + 3] = 0x00 | alpha # set color alpha 87 | 88 | putbuffer (tmp) # red screen 89 | putbuffer (hues) # hues + alpha on red 90 | refresh () 91 | delay (10) 92 | 93 | outtextxy (0, 0, "Left click to finish:") 94 | refresh () 95 | getclick () 96 | 97 | closegraph () 98 | 99 | # ----- end of file buffers.py 100 | -------------------------------------------------------------------------------- /demo/buffers_numpy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | buffers_numpy.py: getbuffer() / putbuffer() demonstration. This 5 | version uses Numpy; please see 'buffers.py' for a Numpy-less version. 6 | 7 | By Guido Gonzato, September 2022. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | """ 23 | 24 | try: 25 | from numpy import * # matrix support 26 | except ModuleNotFoundError or ImportError: 27 | print ("Sorry, this program needs Numpy.") 28 | quit () 29 | 30 | from sdl_bgi import * 31 | 32 | # ----- 33 | 34 | WIDTH = 256 35 | HEIGHT = 256 36 | SIZE = WIDTH * HEIGHT * sizeofint () 37 | 38 | # plain 'int' raises overflow error 39 | red = empty ((WIDTH, HEIGHT), dtype=int64) 40 | hues = empty ((WIDTH, HEIGHT), dtype=int64) 41 | 42 | # initialise the buffers 43 | for y in range (HEIGHT): 44 | for x in range (WIDTH): 45 | # fill the red buffer with 0xffff0000 46 | red [x, y] = 0xffff0000 47 | # fill the hues buffer with colorRGB (x, y, abs (x - y)) 48 | hues [x, y] = colorRGB (x, y, abs (x - y)) 49 | 50 | setwinoptions ("Using putbuffer()", -1, -1, -1) 51 | initwindow (WIDTH, HEIGHT) 52 | setcolor (BLACK) 53 | setbkcolor (WHITE) 54 | cleardevice () 55 | outtextxy (0, 0, "Click to continue:") 56 | refresh () 57 | getclick () 58 | 59 | # create a buffer for 'red' array 60 | b_red = vec2buf (reshape (red, -1)) 61 | putbuffer (b_red) 62 | refresh () 63 | 64 | # create a temporary buffer 65 | b_tmp = vec2buf (reshape (red, -1)) 66 | getbuffer (b_tmp) # b_tmp == red 67 | setcolor (WHITE) 68 | outtextxy (0, 0, "Left click to continue:") 69 | refresh () 70 | getclick () 71 | # create a buffer for 'hues' array 72 | b_hues = vec2buf (reshape (hues, -1)) 73 | 74 | for alpha in range (128): 75 | 76 | for n in range (0, SIZE, 4): 77 | b_hues[n + 3] = 0x00 | alpha # set color alpha 78 | 79 | putbuffer (b_tmp) # red screen 80 | putbuffer (b_hues) # hues + alpha on red 81 | refresh () 82 | delay (10) 83 | 84 | outtextxy (0, 0, "Left click to finish:") 85 | refresh () 86 | getclick () 87 | 88 | closegraph () 89 | 90 | # ----- end of file buffers.py 91 | -------------------------------------------------------------------------------- /demo/conio.h: -------------------------------------------------------------------------------- 1 | // Minimal conio.h for old BGI programs 2 | // For a real implementation, have a look at 3 | // https://github.com/nowres/conio-for-linux 4 | 5 | #include 6 | 7 | void clrscr (void); 8 | void gotoxy (int, int); 9 | 10 | // ----- 11 | 12 | void clrscr (void) 13 | { 14 | // Clears the console 15 | 16 | printf ("\x1b[2J"); 17 | 18 | } // clrscr () 19 | 20 | // ----- 21 | 22 | void gotoxy (int x, int y) 23 | { 24 | // Moves the cursor to line y, column x 25 | 26 | printf ("\x1b[%d;%df", y, x); 27 | 28 | } // gotoxy () 29 | 30 | // ----- end of file conio.h 31 | -------------------------------------------------------------------------------- /demo/dos.h: -------------------------------------------------------------------------------- 1 | // dummy dos.h for bgidemo.c 2 | 3 | #include 4 | 5 | #define far 6 | 7 | #ifndef _WIN32 8 | 9 | // K&R itoa() implementation, adapted from 10 | // https://en.wikibooks.org/wiki/C_Programming/stdlib.h/itoa 11 | 12 | /* reverse: reverse string s in place */ 13 | void reverse(char s[]) 14 | { 15 | int i, j; 16 | char c; 17 | 18 | for (i = 0, j = strlen(s)-1; i 0); /* delete it */ 36 | if (sign < 0) 37 | s[i++] = '-'; 38 | s[i] = '\0'; 39 | reverse (s); 40 | return s; 41 | } 42 | 43 | #endif 44 | 45 | // --- end of file dos.h 46 | -------------------------------------------------------------------------------- /demo/emcc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script compiles a .C source using emscripten, which is 4 | # assumed to be installed and working. To run the resulting program, 5 | # open $NAME.html in a web browser. 6 | 7 | # Tested on GNU/Linux only! 8 | 9 | if [ $# -eq 0 ] ; then 10 | echo "Usage: $0 [-c] [-f] [-m] [-s] " 11 | exit 1 12 | fi 13 | 14 | if ! [ -x "$(command -v emcc)" ]; then 15 | echo 'Error: emcc is not installed.' >&2 16 | exit 1 17 | fi 18 | 19 | SHELLFILE="" 20 | SHELL="" 21 | 22 | while getopts ":cfmsh" opt; do 23 | case ${opt} in 24 | c ) SHELLFILE="./shells/canvas_only.html" 25 | ;; 26 | f ) SHELLFILE="./shells/fullwindow.html" 27 | ;; 28 | m ) SHELLFILE="./shells/shell_minimal.html" 29 | ;; 30 | s ) SHELLFILE="./shells/sdl_bgi.html" 31 | ;; 32 | h ) echo "Usage: $0 [-c] [-f] [-m] [-s] " 33 | echo "-c: use ./shells/canvas_only.html" 34 | echo "-f: use ./shells/fullwindow.html" 35 | echo "-m: use ./shells/shell_minimal.html" 36 | echo "-s: use ./shells/sdl_bgi.html" 37 | exit 1 38 | ;; 39 | esac 40 | done 41 | 42 | if [ -n "$SHELLFILE" ] ; then 43 | SHELL="--shell-file "$SHELLFILE 44 | fi 45 | 46 | # program must be the last argument 47 | for arg in "$@" ; do : ; done 48 | 49 | NAME=$(basename $arg .c) 50 | 51 | # load files in 'assets/' as if they were in local directory '.' 52 | EMBED="--embed-file ./assets@/." 53 | CFLAGS="-std=gnu99 -O2 -Wall" 54 | 55 | emcc $CFLAGS -o $NAME.html \ 56 | $SHELL $INCLUDE $EMBED $NAME.c -lSDL_bgi \ 57 | -s USE_SDL=2 \ 58 | -s ALLOW_MEMORY_GROWTH=1 \ 59 | -s ASYNCIFY \ 60 | -s SINGLE_FILE 61 | 62 | # --- end of file emcc.sh 63 | -------------------------------------------------------------------------------- /demo/f90_test.f90: -------------------------------------------------------------------------------- 1 | ! f90_test.f90 2 | ! 3 | ! To compile this program: 4 | ! gfortran -o f90_test -Wall f90_test.f90 -lSDL_bgi -lSDL2 5 | ! 6 | ! Kindly provided by Angelo Graziosi, angelo.graziosi "at" alice.it 7 | 8 | module sdl_bgi 9 | use, intrinsic :: iso_c_binding, only: C_INT, C_CHAR 10 | implicit none 11 | private 12 | 13 | interface 14 | subroutine close_graph() bind(C, name = 'closegraph') 15 | import 16 | end subroutine close_graph 17 | end interface 18 | 19 | interface 20 | function get_ch() bind(C, name = 'getch') 21 | import 22 | integer(C_INT) :: get_ch 23 | end function get_ch 24 | end interface 25 | 26 | interface 27 | function get_pixel(x,y) bind(C, name = 'getpixel') 28 | import 29 | integer(C_INT) :: get_pixel 30 | integer(C_INT), intent(in), value :: x, y 31 | end function get_pixel 32 | end interface 33 | 34 | interface 35 | subroutine init_graph(gd,gm,pd) bind(C, name = 'initgraph') 36 | import 37 | integer(C_INT), intent(inout) :: gd, gm 38 | character(C_CHAR), intent(in) :: pd(*) 39 | end subroutine init_graph 40 | end interface 41 | 42 | interface 43 | subroutine put_pixel(x,y,c) bind(C, name = 'putpixel') 44 | import 45 | integer(C_INT), intent(in), value :: x, y, c 46 | end subroutine put_pixel 47 | end interface 48 | 49 | interface 50 | subroutine out_text_xy(x,y,textstring) bind(C, name = 'outtextxy') 51 | import 52 | integer(C_INT), intent(in), value :: x, y 53 | character(C_CHAR), intent(in) :: textstring(*) 54 | end subroutine out_text_xy 55 | end interface 56 | 57 | public :: close_graph, get_ch, get_pixel, init_graph, & 58 | & put_pixel, out_text_xy 59 | 60 | end module sdl_bgi 61 | 62 | program sdl_bgi_test 63 | use, intrinsic :: iso_c_binding, only: C_NULL_CHAR 64 | use sdl_bgi, only: close_graph, get_ch, get_pixel, & 65 | & init_graph, put_pixel, out_text_xy 66 | implicit none 67 | 68 | integer, parameter :: WIDTH = 640, HEIGHT = 480, MAX_COLOR = 15, NPTS = 1000 69 | integer :: i, x, y, c, k, gd, gm 70 | real :: r(3) 71 | 72 | gd = 3 73 | gm = 3 74 | call init_graph(gd, gm, '') 75 | 76 | call random_seed() 77 | do i = 1, NPTS 78 | call random_number(r) 79 | 80 | x = int(r(1)*WIDTH) 81 | y = int(r(2)*HEIGHT) 82 | c = 1+int(r(3)*MAX_COLOR) 83 | 84 | call put_pixel(x,y,c) 85 | end do 86 | 87 | k = get_ch() 88 | 89 | call random_seed() 90 | do i = 1, NPTS 91 | call random_number(r) 92 | 93 | x = int(r(1)*WIDTH) 94 | y = int(r(2)*HEIGHT) 95 | c = get_pixel(x,y) 96 | 97 | if (c == 1+int(r(3)*MAX_COLOR)) call put_pixel(x,y,0) 98 | end do 99 | 100 | call out_text_xy(0,20,'Press a key to quit'//C_NULL_CHAR) 101 | k = get_ch() 102 | call close_graph() 103 | 104 | end program sdl_bgi_test 105 | -------------------------------------------------------------------------------- /demo/fern.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | fern.py: a famous IFS system. 5 | 6 | By Guido Gonzato, September 2022. 7 | 8 | This program is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 2 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | """ 22 | 23 | from sdl_bgi import * 24 | 25 | gd = DETECT 26 | gm = SDL_800x600 27 | 28 | stop = 0 29 | counter = 0 30 | # midx, midy, scale 31 | # int k = 0, prob 32 | # float x, y, xx, yy 33 | 34 | a = [0.0, 0.85, 0.2, -0.15] 35 | b = [0.0, 0.04, -0.26, 0.28] 36 | c = [0.0, 0.04, 0.23, 0.26] 37 | d = [0.16, 0.85, 0.22, 0.24] 38 | e = [0.0, 0.0, 0.0, 0.0] 39 | f = [0.0, 1.6, 1.6, 0.44] 40 | 41 | setwinoptions ("This is a fractal fern", -1, -1, -1) 42 | initgraph (gd, gm, "") 43 | setbkcolor (COLOR (0, 0, 40)) 44 | cleardevice () 45 | setcolor (YELLOW) 46 | outtextxy (0, 0, "Press a key to exit: ") 47 | 48 | midx = getmaxx () / 2 49 | midy = getmaxy () / 2 50 | scale = getmaxx () / 16 51 | x = 0.0 52 | y = 0.0 53 | setcolor (COLOR (random (256), random (256), random (256))) 54 | 55 | # kbhit (), mouseclick () and event () are slow. Use them sparingly. 56 | 57 | while (stop != 1): 58 | 59 | prob = 1 + random (100) 60 | if (prob == 1): 61 | k = 0 62 | if ( (prob > 1) and (prob < 87)): 63 | k = 1 64 | if ( (prob > 86) and (prob < 94)): 65 | k = 2 66 | if (prob > 93): 67 | k = 3 68 | # to use equal probability, just use: 69 | # k = random (5) 70 | 71 | xx = a[k] * x + b[k] * y # + e[k] 72 | yy = c[k] * x + d[k] * y + f[k] 73 | x = xx 74 | y = yy 75 | 76 | fputpixel ((int)(midx + scale * x), (int)(2 * midy - scale * y)) 77 | counter = counter + 1 78 | 79 | if (0 == (counter % 100000)): 80 | setcolor (COLOR (random (256), random (256), random (256))) 81 | refresh () 82 | if (kbhit ()): 83 | stop = 1 84 | 85 | if (100000000 == counter): # 100 million pixels 86 | break 87 | 88 | setcolor (GREEN) 89 | outtextxy (0, 10, "Ok, leaving in 2 seconds") 90 | delay (2000) 91 | closegraph () 92 | 93 | # ----- end of file fern.py ----- 94 | -------------------------------------------------------------------------------- /demo/floodfilltest.c: -------------------------------------------------------------------------------- 1 | /* floodfilltest.c -*- C -*- 2 | * 3 | * To compile: 4 | * gcc -o floodfilltest floodfilltest.c -lSDL_bgi -lSDL2 5 | * 6 | * Floodfill demostration. 7 | * By Guido Gonzato, May 2015. 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | // ----- 30 | 31 | int main (int argc, char *argv[]) 32 | { 33 | 34 | int 35 | stop = 0, 36 | mclick; 37 | 38 | initwindow (800, 600); 39 | setbkcolor (BLACK); 40 | setcolor (RED); 41 | cleardevice (); 42 | settextjustify (CENTER_TEXT, CENTER_TEXT); 43 | 44 | outtextxy (getmaxx() / 2, getmaxy () / 2 - 15, 45 | "Left click to draw a random circle;"); 46 | outtextxy (getmaxx() / 2, getmaxy () / 2, 47 | "right click to fill;"); 48 | outtextxy (getmaxx() / 2, getmaxy () / 2 + 15, 49 | "press a key to exit."); 50 | 51 | getevent (); 52 | 53 | cleardevice (); 54 | setcolor (YELLOW); 55 | refresh (); 56 | 57 | while (! stop) { 58 | 59 | mclick = getevent (); 60 | 61 | if (WM_LBUTTONDOWN == mclick) { 62 | setcolor (YELLOW); 63 | circle (mousex (), mousey (), 10 + random (100)); 64 | refresh (); 65 | } 66 | 67 | if (WM_RBUTTONDOWN == mclick) { 68 | setcolor (random (MAXCOLORS)); 69 | setfillstyle (1 + random(USER_FILL), 70 | COLOR (random (255), random (255), random (255))); 71 | floodfill (mousex (), mousey (), YELLOW); 72 | refresh (); 73 | } 74 | 75 | if (KEY_ESC == mclick) 76 | stop = 1; 77 | 78 | } // while 79 | 80 | closegraph (); 81 | return 0; 82 | 83 | } 84 | 85 | // ----- end of file floodfilltest.c 86 | -------------------------------------------------------------------------------- /demo/floodfilltest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | By Guido Gonzato, September 2022. 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | """ 20 | 21 | from sdl_bgi import * 22 | 23 | stop = False 24 | 25 | initwindow (800, 600) 26 | setbkcolor (BLACK) 27 | setcolor (RED) 28 | cleardevice () 29 | settextjustify (CENTER_TEXT, CENTER_TEXT) 30 | 31 | outtextxy (getmaxx() / 2, getmaxy () / 2 - 15, 32 | "Left click to draw a random circle") 33 | outtextxy (getmaxx() / 2, getmaxy () / 2, 34 | "right click to fill") 35 | outtextxy (getmaxx() / 2, getmaxy () / 2 + 15, 36 | "press a key to exit.") 37 | 38 | getevent () 39 | 40 | cleardevice () 41 | setcolor (YELLOW) 42 | refresh () 43 | 44 | while (stop != True): 45 | 46 | mclick = getevent () 47 | 48 | if (WM_LBUTTONDOWN == mclick): 49 | setcolor (YELLOW) 50 | circle (mousex (), mousey (), 10 + random (100)) 51 | refresh () 52 | 53 | if (WM_RBUTTONDOWN == mclick): 54 | setcolor (random (MAXCOLORS)) 55 | setfillstyle (1 + random(USER_FILL), 56 | COLOR (random (255), random (255), random (255))) 57 | floodfill (mousex (), mousey (), YELLOW) 58 | refresh () 59 | 60 | if (KEY_ESC == mclick): 61 | stop = True 62 | 63 | closegraph () 64 | 65 | # ----- end of file floodfilltest.py 66 | -------------------------------------------------------------------------------- /demo/hopalong.c: -------------------------------------------------------------------------------- 1 | /* hopalong.c -*- C -*- 2 | * 3 | * To compile: 4 | * gcc -o hopalong hopalong.c -lSDL_bgi -lSDL2 5 | * 6 | * An implementation of Barry Martin's algorithm. 7 | * By Guido Gonzato, May 2015. 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | // ----- 32 | 33 | #define sgn(n) ((n < 0) ? -1: 1) 34 | 35 | // ----- 36 | 37 | int main (int argc, char *argv[]) 38 | { 39 | int gd, gm, stop; 40 | unsigned int seed; 41 | unsigned long int counter; 42 | float j, k, x, y, xx, xp, yp, r, xoffs, yoffs; 43 | 44 | if (argc == 2) 45 | seed = atoi (argv [1]); // no checks! 46 | else { 47 | printf ("Seed: "); 48 | j = scanf ("%d", &seed); 49 | } 50 | srand (seed); 51 | 52 | gd = DETECT; 53 | gm = getmaxmode (); 54 | initgraph(&gd, &gm, ""); 55 | 56 | setbkcolor (BLACK); 57 | cleardevice (); 58 | setcolor (YELLOW); 59 | outtextxy (0, 0, "Press a key or click to exit: "); 60 | 61 | xoffs = getmaxx () / 2; 62 | yoffs = getmaxy () / 2; 63 | j = random (100); 64 | k = random (100); 65 | x = y = xx = xp = yp = r = 0.0; 66 | stop = counter = 0; 67 | setcolor (COLOR (random (256), random (256), random (256))); 68 | 69 | while (! stop) { 70 | xx = y - sgn (x) * sqrt (fabs (k * x - 1)); 71 | y = j - x; 72 | x = xx; 73 | xp = x * 2 + xoffs; 74 | yp = y * 2 + yoffs; 75 | _putpixel (xp, yp); 76 | if (++counter == 50000) { 77 | refresh (); 78 | counter = 0; 79 | setcolor (COLOR (random (256), random (256), random (256))); 80 | refresh (); 81 | if (ismouseclick (WM_LBUTTONDOWN) || kbhit ()) 82 | stop = 1; 83 | } 84 | } 85 | 86 | closegraph (); 87 | if (SDL_KEYDOWN == eventtype ()) 88 | puts ("Key pressed."); 89 | else 90 | puts ("Mouse clicked."); 91 | 92 | return 0; 93 | } 94 | 95 | // ----- end of file hopalong.c 96 | -------------------------------------------------------------------------------- /demo/hopalong.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | hopalong.py: an implementation of Barry Martin's algorithm. 5 | By Guido Gonzato, September 2022. 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | """ 21 | 22 | from sdl_bgi import * 23 | from math import sqrt 24 | from random import seed 25 | from sys import argv 26 | 27 | def sgn(n): 28 | if (n < 0): 29 | return -1 30 | else: 31 | return 1 32 | 33 | # ----- 34 | 35 | def main (args): 36 | 37 | if (len (args) == 1): 38 | s = 1922 39 | else: 40 | s = int (argv[1]) 41 | 42 | seed (s) 43 | gd = DETECT 44 | gm = getmaxmode () 45 | initgraph(gd, gm, "") 46 | 47 | setbkcolor (BLACK) 48 | cleardevice () 49 | setcolor (YELLOW) 50 | outtextxy (0, 0, "Press a key or click to exit: ") 51 | 52 | xoffs = getmaxx () / 2 53 | yoffs = getmaxy () / 2 54 | j = random (100) 55 | k = random (100) 56 | x = y = xx = xp = yp = r = 0.0 57 | stop, counter = 0, 0 58 | setcolor (COLOR (random (256), random (256), random (256))) 59 | 60 | while (stop != 1): 61 | xx = y - sgn (x) * sqrt (abs (k * x - 1)) 62 | y = j - x 63 | x = xx 64 | xp = x * 2 + xoffs 65 | yp = y * 2 + yoffs 66 | fputpixel (xp, yp) 67 | counter += 1 68 | if counter == 50000: 69 | refresh () 70 | counter = 0 71 | setcolor (COLOR (random (256), random (256), random (256))) 72 | refresh () 73 | if ismouseclick (WM_LBUTTONDOWN) or kbhit (): 74 | stop = 1 75 | 76 | closegraph () 77 | if (SDL_KEYDOWN == eventtype ()): 78 | print ("Key pressed.") 79 | else: 80 | print ("Mouse clicked.") 81 | 82 | # ----- 83 | 84 | if __name__ == '__main__': 85 | main (argv) 86 | 87 | 88 | # ----- end of file hopalong.py 89 | -------------------------------------------------------------------------------- /demo/linebuffers.c: -------------------------------------------------------------------------------- 1 | /* linebuffers.c -*- C -*- 2 | * 3 | * To compile: 4 | * gcc -o linebuffers linebuffers.c -lSDL_bgi -lSDL2 5 | * 6 | * getlinebuffer() / putlinebuffer() demonstration. 7 | * 8 | * By Guido Gonzato, February 2020. 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 | * 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #define WIDTH 256 30 | #define HEIGHT 256 31 | 32 | void shiftbuffer (Uint32 *line) 33 | { 34 | // scroll line elements 1 position to the right 35 | 36 | Uint32 37 | tmp; 38 | 39 | tmp = line[0]; 40 | memmove ( (void *) &line[0], (const void *) &line[1], 41 | (size_t) ((WIDTH - 1) * sizeof (Uint32)) ); 42 | line[WIDTH - 1] = tmp; 43 | 44 | } // shiftbuffer() 45 | 46 | // ----- 47 | 48 | int main (int argc, char *argv[]) 49 | { 50 | Uint32 51 | hues[HEIGHT][WIDTH], 52 | linebuffer[WIDTH]; 53 | 54 | // initialise the buffer 55 | 56 | for (int y = 0; y < HEIGHT; y++) 57 | for (int x = 0; x < WIDTH; x++) 58 | hues[y][x] = colorRGB (x, y, abs (x - y)); 59 | 60 | setwinoptions ("Using putlinebuffer()", -1, -1, -1); 61 | initwindow (WIDTH, HEIGHT); 62 | refresh (); 63 | showinfobox ("Left click to switch between\n" 64 | "putlinebuffer() and putpixel();\n" 65 | "right click to stop."); 66 | 67 | putbuffer (hues[0]); 68 | refresh (); 69 | int mode = 1; 70 | 71 | while (! ismouseclick (WM_RBUTTONDOWN)) { 72 | 73 | if (1 == mode) { 74 | for (int y = 0; y < HEIGHT; y++) { 75 | getlinebuffer (y, linebuffer); 76 | shiftbuffer (linebuffer); 77 | putlinebuffer (y, linebuffer); 78 | } 79 | } 80 | else { 81 | for (int y = 0; y < HEIGHT; y++) { 82 | for (int x = 0; x < WIDTH; x++) 83 | linebuffer[x] = getpixel (x, y); 84 | shiftbuffer (linebuffer); 85 | for (int x = 0; x < WIDTH; x++) 86 | putpixel (x, y, COLOR32(linebuffer[x])); 87 | } 88 | } 89 | 90 | if (WM_LBUTTONDOWN == mouseclick ()) { 91 | mode ^= 1; 92 | if (1 == mode) 93 | puts ("using getlinebuffer()/putlinebuffer()"); 94 | else 95 | puts ("using getpixel()/putpixel()"); 96 | } 97 | 98 | delay (5); 99 | refresh (); 100 | 101 | } // while 102 | 103 | puts ("Bye!"); 104 | closegraph(); 105 | 106 | } 107 | 108 | // ----- end of file linebuffers.c 109 | -------------------------------------------------------------------------------- /demo/logo.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/demo/logo.bmp -------------------------------------------------------------------------------- /demo/minimal.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (int argc, char *argv[]) 4 | { 5 | int i, gd = DETECT, gm = 0; 6 | initgraph (&gd, &gm, ""); 7 | setbkcolor (BLACK); 8 | cleardevice (); 9 | outtextxy (0, 0, "Drawing 1000 lines..."); 10 | for (i = 0; i < 1000; i++) { 11 | setcolor (1 + random (15)); 12 | line (random(getmaxx()), random(getmaxy()), 13 | random (getmaxx()), random(getmaxy()) ); 14 | } 15 | getch (); 16 | closegraph (); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /demo/minimal.py: -------------------------------------------------------------------------------- 1 | # run with: python3 minimal.py 2 | 3 | from sdl_bgi import * 4 | 5 | gd, gm = DETECT, 0 6 | initgraph (gd, gm, "") 7 | setbkcolor (BLACK) 8 | cleardevice () 9 | outtextxy (0, 0, "Drawing 1000 lines...") 10 | for i in range (1000): 11 | setcolor (1 + random (15)) 12 | line (random(getmaxx()), random(getmaxy()), 13 | random (getmaxx()), random(getmaxy())) 14 | getch () 15 | closegraph () 16 | -------------------------------------------------------------------------------- /demo/multiwin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | multiwin.py: shows how to open multiple windows. 5 | By Guido Gonzato, September 2022. 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | """ 21 | 22 | from sdl_bgi import * 23 | 24 | gd = DETECT 25 | gm = SDL_320x200 26 | 27 | setwinoptions ("First Window", 10, 10, -1) 28 | initgraph (gd, gm, "") 29 | cleardevice () 30 | outtextxy (0, 0, "Click or press a key for a SECOND window") 31 | circle (50, 100, 50) 32 | win1 = getcurrentwindow () 33 | print ("Current window: %d" % win1) 34 | x = getmaxx () - 110 35 | y = getmaxy () - 60 36 | readimagefile ("./logo.bmp", x, y, x + 100, y + 50) 37 | getevent () 38 | delay (500) 39 | 40 | setwinoptions ("Second Window", 10, 200 + 50, -1) 41 | initgraph (gd, gm, "") 42 | cleardevice () 43 | setcolor (RED) 44 | outtextxy (0, 0, "Click or press a key for a THIRD window") 45 | circle (100, 100, 50) 46 | win2 = getcurrentwindow () 47 | print ("Current window: %d" % win2) 48 | readimagefile ("./logo.bmp", x, y, x + 100, y + 50) 49 | getevent () 50 | delay (500) 51 | 52 | setwinoptions ("Third Window", 320 + 50, 10, -1) 53 | win3 = initwindow (640, 480) 54 | cleardevice () 55 | setcolor (GREEN) 56 | outtextxy (0, 0, "Press a key to switch back to the FIRST window") 57 | circle (150, 100, 50) 58 | print ("Current window: %d" % win3) 59 | x = getmaxx () - 110 60 | y = getmaxy () - 60 61 | readimagefile ("./logo.bmp", x, y, x + 100, y + 50) 62 | getevent () 63 | delay (500) 64 | 65 | setcurrentwindow (win1) 66 | setcolor (WHITE) 67 | circle (150, 100, 50) 68 | win1 = getcurrentwindow () 69 | print ("Current window: %d" % win1) 70 | setcolor (YELLOW) 71 | outtextxy (0, 10, "Back to the FIRST window press a key") 72 | getevent () 73 | setcolor (RED) 74 | outtextxy (0, 20, "Shutting down...") 75 | 76 | setwintitle (win3, "Window 3 is shutting down...") 77 | delay (2000) 78 | print ("Shutting down window %d" % win3) 79 | closewindow (win3) 80 | 81 | setwintitle (win2, "Window 2 is shutting down...") 82 | delay (2000) 83 | print ("Shutting down window %d" % win2) 84 | closewindow (win2) 85 | 86 | setwintitle (win1, "Window 1 is shutting down...") 87 | delay (2000) 88 | print ("Shutting down window %d" % win1) 89 | closewindow (win1) 90 | 91 | # ----- end of file multiwin.py 92 | -------------------------------------------------------------------------------- /demo/pages.c: -------------------------------------------------------------------------------- 1 | /* pages.c -*- C -*- 2 | * 3 | * To compile: 4 | * gcc -o pages pages.c -lSDL_bgi -lSDL2 5 | * 6 | * pages.c shows how to make a window transparent and change some of 7 | * its properties. 8 | * By Guido Gonzato, November 2022 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 | * 24 | */ 25 | 26 | #include 27 | 28 | int main (int argc, char *argv[]) 29 | { 30 | 31 | initwindow (300, 200); 32 | 33 | settextstyle (BOLD_FONT, HORIZ_DIR, 4); 34 | settextjustify (CENTER_TEXT, CENTER_TEXT); 35 | 36 | setactivepage (0); 37 | setbkcolor (BLACK); 38 | setcolor (YELLOW); 39 | outtextxy (150, 60, "PAGE"); 40 | outtextxy (150, 120, "0"); 41 | ; 42 | setactivepage (1); 43 | setbkcolor (BLUE); 44 | setcolor (WHITE); 45 | outtextxy (150, 60, "PAGE"); 46 | outtextxy (150, 120, "1"); 47 | 48 | setactivepage (2); 49 | setbkcolor (RED); 50 | setcolor (BLUE); 51 | outtextxy (150, 60, "PAGE"); 52 | outtextxy (150, 120, "2"); 53 | 54 | setactivepage (3); 55 | setbkcolor (GREEN); 56 | setcolor (MAGENTA); 57 | outtextxy (150, 60, "PAGE"); 58 | outtextxy (150, 120, "3"); 59 | 60 | int page = 0; 61 | int stop = 0; 62 | 63 | while (0 == stop) { 64 | setvisualpage (page); 65 | if (kdelay (500)) 66 | stop = 1; 67 | page++; 68 | if (4 == page) 69 | page = 0; 70 | } 71 | 72 | closegraph (); 73 | 74 | } 75 | -------------------------------------------------------------------------------- /demo/pages.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | pages.py: using active and visual pages. 5 | 6 | By Guido Gonzato, November 2022. 7 | 8 | This program is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 2 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | """ 22 | 23 | from sdl_bgi import * 24 | 25 | initwindow (300, 200); 26 | 27 | settextstyle (BOLD_FONT, HORIZ_DIR, 4) 28 | settextjustify (CENTER_TEXT, CENTER_TEXT) 29 | 30 | setactivepage (0) 31 | setbkcolor (BLACK) 32 | setcolor (YELLOW) 33 | outtextxy (150, 60, "PAGE") 34 | outtextxy (150, 120, str (0)) 35 | 36 | setactivepage (1) 37 | setbkcolor (BLUE) 38 | setcolor (WHITE) 39 | outtextxy (150, 60, "PAGE") 40 | outtextxy (150, 120, str (1)) 41 | 42 | setactivepage (2) 43 | setbkcolor (RED) 44 | setcolor (BLUE) 45 | outtextxy (150, 60, "PAGE") 46 | outtextxy (150, 120, str (2)) 47 | 48 | setactivepage (3) 49 | setbkcolor (GREEN) 50 | setcolor (MAGENTA) 51 | outtextxy (150, 60, "PAGE") 52 | outtextxy (150, 120, str (3)) 53 | 54 | page = 0 55 | stop = False 56 | while stop == False: 57 | setvisualpage (page); 58 | if kdelay (500) == True: 59 | stop = True 60 | page += 1 61 | if page == 4: 62 | page = 0 63 | 64 | closegraph () 65 | -------------------------------------------------------------------------------- /demo/pdj.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | pdj.py: plots Peter de Jong attractors. 5 | By Guido Gonzato, September 2022. 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | """ 21 | 22 | from sdl_bgi import * 23 | from math import * 24 | 25 | def create_palette (): 26 | 27 | # blue fading to white 28 | for x in range (256): 29 | setrgbpalette (x, x, x, 255) # end at 255,255,255 30 | 31 | # white fading to red 32 | for x in range (256): 33 | setrgbpalette (x + 256, 255, 255 - x, 255 - x) # end at 255,0,0 34 | 35 | # red fading to purple 36 | for x in range (256): 37 | setrgbpalette (x + 512, 255, 0, x) # end at 255,0,255 38 | 39 | # purple fading to blue 40 | for x in range (256): 41 | setrgbpalette (x + 768, 255 - x, 0, 255) # end at 0,0,255 42 | 43 | # ----- 44 | 45 | a = 1.641 46 | b = 1.902 47 | c = 0.316 48 | d = 1.525 49 | x = 0.0 50 | y = 0.0 51 | 52 | stop = False 53 | cnt = 0 54 | 55 | initwindow (800, 600) 56 | create_palette () 57 | xm = getmaxx () / 2 58 | ym = getmaxy () / 2 59 | ly = ym / 2 60 | # srand (time (NULL)) 61 | print ("a = %7.4f, b = %7.4f, c = %7.4f, d = %7.4f" % 62 | (a, b, c, d)) 63 | 64 | while (stop != True): 65 | 66 | xx = sin (a * y) - cos (b * x) 67 | yy = sin (c * x) - cos (d * y) 68 | 69 | color = cnt / 16384 70 | if color > 1024: 71 | cnt = 0 72 | color = 0 73 | 74 | setrgbcolor (color) 75 | fputpixel (xm + ly * xx, ym + ly * yy) 76 | x = xx 77 | y = yy 78 | 79 | cnt += 1 80 | if (0 == cnt % 5000): 81 | 82 | refresh () 83 | 84 | if (WM_LBUTTONDOWN == mouseclick ()): 85 | a = -4.0 + 8 * random (10000) / 10000.0 86 | b = -4.0 + 8 * random (10000) / 10000.0 87 | c = -4.0 + 8 * random (10000) / 10000.0 88 | d = -4.0 + 8 * random (10000) / 10000.0 89 | print ("a = %7.4f, b = %7.4f, c = %7.4f, d = %7.4f" % 90 | (a, b, c, d)) 91 | cleardevice () 92 | 93 | if kbhit (): 94 | stop = True 95 | break 96 | 97 | getch () 98 | closegraph () 99 | 100 | # ----- end of file pdj.py 101 | -------------------------------------------------------------------------------- /demo/plasma.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/demo/plasma.bmp -------------------------------------------------------------------------------- /demo/plasma.c: -------------------------------------------------------------------------------- 1 | /* plasma.c -*- C -*- 2 | * 3 | * To compile: 4 | * gcc -o plasma plasma.c -lSDL_bgi -lSDL2 5 | * 6 | * Writes the window contents to a `.bmp` file. 7 | * 8 | * By Guido Gonzato, May 2015. 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 | * 24 | */ 25 | 26 | 27 | #include 28 | #include 29 | 30 | #define PI 3.141593 31 | 32 | int main (int argc, char *argv[]) 33 | { 34 | 35 | int i, x, y, r, g, b; 36 | int cols[3][255]; 37 | double c; 38 | 39 | initwindow (600, 600); 40 | 41 | for (i = 0; i < 255; i++) { 42 | cols[0][i] = (int) fabs( (128. - 127. * sin ((double) i * PI / 32.0))); 43 | cols[1][i] = (int) fabs( (128. - 127. * sin ((double) i * PI / 64.))); 44 | cols[2][i] = (int) fabs( (128. - 127. * sin ((double) i * PI / 128.))); 45 | } 46 | 47 | for (y = 0; y < getmaxy (); y++) { 48 | for (x = 0; x < getmaxx (); x++) { 49 | c = (sin(x/35.)*128. + sin(y/28.)*32. + sin((x+y)/16.)*64.); 50 | if (c > 255) 51 | c = c - 256; 52 | if (c < 0) 53 | c = 256 + c; 54 | r = cols[0][(int)c]; 55 | if (r > 255) 56 | r = r - 256; 57 | if (r < 0) 58 | r = 256 + c; 59 | g = cols[1][(int)c]; 60 | if (g > 255) 61 | g = g - 256; 62 | if (g < 0) 63 | g = 256 + c; 64 | b = cols[2][(int)c]; 65 | if (b > 255) 66 | b = b - 256; 67 | if (b < 0) 68 | b = 256 + c; 69 | putpixel(x, y, COLOR(r, g, b)); 70 | } 71 | } 72 | refresh (); 73 | getch (); 74 | writeimagefile ("plasma.bmp", 0, 0, 599, 599); 75 | 76 | closegraph (); 77 | return 0; 78 | 79 | } 80 | 81 | // ----- end of file plasma.c 82 | -------------------------------------------------------------------------------- /demo/plasma.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | plasma.py: writes the window contents to a `.bmp` file. 5 | By Guido Gonzato, September 2022. 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | """ 21 | 22 | try: 23 | from numpy import * # matrix support 24 | except ModuleNotFoundError or ImportError: 25 | print ("Sorry, this program needs Numpy.") 26 | quit () 27 | 28 | from sdl_bgi import * 29 | from math import * 30 | 31 | PI = 3.141593 32 | 33 | # int i, x, y, r, g, b 34 | cols = empty ((3, 256)) 35 | 36 | initwindow (600, 600) 37 | 38 | for i in range (255): 39 | cols[0][i] = abs( (128. - 127. * sin (i * PI / 32.0))) 40 | cols[1][i] = abs( (128. - 127. * sin (i * PI / 64.))) 41 | cols[2][i] = abs( (128. - 127. * sin (i * PI / 128.))) 42 | 43 | for y in range (getmaxy ()): 44 | for x in range (getmaxx()): 45 | c = (sin(x/35.)*128. + sin(y/28.)*32. + sin((x+y)/16.)*64.) 46 | if (c > 255): 47 | c = c - 256 48 | if (c < 0): 49 | c = 256 + c 50 | r = cols[0][int (c)] 51 | if (r > 255): 52 | r = r - 256 53 | if (r < 0): 54 | r = 256 + c 55 | g = cols[1][int (c)] 56 | if (g > 255): 57 | g = g - 256 58 | if (g < 0): 59 | g = 256 + c 60 | b = cols[2][int (c)] 61 | if (b > 255): 62 | b = b - 256 63 | if (b < 0): 64 | b = 256 + c 65 | putpixel (x, y, COLOR(r, g, b)) 66 | 67 | refresh () 68 | getch () 69 | writeimagefile ("plasma.bmp", 0, 0, 599, 599) 70 | closegraph () 71 | 72 | # ----- end of file plasma.py 73 | -------------------------------------------------------------------------------- /demo/rgbpalette.c: -------------------------------------------------------------------------------- 1 | /* palette.c -*- C -*- 2 | * 3 | * To compile: 4 | * gcc -o rgbpalette rgbpalette.c -lSDL_bgi -lSDL2 5 | * 6 | * Shows how to save, redefine, and restore colours in the ARGB palette. 7 | * 8 | * By Guido Gonzato, September 2021. 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 | * 24 | */ 25 | 26 | #include 27 | 28 | #define MAX 100 29 | 30 | int main (int argc, char *argv[]) 31 | { 32 | int 33 | i; 34 | 35 | struct rgbpalettetype 36 | palette; 37 | 38 | // you must allocate space for colors 39 | palette.colors = calloc (MAX, sizeof (Uint32)); 40 | if (NULL == palette.colors) { 41 | fprintf (stderr, "Cannot allocate colours\n"); 42 | exit (1); 43 | } 44 | 45 | initwindow (500, 250); 46 | sdlbgislow (); 47 | setbkcolor (BLACK); 48 | cleardevice (); 49 | 50 | // set MAX hues of blue in the RGB palette 51 | for (i = 0; i < MAX; i++) 52 | setrgbpalette (i, 0, 0, 10 + i*2); 53 | 54 | // show the colours 55 | setcolor (WHITE); 56 | outtextxy (250, 100, "Here are 100 shades of blue"); 57 | for (i = 0; i < MAX; i++) { 58 | setrgbcolor (i); 59 | setfillstyle (SOLID_FILL, RGBPALETTE (i)); 60 | bar (10, 10, 200, 200); 61 | delay (20); 62 | } 63 | 64 | // save the ARGB palette 65 | setcolor (WHITE); 66 | outtextxy (250, 120, "Saving the ARGB palette..."); 67 | delay (2000); 68 | getrgbpalette (&palette, MAX); 69 | cleardevice (); 70 | 71 | // reset ARGB colours to gray 72 | for (i = 0; i < MAX; i++) 73 | setrgbpalette (i, 128, 128, 128); 74 | 75 | setcolor (WHITE); 76 | outtextxy (250, 100, "Grayed out ARGB colours..."); 77 | for (i = 0; i < MAX; i++) { 78 | setrgbcolor (i); 79 | setfillstyle (SOLID_FILL, RGBPALETTE (i)); 80 | bar (10, 10, 200, 200); 81 | delay (20); 82 | } 83 | 84 | // restore the ARGB palette 85 | setcolor (WHITE); 86 | outtextxy (250, 120, "Restoring the ARGB palette..."); 87 | delay (2000); 88 | setallrgbpalette (&palette); 89 | cleardevice (); 90 | 91 | setcolor (WHITE); 92 | outtextxy (250, 100, "Restored ARGB colours"); 93 | for (i = 0; i < MAX; i++) { 94 | setrgbcolor (i); 95 | setfillstyle (SOLID_FILL, RGBPALETTE (i)); 96 | bar (10, 10, 200, 200); 97 | delay (20); 98 | } 99 | setcolor (WHITE); 100 | outtextxy (250, 120, "Press a key to exit"); 101 | 102 | getch (); 103 | closegraph (); 104 | 105 | } 106 | 107 | // ----- end of file rgbpalette.c 108 | -------------------------------------------------------------------------------- /demo/rgbpalette.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | rgbpalette.py: Shows how to save, redefine, and restore colours in the 5 | ARGB palette. 6 | 7 | By Guido Gonzato, September 2022. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | """ 23 | 24 | from sdl_bgi import * 25 | 26 | def main (): 27 | 28 | MAX = 100 29 | 30 | palette = rgbpalettetype () 31 | # you must allocate space for colors 32 | col = create_string_buffer (MAX * sizeofint ()) 33 | palette.colors = addressof (col) 34 | palette.size = MAX 35 | 36 | initwindow (500, 250) 37 | sdlbgislow () 38 | setbkcolor (BLACK) 39 | cleardevice () 40 | 41 | # set MAX hues of blue in the RGB palette 42 | for i in range (MAX): 43 | setrgbpalette (i, 0, 0, 10 + i*2) 44 | 45 | # show the colours 46 | setcolor (WHITE) 47 | outtextxy (250, 100, "Here are 100 shades of blue") 48 | for i in range (MAX): 49 | setrgbcolor (i) 50 | setfillstyle (SOLID_FILL, RGBPALETTE (i)) 51 | bar (10, 10, 200, 200) 52 | delay (20) 53 | 54 | # save the ARGB palette 55 | setcolor (WHITE) 56 | outtextxy (250, 120, "Saving the ARGB palette...") 57 | delay (2000) 58 | getrgbpalette (palette, MAX) 59 | cleardevice () 60 | 61 | # reset ARGB colours to gray 62 | for i in range (MAX): 63 | setrgbpalette (i, 128, 128, 128) 64 | 65 | setcolor (WHITE) 66 | outtextxy (250, 100, "Grayed out ARGB colours...") 67 | for i in range (MAX): 68 | setrgbcolor (i) 69 | setfillstyle (SOLID_FILL, RGBPALETTE (i)) 70 | bar (10, 10, 200, 200) 71 | delay (20) 72 | 73 | # restore the ARGB palette 74 | setcolor (WHITE) 75 | outtextxy (250, 120, "Restoring the ARGB palette...") 76 | delay (2000) 77 | setallrgbpalette (palette) 78 | cleardevice () 79 | 80 | setcolor (WHITE) 81 | outtextxy (250, 100, "Restored ARGB colours") 82 | for i in range (MAX): 83 | setrgbcolor (i) 84 | setfillstyle (SOLID_FILL, RGBPALETTE (i)) 85 | bar (10, 10, 200, 200) 86 | delay (20) 87 | 88 | setcolor (WHITE) 89 | outtextxy (250, 120, "Press a key to exit") 90 | 91 | getch () 92 | closegraph () 93 | 94 | # ----- 95 | 96 | main () 97 | 98 | # ----- end of file rgbpalette.c 99 | -------------------------------------------------------------------------------- /demo/speedtest.md: -------------------------------------------------------------------------------- 1 | # Speedtest 2 | 3 | The following is a rough indicator of program speed using `fern`, 4 | compiled to native code, Python, and Wasm. 5 | 6 | msys2:~$ time ./fern.exe 7 | 8 | real 0m6.796s 9 | user 0m0.000s 10 | sys 0m0.000s 11 | 12 | msys2:~$ time ./fern.py 13 | 14 | real 4m32.474s 15 | user 0m0.000s 16 | sys 0m0.015s 17 | 18 | msys2:~$ start fern.html 19 | timed by hand: 25 seconds 20 | 21 | In general, native code is approx. 3 times faster than Wasm, 22 | and much, much faster than Python. 23 | -------------------------------------------------------------------------------- /demo/tccrun: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ $(uname) != "Linux" ] ; then 4 | echo "Sorry, GNU/Linux only!" 5 | exit 1 6 | fi 7 | 8 | if ! [ -x "$(command -v tcc)" ] ; then 9 | echo "Error: 'tcc' could not be found." >&2 10 | exit 1 11 | fi 12 | 13 | MYSELF=$(basename $0) 14 | 15 | if [ $# -eq 0 ] ; then 16 | printf "Usage: ${MYSELF} [arguments]\n" 17 | exit 1 18 | fi 19 | 20 | PROGRAM=$1 21 | shift 22 | ARGS=$@ 23 | # you may have to extend this variable to include "-lSDL2_image" 24 | SDL_BGI_OPTS="-I /usr/include/SDL2 -I. -lSDL_bgi -lSDL2" 25 | TCC_OPTS="-w -D SDL_DISABLE_IMMINTRIN_H" 26 | tcc -run $TCC_OPTS $SDL_BGI_OPTS $PROGRAM $ARGS 27 | 28 | # --- end of file tccrun 29 | -------------------------------------------------------------------------------- /doc/C.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/C.png -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for documentation 2 | 3 | # PDF engine for Pandoc: tested with 4 | # pdflatex, pdfroff, wkhtmltopdf, and weasyprint 5 | PDFENGINE = pdflatex 6 | OPTS = -V urlcolor=blue -V toccolor=red --pdf-engine=$(PDFENGINE) 7 | 8 | PDFDOCS = compatibility.pdf fonts.pdf functions.pdf howto_AppImage.pdf \ 9 | howto_CodeBlocks.pdf howto_Dev-Cpp.pdf howto_Emscripten.pdf \ 10 | howto_Python.pdf using.pdf 11 | 12 | HTMLDOCS = $(PDFDOCS:.pdf=.html) 13 | 14 | all: $(PDFDOCS) $(HTMLDOCS) 15 | echo $(HTMLDOCS) 16 | 17 | compatibility.pdf: compatibility.md 18 | pandoc $(OPTS) compatibility.md \ 19 | -o compatibility.pdf 20 | 21 | compatibility.html: compatibility.md 22 | pandoc compatibility.md \ 23 | -o compatibility.html 24 | 25 | fonts.pdf: fonts.md 26 | pandoc $(OPTS) fonts.md -o fonts.pdf 27 | 28 | fonts.html: fonts.md 29 | pandoc fonts.md -o fonts.html 30 | 31 | functions.pdf: functions.md 32 | pandoc $(OPTS) functions.md -o functions.pdf 33 | 34 | functions.html: functions.md 35 | pandoc functions.md -o functions.html 36 | 37 | howto_AppImage.pdf: howto_AppImage.md 38 | pandoc $(OPTS) howto_AppImage.md \ 39 | -o howto_AppImage.pdf 40 | 41 | howto_AppImage.html: howto_AppImage.md 42 | pandoc howto_AppImage.md \ 43 | -o howto_AppImage.html 44 | 45 | howto_CodeBlocks.pdf: howto_CodeBlocks.md 46 | pandoc $(OPTS) howto_CodeBlocks.md \ 47 | -o howto_CodeBlocks.pdf 48 | 49 | howto_CodeBlocks.html: howto_CodeBlocks.md 50 | pandoc howto_CodeBlocks.md \ 51 | -o howto_CodeBlocks.html 52 | 53 | howto_Dev-Cpp.pdf: howto_Dev-Cpp.md 54 | pandoc $(OPTS) howto_Dev-Cpp.md \ 55 | -o howto_Dev-Cpp.pdf 56 | 57 | howto_Dev-Cpp.html: howto_Dev-Cpp.md 58 | pandoc howto_Dev-Cpp.md \ 59 | -o howto_Dev-Cpp.html 60 | 61 | howto_Emscripten.pdf: howto_Emscripten.md 62 | pandoc $(OPTS) howto_Emscripten.md \ 63 | -o howto_Emscripten.pdf 64 | 65 | howto_Emscripten.html: howto_Emscripten.md 66 | pandoc howto_Emscripten.md \ 67 | -o howto_Emscripten.html 68 | 69 | howto_Python.pdf: howto_Python.md 70 | pandoc $(OPTS) howto_Python.md \ 71 | -o howto_Python.pdf 72 | 73 | howto_Python.html: howto_Python.md 74 | pandoc howto_Python.md \ 75 | -o howto_Python.html 76 | 77 | using.pdf: using.md 78 | pandoc $(OPTS) --toc \ 79 | using.md -o using.pdf 80 | 81 | using.html: using.md 82 | pandoc --toc \ 83 | using.md -o using.html 84 | 85 | # --- end of Makefile 86 | -------------------------------------------------------------------------------- /doc/Python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/Python.png -------------------------------------------------------------------------------- /doc/README.md: -------------------------------------------------------------------------------- 1 | # README.md 2 | 3 | Documentation in this directory: 4 | 5 | - Compatibility (`compatibility.md`) 6 | 7 | - About internal fonts (`fonts.md`) 8 | 9 | - Functions (`functions.md`) 10 | 11 | - How to compile SDL_bgi programs with Code-Blocks (`howto_CodeBlocks.md`) 12 | 13 | - How to compile SDL_bgi programs with Dev-C++ (`howto_Dev-Cpp.md`) 14 | 15 | - How to turn an `SDL_bgi` program to an AppImage (`making_AppImages.md`) 16 | 17 | - How to use `SDL_bgi` in Python programs (`howto_Python.md`) 18 | 19 | - SDL bgi Quick Reference (`sdl_bgi-quickref.tex`) 20 | 21 | - Turtle Graphics Quick Reference (`turtlegraphics.tex`) 22 | 23 | - Using SDL_bgi (`using.md`) 24 | 25 | - graphics.3.gz (GNU/Linux manpage) 26 | 27 | All `.md` (Markdown) files have been converted to PDF using `pandoc` 28 | and the default PDF engine (pdflatex). If you want to modify these 29 | files and convert them to PDF without a LaTeX installation, a good 30 | alternative is `pdfroff`, provided by the `groff` package: 31 | 32 | ``` 33 | pandoc --pdf-engine=pdfroff file.md -o file.pdf 34 | ``` 35 | 36 | Documents written in LaTeX are typeset with `pdflatex`. 37 | 38 | -------------------------------------------------------------------------------- /doc/SDL_bgi_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/SDL_bgi_logo.png -------------------------------------------------------------------------------- /doc/compatibility.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/compatibility.pdf -------------------------------------------------------------------------------- /doc/fonts.html: -------------------------------------------------------------------------------- 1 | 8 |

About internal fonts

9 |

Internal vector fonts have been decoded from original Borland CHR fonts and turned to arrays of coordinates; that is, glyphs.

10 |

I’m not aware of the legal status of the CHR fonts that accompanied Borland Turbo C and other compilers. Anyhow, even assuming that they are still copyrighted under U.S. law, their glyphs are not; please see this Wikipedia article for details. It is therefore legal to incorporate the glyphs of CHR fonts in SDL_bgi.

11 |

Fonts were taken from Borland Turbo C++ 3, available here, and converted using the ancillary program tmp/chr_decoder.c.

12 | -------------------------------------------------------------------------------- /doc/fonts.md: -------------------------------------------------------------------------------- 1 | --- 2 | header-includes: | 3 | \usepackage{libertine} 4 | \renewcommand{\ttdefault}{cmtt} 5 | ... 6 | 7 | 14 | 15 | # About internal fonts 16 | 17 | Internal vector fonts have been decoded from original Borland `CHR` 18 | fonts and turned to arrays of coordinates; that is, glyphs. 19 | 20 | I'm not aware of the legal status of the `CHR` fonts that accompanied 21 | Borland Turbo C and other compilers. Anyhow, even assuming that they 22 | are still copyrighted under U.S. law, their glyphs are not; please see 23 | [this Wikipedia article](https://en.wikipedia.org/wiki/Intellectual_property_protection_of_typefaces) 24 | for details. It is therefore legal to incorporate the glyphs of `CHR` 25 | fonts in `SDL_bgi`. 26 | 27 | Fonts were taken from Borland Turbo C++ 3, available 28 | [here](https://archive.org/details/turboc3), and converted using the 29 | ancillary program `tmp/chr_decoder.c`. 30 | -------------------------------------------------------------------------------- /doc/fonts.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/fonts.pdf -------------------------------------------------------------------------------- /doc/functions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/functions.pdf -------------------------------------------------------------------------------- /doc/graphics.3.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/graphics.3.gz -------------------------------------------------------------------------------- /doc/howto_AppImage.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/howto_AppImage.pdf -------------------------------------------------------------------------------- /doc/howto_CodeBlocks.md: -------------------------------------------------------------------------------- 1 | --- 2 | header-includes: | 3 | \usepackage{libertine} 4 | \renewcommand{\ttdefault}{cmtt} 5 | ... 6 | 7 | 14 | 15 | # How to compile `SDL_bgi` programs with CodeBlocks 16 | 17 | These instructions show how to compile an `SDL_bgi` program using 18 | CodeBlocks; we will use `fern.c`, provided in the `demo/` directory. 19 | 20 | Let's assume that CodeBlocks is installed in `C:\CodeBlocks`, and that 21 | the SDL2 development libraries for MinGW are installed in 22 | `C:\SDL2-*`. If you installed the software in different 23 | directories, change the following instructions accordingly. 24 | 25 | The procedure was tested with CodeBlocks 20.03 and 26 | SDL2-devel-2.24.2-mingw.tar.gz. 27 | 28 | Links: 29 | 30 | 31 | 32 | 33 | 34 | 35 | ## Installing `SDL_bgi` 36 | 37 | - copy `bin/CodeBlocks/SDL_bgi.dll` to\ 38 | `C:\CodeBlocks\MinGW\bin` 39 | 40 | - copy `SDL_bgi.h` to\ 41 | `C:\SDL2-*\x86_64-w64-mingw32\include\SDL2` 42 | 43 | - copy `graphics.h` to\ 44 | `C:\SDL2-*\x86_64-w64-mingw32\include` 45 | 46 | 47 | ## How to compile 48 | 49 | - start CodeBlocks and click on `Create a new project` 50 | 51 | - click on `SDL2 project`, then proceed 52 | 53 | - in the wizard, provide a project name (`fern`), pick a folder to 54 | store the project, then click on `Next>` 55 | 56 | - in the next window (SDL2 location), pick 57 | `C:\SDL2-*\x86_64-w64-mingw32`, then click on `Next>` 58 | 59 | - in the next window, uncheck `Create "Debug" configuration`, check 60 | `Create "Release" configuration`, then click on `Finish` 61 | 62 | - in the panel `Projects/Workspace/fern/Sources`, delete `main.cpp` 63 | (Remove file from project) 64 | 65 | - in the panel `Projects/Workspace/fern`: right click, click on 66 | `Add files...`, pick `fern.c`, then click on `Ok` 67 | 68 | - from the menu `Project/Build options...` select the `Search 69 | directories` tab, click on `Add`, pick the directory\ 70 | `C:\SDL2-*\x86_64-w64-mingw32\include`, then select `No` when 71 | asked to `Keep this as a relative path?`. Click on `Ok` 72 | 73 | - from the menu `Project/Build options...` select the `Linker 74 | settings` tab, click on `Add`, pick the files\ 75 | `C:\CodeBlocks\MinGW\bin\SDL_bgi.dll` and\ 76 | `C:\SDL2-*\x86_64-w64-mingw32\bin\SDL2.dll`, then select 77 | `No` when asked to `Keep this as a relative path?`. Click on `Ok` 78 | 79 | - from the menu `Build`, select `Build`. The executable `fern.exe` 80 | will be compiled. 81 | 82 | - if you don't need to set environment variables, close the\ 83 | `Global variable editor` window 84 | 85 | - run `fern.exe`. 86 | 87 | 88 | **Note 1**: if you release your compiled program, you must 89 | also provide `SDL2.dll` and `SDL_bgi.dll` in the same directory. 90 | 91 | **Note 2**: if your code uses functions provided by `stdio.h` (e.g. 92 | `printf()`, `scanf()`, etc.) you must also run a terminal. From the 93 | menu `"Project/Set program's arguments...`, check the box `Run host in 94 | terminal`. 95 | 96 | 97 | []: # Absurdly complicated. Give me a command line anytime. 98 | -------------------------------------------------------------------------------- /doc/howto_CodeBlocks.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/howto_CodeBlocks.pdf -------------------------------------------------------------------------------- /doc/howto_Dev-Cpp.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/howto_Dev-Cpp.pdf -------------------------------------------------------------------------------- /doc/howto_Emscripten.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/howto_Emscripten.pdf -------------------------------------------------------------------------------- /doc/howto_Python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/howto_Python.pdf -------------------------------------------------------------------------------- /doc/sdl_bgi-quickref.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/sdl_bgi-quickref.pdf -------------------------------------------------------------------------------- /doc/turtlegraphics.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/turtlegraphics.pdf -------------------------------------------------------------------------------- /doc/using.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/doc/using.pdf -------------------------------------------------------------------------------- /icon.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/icon.bmp -------------------------------------------------------------------------------- /mkpkg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script builds .deb and/or .rpm packages 4 | # on GNU/Linux 5 | 6 | if [ $(uname) != "Linux" ] ; then 7 | echo "This script is for GNU/Linux only." 8 | exit 1 9 | fi 10 | 11 | VERSION=$(cat VERSION) 12 | 13 | mkdir -p build && cd build/ 14 | cmake -DCMAKE_INSTALL_PREFIX=/usr .. 15 | PACKAGE_DONE=0 16 | 17 | # is this system .deb based? 18 | DEB=$(which dpkg 2> /dev/null) 19 | if [ $? = 0 ] ; then 20 | DEB_ARCH=$(dpkg --print-architecture) 21 | printf "\n*** This system looks Debian-based.\n\n" 22 | cpack -G "DEB" .. 23 | DEB_NAME="sdl_bgi_"$VERSION"-1_"$DEB_ARCH".deb" 24 | /bin/mv *deb $DEB_NAME 25 | printf "\n*** Package $DEB_NAME created in subdirectory build/.\n\n" 26 | PACKAGE_DONE=1 27 | fi 28 | 29 | # is this system .rpm based? 30 | RPM=$(which rpm 2> /dev/null) 31 | if [ $? = 0 ] ; then 32 | RPM_ARCH=$(uname -m) 33 | printf "\n*** This system looks RPM-based.\n\n" 34 | cpack -G "RPM" .. 35 | RPM_NAME="SDL_bgi-"$VERSION"-1."$RPM_ARCH".rpm" 36 | /bin/mv *rpm $RPM_NAME 37 | printf "\n*** Package $RPM_NAME created in subdirectory build/.\n\n" 38 | PACKAGE_DONE=1 39 | fi 40 | 41 | if [ $PACKAGE_DONE = 0 ] ; then 42 | printf "\n*** I don't know what package to build.\n\n" 43 | fi 44 | -------------------------------------------------------------------------------- /pypi/LICENSE: -------------------------------------------------------------------------------- 1 | // ZLib License 2 | 3 | Copyright (c) 2014-2021 Guido Gonzato, PhD 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | 21 | -------------------------------------------------------------------------------- /pypi/pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | 3 | name = "sdl_bgi" 4 | version = "3.0.0" 5 | description = "SDL2-based 'GRAPHICS.H' implementation" 6 | authors = [ 7 | { name="Guido Gonzato, PhD", email="guido.gonzato@gmail.com" }, 8 | ] 9 | readme = "README.md" 10 | license = {file = "LICENSE"} 11 | requires-python = ">=3.8" 12 | 13 | classifiers = [ 14 | "Programming Language :: Python :: 3", 15 | "Topic :: Software Development :: Libraries :: Python Modules", 16 | "Intended Audience :: Developers", 17 | "Intended Audience :: Education", 18 | "License :: OSI Approved :: zlib/libpng License", 19 | "Operating System :: OS Independent" 20 | ] 21 | 22 | keywords = ["GRAPHICS.H", "BGI", "SDL2"] 23 | 24 | [project.urls] 25 | "Homepage" = "https://sdl-bgi.sourceforge.io/" 26 | 27 | [build-system] 28 | requires = ["hatchling"] 29 | build-backend = "hatchling.build" 30 | 31 | -------------------------------------------------------------------------------- /pypi/src/sdl_bgi/__init__.py: -------------------------------------------------------------------------------- 1 | # module sdl_bgi.py 2 | 3 | """ 4 | ZLib License 5 | 6 | Copyright (c) 2014-2022 Guido Gonzato, PhD 7 | 8 | This software is provided 'as-is', without any express or implied 9 | warranty. In no event will the authors be held liable for any damages 10 | arising from the use of this software. 11 | 12 | Permission is granted to anyone to use this software for any purpose, 13 | including commercial applications, and to alter it and redistribute it 14 | freely, subject to the following restrictions: 15 | 16 | 1. The origin of this software must not be misrepresented; you must not 17 | claim that you wrote the original software. If you use this software 18 | in a product, an acknowledgment in the product documentation would be 19 | appreciated but is not required. 20 | 2. Altered source versions must be plainly marked as such, and must not be 21 | misrepresented as being the original software. 22 | 3. This notice may not be removed or altered from any source distribution 23 | """ 24 | 25 | __doc__ = """ 26 | `SDL_bgi` is a graphics library (`GRAPHICS.H`) for C, C++, WebAssembly, 27 | and Python. It's based on SDL2 and it's portable on many platforms. 28 | 29 | Its name refers to BGI, the Borland Graphics Interface that was the 30 | 'de facto' standard in PC graphics back in DOS days; it was made 31 | popular by Borland Turbo C/C++ compilers. I wrote `SDL_bgi` because I 32 | wanted a simple to use but fast graphics library for my experiments 33 | with fractals and cellular automata, using the BGI syntax I'm used to. 34 | 35 | `SDL_bgi` is functionally compatible with the BGI implementation in 36 | Turbo C 2.01 and Borland C++ 1.0; for instance, it compiles and runs 37 | the original `bgidemo.c`. `SDL_bgi` also provides nearly full 38 | compatibility with another BGI implementation, WinBGIm (see links 39 | below). One of the aims of `SDL_bgi` is the preservation of old 40 | software written for BGI; but not only that. 41 | 42 | `SDL_bgi` provides graphics primitives, and is much easier to use than 43 | plain SDL2; it should be especially useful for beginners, i.e. in 44 | introductory programming courses. `SDL_bgi` is pretty fast, and in 45 | addition to BGI compatibility it provides extensions for ARGB colours, 46 | mouse support, vector fonts, and multiple windows. Native SDL2 47 | functions can be used alongside `SDL_bgi` functions. `SDL_bgi` can 48 | also be used in programs written in C++ or Python. 49 | 50 | `SDL_bgi` is written in C, and it should compile on any platform 51 | supported by SDL2; it has been tested on GNU/Linux, MS Windows (MSYS2 52 | + Mingw-w64, CodeBlocks, Dev-C++), macOS (High Sierra and Catalina), 53 | Raspios (ARM, i386), and WebAssembly (Emscripten). A few example 54 | programs are provided in the `test/` directory. 55 | """ 56 | 57 | from .sdl_bgi import * 58 | 59 | # --- end of file __init__.py 60 | -------------------------------------------------------------------------------- /pypi/test/boo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | boo.py: shows how to make a window transparent and change some of its 5 | properties. 6 | 7 | By Guido Gonzato, September 2022. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | """ 23 | 24 | from sdl_bgi import * 25 | 26 | try: 27 | from sdl2 import * 28 | except: 29 | print ("Sorry, I need the sdl2 module.") 30 | exit () 31 | 32 | boo = "BOOO!" 33 | stop = 0 34 | 35 | # physical screen size, regardless of window dimensions 36 | x, y = getscreensize () 37 | 38 | setwinoptions ("", SDL_WINDOWPOS_CENTERED, 39 | SDL_WINDOWPOS_CENTERED, SDL_WINDOW_BORDERLESS) 40 | initwindow (32 * len (boo), 32) # 4 times the usual size 41 | setbkcolor (BLACK) 42 | cleardevice () 43 | winid = getcurrentwindow () 44 | 45 | # make the window opaque 46 | SDL_SetWindowOpacity (bgi_window, 1.0) 47 | setcolor (RED) 48 | settextstyle (DEFAULT_FONT, HORIZ_DIR, 4) 49 | outtextxy (0, 0, boo) 50 | refresh () 51 | 52 | while (stop != 1): 53 | 54 | stop = edelay (random (1000)) 55 | if (stop): 56 | break 57 | 58 | # make the window transparent (disappear) 59 | SDL_SetWindowOpacity (bgi_window, 0.0) 60 | refresh () 61 | stop = edelay (random (1500)) 62 | 63 | # opaque again - reappear 64 | resetwinoptions (winid, "", random (x), random (y)) 65 | SDL_SetWindowOpacity (bgi_window, 1.0) 66 | refresh () 67 | 68 | closegraph () 69 | 70 | # ----- end of file boo.py 71 | -------------------------------------------------------------------------------- /pypi/test/buffers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | buffers.py: getbuffer() / putbuffer() demonstration. 5 | This program is equivalent to 'buffers_numpy.py', but it does not use 6 | matrix and vector facilities provided by Numpy. 7 | 8 | By Guido Gonzato, September 2022. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 | """ 24 | 25 | from sdl_bgi import * 26 | 27 | WIDTH = 256 28 | HEIGHT = 256 29 | SIZE = WIDTH * HEIGHT * sizeofint () 30 | 31 | """ 32 | These are byte buffers, i.e. one-dimensional 'arrays'. 33 | Function create_string_buffer() is provided by ctypes. 34 | """ 35 | 36 | red = create_string_buffer (SIZE) 37 | tmp = create_string_buffer (SIZE) 38 | hues = create_string_buffer (SIZE) 39 | 40 | # ----- 41 | 42 | def bufferxy (buf, width, x, y, value): 43 | """ 44 | Given a byte buffer 'buf 'simulating an array of 'width' 45 | columns, set (x, y) element as 'value'. 46 | """ 47 | # bytes, from lowest to highest 48 | SOI = sizeofint () 49 | vtb = value.to_bytes (4, 'little') 50 | for j in range (SOI): 51 | buf [y * width * SOI + x + j] = vtb[j] 52 | 53 | # ----- 54 | 55 | # initialise the buffers 56 | for y in range (HEIGHT): 57 | for x in range (0, WIDTH * sizeofint (), 4): 58 | """ 59 | each value in 'x' must have room for a C integer, given by 60 | sizeof (int): 4 bytes. Therefore, the real 'x' column is 61 | given by x // 4. 62 | """ 63 | bufferxy (red, WIDTH, x, y, 0xffff0000) 64 | bufferxy (hues, WIDTH, x, y, colorRGB (x//4, y, abs ((x//4) - y))) 65 | 66 | setwinoptions ("Using putbuffer()", -1, -1, -1) 67 | initwindow (WIDTH, HEIGHT) 68 | setcolor (BLACK) 69 | setbkcolor (WHITE) 70 | cleardevice () 71 | outtextxy (0, 0, "Click to continue:") 72 | refresh () 73 | 74 | getclick () 75 | putbuffer (red) 76 | 77 | getbuffer (tmp) # tmp == red 78 | setcolor (WHITE) 79 | outtextxy (0, 0, "Left click to continue:") 80 | refresh () 81 | getclick () 82 | 83 | for alpha in range (128): 84 | 85 | for n in range (0, SIZE, 4): 86 | hues[n + 3] = 0x00 | alpha # set color alpha 87 | 88 | putbuffer (tmp) # red screen 89 | putbuffer (hues) # hues + alpha on red 90 | refresh () 91 | delay (10) 92 | 93 | outtextxy (0, 0, "Left click to finish:") 94 | refresh () 95 | getclick () 96 | 97 | closegraph () 98 | 99 | # ----- end of file buffers.py 100 | -------------------------------------------------------------------------------- /pypi/test/buffers_numpy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | buffers_numpy.py: getbuffer() / putbuffer() demonstration. This 5 | version uses Numpy; please see 'buffers.py' for a Numpy-less version. 6 | 7 | By Guido Gonzato, September 2022. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | """ 23 | 24 | try: 25 | from numpy import * # matrix support 26 | except ModuleNotFoundError or ImportError: 27 | print ("Sorry, this program needs Numpy.") 28 | quit () 29 | 30 | from sdl_bgi import * 31 | 32 | # ----- 33 | 34 | WIDTH = 256 35 | HEIGHT = 256 36 | SIZE = WIDTH * HEIGHT * sizeofint () 37 | 38 | # plain 'int' raises overflow error 39 | red = empty ((WIDTH, HEIGHT), dtype=int64) 40 | hues = empty ((WIDTH, HEIGHT), dtype=int64) 41 | 42 | # initialise the buffers 43 | for y in range (HEIGHT): 44 | for x in range (WIDTH): 45 | # fill the red buffer with 0xffff0000 46 | red [x, y] = 0xffff0000 47 | # fill the hues buffer with colorRGB (x, y, abs (x - y)) 48 | hues [x, y] = colorRGB (x, y, abs (x - y)) 49 | 50 | setwinoptions ("Using putbuffer()", -1, -1, -1) 51 | initwindow (WIDTH, HEIGHT) 52 | setcolor (BLACK) 53 | setbkcolor (WHITE) 54 | cleardevice () 55 | outtextxy (0, 0, "Click to continue:") 56 | refresh () 57 | getclick () 58 | 59 | # create a buffer for 'red' array 60 | b_red = vec2buf (reshape (red, -1)) 61 | putbuffer (b_red) 62 | refresh () 63 | 64 | # create a temporary buffer 65 | b_tmp = vec2buf (reshape (red, -1)) 66 | getbuffer (b_tmp) # b_tmp == red 67 | setcolor (WHITE) 68 | outtextxy (0, 0, "Left click to continue:") 69 | refresh () 70 | getclick () 71 | # create a buffer for 'hues' array 72 | b_hues = vec2buf (reshape (hues, -1)) 73 | 74 | for alpha in range (128): 75 | 76 | for n in range (0, SIZE, 4): 77 | b_hues[n + 3] = 0x00 | alpha # set color alpha 78 | 79 | putbuffer (b_tmp) # red screen 80 | putbuffer (b_hues) # hues + alpha on red 81 | refresh () 82 | delay (10) 83 | 84 | outtextxy (0, 0, "Left click to finish:") 85 | refresh () 86 | getclick () 87 | 88 | closegraph () 89 | 90 | # ----- end of file buffers.py 91 | -------------------------------------------------------------------------------- /pypi/test/fern.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | fern.py: a famous IFS system. 5 | 6 | By Guido Gonzato, September 2022. 7 | 8 | This program is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 2 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | """ 22 | 23 | from sdl_bgi import * 24 | 25 | gd = DETECT 26 | gm = SDL_800x600 27 | 28 | stop = 0 29 | counter = 0 30 | # midx, midy, scale 31 | # int k = 0, prob 32 | # float x, y, xx, yy 33 | 34 | a = [0.0, 0.85, 0.2, -0.15] 35 | b = [0.0, 0.04, -0.26, 0.28] 36 | c = [0.0, 0.04, 0.23, 0.26] 37 | d = [0.16, 0.85, 0.22, 0.24] 38 | e = [0.0, 0.0, 0.0, 0.0] 39 | f = [0.0, 1.6, 1.6, 0.44] 40 | 41 | setwinoptions ("This is a fractal fern", -1, -1, -1) 42 | initgraph (gd, gm, "") 43 | setbkcolor (COLOR (0, 0, 40)) 44 | cleardevice () 45 | setcolor (YELLOW) 46 | outtextxy (0, 0, "Press a key to exit: ") 47 | 48 | midx = getmaxx () / 2 49 | midy = getmaxy () / 2 50 | scale = getmaxx () / 16 51 | x = 0.0 52 | y = 0.0 53 | setcolor (COLOR (random (256), random (256), random (256))) 54 | 55 | # kbhit (), mouseclick () and event () are slow. Use them sparingly. 56 | 57 | while (stop != 1): 58 | 59 | prob = 1 + random (100) 60 | if (prob == 1): 61 | k = 0 62 | if ( (prob > 1) and (prob < 87)): 63 | k = 1 64 | if ( (prob > 86) and (prob < 94)): 65 | k = 2 66 | if (prob > 93): 67 | k = 3 68 | # to use equal probability, just use: 69 | # k = random (5) 70 | 71 | xx = a[k] * x + b[k] * y # + e[k] 72 | yy = c[k] * x + d[k] * y + f[k] 73 | x = xx 74 | y = yy 75 | 76 | fputpixel ((int)(midx + scale * x), (int)(2 * midy - scale * y)) 77 | counter = counter + 1 78 | 79 | if (0 == (counter % 100000)): 80 | setcolor (COLOR (random (256), random (256), random (256))) 81 | refresh () 82 | if (kbhit ()): 83 | stop = 1 84 | 85 | if (100000000 == counter): # 100 million pixels 86 | break 87 | 88 | setcolor (GREEN) 89 | outtextxy (0, 10, "Ok, leaving in 2 seconds") 90 | delay (2000) 91 | closegraph () 92 | 93 | # ----- end of file fern.py ----- 94 | -------------------------------------------------------------------------------- /pypi/test/floodfilltest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | By Guido Gonzato, September 2022. 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | """ 20 | 21 | from sdl_bgi import * 22 | 23 | stop = False 24 | 25 | initwindow (800, 600) 26 | setbkcolor (BLACK) 27 | setcolor (RED) 28 | cleardevice () 29 | settextjustify (CENTER_TEXT, CENTER_TEXT) 30 | 31 | outtextxy (getmaxx() / 2, getmaxy () / 2 - 15, 32 | "Left click to draw a random circle") 33 | outtextxy (getmaxx() / 2, getmaxy () / 2, 34 | "right click to fill") 35 | outtextxy (getmaxx() / 2, getmaxy () / 2 + 15, 36 | "press a key to exit.") 37 | 38 | getevent () 39 | 40 | cleardevice () 41 | setcolor (YELLOW) 42 | refresh () 43 | 44 | while (stop != True): 45 | 46 | mclick = getevent () 47 | 48 | if (WM_LBUTTONDOWN == mclick): 49 | setcolor (YELLOW) 50 | circle (mousex (), mousey (), 10 + random (100)) 51 | refresh () 52 | 53 | if (WM_RBUTTONDOWN == mclick): 54 | setcolor (random (MAXCOLORS)) 55 | setfillstyle (1 + random(USER_FILL), 56 | COLOR (random (255), random (255), random (255))) 57 | floodfill (mousex (), mousey (), YELLOW) 58 | refresh () 59 | 60 | if (KEY_ESC == mclick): 61 | stop = True 62 | 63 | closegraph () 64 | 65 | # ----- end of file floodfilltest.py 66 | -------------------------------------------------------------------------------- /pypi/test/hopalong.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | hopalong.py: an implementation of Barry Martin's algorithm. 5 | By Guido Gonzato, September 2022. 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | """ 21 | 22 | from sdl_bgi import * 23 | from math import sqrt 24 | from random import seed 25 | from sys import argv 26 | 27 | def sgn(n): 28 | if (n < 0): 29 | return -1 30 | else: 31 | return 1 32 | 33 | # ----- 34 | 35 | def main (args): 36 | 37 | if (len (args) == 1): 38 | s = 1922 39 | else: 40 | s = int (argv[1]) 41 | 42 | seed (s) 43 | gd = DETECT 44 | gm = getmaxmode () 45 | initgraph(gd, gm, "") 46 | 47 | setbkcolor (BLACK) 48 | cleardevice () 49 | setcolor (YELLOW) 50 | outtextxy (0, 0, "Press a key or click to exit: ") 51 | 52 | xoffs = getmaxx () / 2 53 | yoffs = getmaxy () / 2 54 | j = random (100) 55 | k = random (100) 56 | x = y = xx = xp = yp = r = 0.0 57 | stop, counter = 0, 0 58 | setcolor (COLOR (random (256), random (256), random (256))) 59 | 60 | while (stop != 1): 61 | xx = y - sgn (x) * sqrt (abs (k * x - 1)) 62 | y = j - x 63 | x = xx 64 | xp = x * 2 + xoffs 65 | yp = y * 2 + yoffs 66 | fputpixel (xp, yp) 67 | counter += 1 68 | if counter == 50000: 69 | refresh () 70 | counter = 0 71 | setcolor (COLOR (random (256), random (256), random (256))) 72 | refresh () 73 | if ismouseclick (WM_LBUTTONDOWN) or kbhit (): 74 | stop = 1 75 | 76 | closegraph () 77 | if (SDL_KEYDOWN == eventtype ()): 78 | print ("Key pressed.") 79 | else: 80 | print ("Mouse clicked.") 81 | 82 | # ----- 83 | 84 | if __name__ == '__main__': 85 | main (argv) 86 | 87 | 88 | # ----- end of file hopalong.py 89 | -------------------------------------------------------------------------------- /pypi/test/minimal.py: -------------------------------------------------------------------------------- 1 | # run with: python minimal.py 2 | 3 | from sdl_bgi import * 4 | 5 | gd, gm = DETECT, 0 6 | initgraph (gd, gm, "") 7 | setbkcolor (BLACK) 8 | cleardevice () 9 | outtextxy (0, 0, "Drawing 1000 lines...") 10 | for i in range (1000): 11 | setcolor (1 + random (15)) 12 | line (random(getmaxx()), random(getmaxy()), 13 | random (getmaxx()), random(getmaxy())) 14 | getch () 15 | closegraph () 16 | -------------------------------------------------------------------------------- /pypi/test/multiwin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | multiwin.py: shows how to open multiple windows. 5 | By Guido Gonzato, September 2022. 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | """ 21 | 22 | from sdl_bgi import * 23 | 24 | gd = DETECT 25 | gm = SDL_320x200 26 | 27 | setwinoptions ("First Window", 10, 10, -1) 28 | initgraph (gd, gm, "") 29 | cleardevice () 30 | outtextxy (0, 0, "Click or press a key for a SECOND window") 31 | circle (50, 100, 50) 32 | win1 = getcurrentwindow () 33 | print ("Current window: %d" % win1) 34 | x = getmaxx () - 110 35 | y = getmaxy () - 60 36 | readimagefile ("./logo.bmp", x, y, x + 100, y + 50) 37 | getevent () 38 | delay (500) 39 | 40 | setwinoptions ("Second Window", 10, 200 + 50, -1) 41 | initgraph (gd, gm, "") 42 | cleardevice () 43 | setcolor (RED) 44 | outtextxy (0, 0, "Click or press a key for a THIRD window") 45 | circle (100, 100, 50) 46 | win2 = getcurrentwindow () 47 | print ("Current window: %d" % win2) 48 | readimagefile ("./logo.bmp", x, y, x + 100, y + 50) 49 | getevent () 50 | delay (500) 51 | 52 | setwinoptions ("Third Window", 320 + 50, 10, -1) 53 | initwindow (640, 480) 54 | cleardevice () 55 | setcolor (GREEN) 56 | outtextxy (0, 0, "Press a key to switch back to the FIRST window") 57 | circle (150, 100, 50) 58 | win3 = getcurrentwindow () 59 | print ("Current window: %d" % win3) 60 | x = getmaxx () - 110 61 | y = getmaxy () - 60 62 | readimagefile ("./logo.bmp", x, y, x + 100, y + 50) 63 | getevent () 64 | delay (500) 65 | 66 | setcurrentwindow (win1) 67 | setcolor (WHITE) 68 | circle (150, 100, 50) 69 | win1 = getcurrentwindow () 70 | print ("Current window: %d" % win1) 71 | setcolor (YELLOW) 72 | outtextxy (0, 10, "Back to the FIRST window press a key") 73 | getevent () 74 | setcolor (RED) 75 | outtextxy (0, 20, "Shutting down...") 76 | 77 | setwintitle (win3, "Window 3 is shutting down...") 78 | delay (2000) 79 | print ("Shutting down window %d" % win3) 80 | closewindow (win3) 81 | 82 | setwintitle (win2, "Window 2 is shutting down...") 83 | delay (2000) 84 | print ("Shutting down window %d" % win2) 85 | closewindow (win2) 86 | 87 | setwintitle (win1, "Window 1 is shutting down...") 88 | delay (2000) 89 | print ("Shutting down window %d" % win1) 90 | closewindow (win1) 91 | 92 | # ----- end of file multiwin.py 93 | -------------------------------------------------------------------------------- /pypi/test/pdj.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | pdj.py: plots Peter de Jong attractors. 5 | By Guido Gonzato, September 2022. 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | """ 21 | 22 | from sdl_bgi import * 23 | from math import * 24 | 25 | def create_palette (): 26 | 27 | # blue fading to white 28 | for x in range (256): 29 | setrgbpalette (x, x, x, 255) # end at 255,255,255 30 | 31 | # white fading to red 32 | for x in range (256): 33 | setrgbpalette (x + 256, 255, 255 - x, 255 - x) # end at 255,0,0 34 | 35 | # red fading to purple 36 | for x in range (256): 37 | setrgbpalette (x + 512, 255, 0, x) # end at 255,0,255 38 | 39 | # purple fading to blue 40 | for x in range (256): 41 | setrgbpalette (x + 768, 255 - x, 0, 255) # end at 0,0,255 42 | 43 | # ----- 44 | 45 | a = 1.641 46 | b = 1.902 47 | c = 0.316 48 | d = 1.525 49 | x = 0.0 50 | y = 0.0 51 | 52 | stop = False 53 | cnt = 0 54 | 55 | initwindow (800, 600) 56 | create_palette () 57 | xm = getmaxx () / 2 58 | ym = getmaxy () / 2 59 | ly = ym / 2 60 | # srand (time (NULL)) 61 | print ("a = %7.4f, b = %7.4f, c = %7.4f, d = %7.4f" % 62 | (a, b, c, d)) 63 | 64 | while (stop != True): 65 | 66 | xx = sin (a * y) - cos (b * x) 67 | yy = sin (c * x) - cos (d * y) 68 | 69 | color = cnt / 16384 70 | if color > 1024: 71 | cnt = 0 72 | color = 0 73 | 74 | setrgbcolor (color) 75 | fputpixel (xm + ly * xx, ym + ly * yy) 76 | x = xx 77 | y = yy 78 | 79 | cnt += 1 80 | if (0 == cnt % 5000): 81 | 82 | refresh () 83 | 84 | if (WM_LBUTTONDOWN == mouseclick ()): 85 | a = -4.0 + 8 * random (10000) / 10000.0 86 | b = -4.0 + 8 * random (10000) / 10000.0 87 | c = -4.0 + 8 * random (10000) / 10000.0 88 | d = -4.0 + 8 * random (10000) / 10000.0 89 | print ("a = %7.4f, b = %7.4f, c = %7.4f, d = %7.4f" % 90 | (a, b, c, d)) 91 | cleardevice () 92 | 93 | if kbhit (): 94 | stop = True 95 | break 96 | 97 | getch () 98 | closegraph () 99 | 100 | # ----- end of file pdj.py 101 | -------------------------------------------------------------------------------- /pypi/test/plasma.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | plasma.py: writes the window contents to a `.bmp` file. 5 | By Guido Gonzato, September 2022. 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | """ 21 | 22 | try: 23 | from numpy import * # matrix support 24 | except ModuleNotFoundError or ImportError: 25 | print ("Sorry, this program needs Numpy.") 26 | quit () 27 | 28 | from sdl_bgi import * 29 | from math import * 30 | 31 | PI = 3.141593 32 | 33 | # int i, x, y, r, g, b 34 | cols = empty ((3, 256)) 35 | 36 | initwindow (600, 600) 37 | 38 | for i in range (255): 39 | cols[0][i] = abs( (128. - 127. * sin (i * PI / 32.0))) 40 | cols[1][i] = abs( (128. - 127. * sin (i * PI / 64.))) 41 | cols[2][i] = abs( (128. - 127. * sin (i * PI / 128.))) 42 | 43 | for y in range (getmaxy ()): 44 | for x in range (getmaxx()): 45 | c = (sin(x/35.)*128. + sin(y/28.)*32. + sin((x+y)/16.)*64.) 46 | if (c > 255): 47 | c = c - 256 48 | if (c < 0): 49 | c = 256 + c 50 | r = cols[0][int (c)] 51 | if (r > 255): 52 | r = r - 256 53 | if (r < 0): 54 | r = 256 + c 55 | g = cols[1][int (c)] 56 | if (g > 255): 57 | g = g - 256 58 | if (g < 0): 59 | g = 256 + c 60 | b = cols[2][int (c)] 61 | if (b > 255): 62 | b = b - 256 63 | if (b < 0): 64 | b = 256 + c 65 | putpixel (x, y, COLOR(r, g, b)) 66 | 67 | refresh () 68 | getch () 69 | writeimagefile ("plasma.bmp", 0, 0, 599, 599) 70 | closegraph () 71 | 72 | # ----- end of file plasma.py 73 | -------------------------------------------------------------------------------- /pypi/test/rgbpalette.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | rgbpalette.py: Shows how to save, redefine, and restore colours in the 5 | ARGB palette. 6 | 7 | By Guido Gonzato, September 2022. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | """ 23 | 24 | from sdl_bgi import * 25 | 26 | def main (): 27 | 28 | MAX = 100 29 | 30 | palette = rgbpalettetype () 31 | # you must allocate space for colors 32 | col = create_string_buffer (MAX * sizeofint ()) 33 | palette.colors = addressof (col) 34 | palette.size = MAX 35 | 36 | initwindow (500, 250) 37 | sdlbgislow () 38 | setbkcolor (BLACK) 39 | cleardevice () 40 | 41 | # set MAX hues of blue in the RGB palette 42 | for i in range (MAX): 43 | setrgbpalette (i, 0, 0, 10 + i*2) 44 | 45 | # show the colours 46 | setcolor (WHITE) 47 | outtextxy (250, 100, "Here are 100 shades of blue") 48 | for i in range (MAX): 49 | setrgbcolor (i) 50 | setfillstyle (SOLID_FILL, RGBPALETTE (i)) 51 | bar (10, 10, 200, 200) 52 | delay (20) 53 | 54 | # save the ARGB palette 55 | setcolor (WHITE) 56 | outtextxy (250, 120, "Saving the ARGB palette...") 57 | delay (2000) 58 | getrgbpalette (palette, MAX) 59 | cleardevice () 60 | 61 | # reset ARGB colours to gray 62 | for i in range (MAX): 63 | setrgbpalette (i, 128, 128, 128) 64 | 65 | setcolor (WHITE) 66 | outtextxy (250, 100, "Grayed out ARGB colours...") 67 | for i in range (MAX): 68 | setrgbcolor (i) 69 | setfillstyle (SOLID_FILL, RGBPALETTE (i)) 70 | bar (10, 10, 200, 200) 71 | delay (20) 72 | 73 | # restore the ARGB palette 74 | setcolor (WHITE) 75 | outtextxy (250, 120, "Restoring the ARGB palette...") 76 | delay (2000) 77 | setallrgbpalette (palette) 78 | cleardevice () 79 | 80 | setcolor (WHITE) 81 | outtextxy (250, 100, "Restored ARGB colours") 82 | for i in range (MAX): 83 | setrgbcolor (i) 84 | setfillstyle (SOLID_FILL, RGBPALETTE (i)) 85 | bar (10, 10, 200, 200) 86 | delay (20) 87 | 88 | setcolor (WHITE) 89 | outtextxy (250, 120, "Press a key to exit") 90 | 91 | getch () 92 | closegraph () 93 | 94 | # ----- 95 | 96 | main () 97 | 98 | # ----- end of file rgbpalette.c 99 | -------------------------------------------------------------------------------- /src/Makefile.CodeBlocks: -------------------------------------------------------------------------------- 1 | # Makefile for SDL_bgi, for CodeBlocks + Mingw 20.03 2 | # and SDL2 (tested with 2.0.24) 3 | 4 | # To compile SDL_bgi for CodeBlocks from the 5 | # MSYS2 shell, run this command: 6 | # PATH=/c/CodeBlocks/MinGW/bin/:$PATH && make -f Makefile.CodeBlocks 7 | 8 | VERSION := $(shell cat ../VERSION) 9 | NAME = SDL_bgi 10 | SRC = $(NAME).c 11 | OBJ = $(NAME).o 12 | HEADER1 = SDL_bgi.h 13 | HEADER2 = graphics.h 14 | 15 | # We assume that CodeBlocks is installed in C:\CodeBlocks, 16 | # while SDL2 is installed in C:\SDL2-* 17 | SDL_DIR = /c/SDL2-* 18 | INC_DIR = /c/CodeBlocks/MinGW/include/ 19 | SDL_INC = $(SDL_DIR)/x86_64-w64-mingw32/include/ 20 | SDL_LIB = $(SDL_DIR)/x86_64-w64-mingw32/lib/ 21 | LIB_DIR = /c/CodeBlocks/MinGW/bin/ 22 | LIB = $(NAME).dll 23 | LDFLAGS = -L $(SDL_LIB) -lSDL2 24 | # Use gcc and strip provided by CodeBlocks 25 | STRIP = strip.exe 26 | CC = gcc.exe 27 | CFLAGS = -O2 -g -std=gnu99 -c -Wall -I . -I $(INC_DIR) -I $(SDL_INC) 28 | 29 | .PHONY : all 30 | all: $(LIB) 31 | 32 | OBJ: 33 | $(CC) $(CFLAGS) $(SRC) 34 | 35 | $(LIB): $(OBJ) 36 | $(CC) -shared -o $(LIB) $(OBJ) $(LDFLAGS) ; \ 37 | $(STRIP) $(LIB) 38 | 39 | install: $(LIB) $(HEADER1) 40 | cp $(LIB) $(LIB_DIR) ; \ 41 | cp $(HEADER1) $(SDL_INC) ; \ 42 | cp $(HEADER2) $(INC_DIR) 43 | 44 | uninstall: 45 | rm -f $(SDL_INC)/$(HEADER1) ; \ 46 | rm -f $(INC_DIR)/$(HEADER2) 47 | rm -f $(LIB_DIR)/$(LIB) 48 | 49 | # End of Makefile.CodeBlocks 50 | -------------------------------------------------------------------------------- /src/Makefile.DevCpp: -------------------------------------------------------------------------------- 1 | # Makefile for SDL_bgi, for Dev-C++ 5.11, TDM-GCC 5.1.0-3, 2 | # and SDL2 (tested with 2.0.24) 3 | 4 | # To compile SDL_bgi for Dev-C++ from the 5 | # MSYS2 shell, run this command: 6 | # PATH=/c/Dev-Cpp/MinGW64/bin/:$PATH && make -f Makefile.DevCpp 7 | 8 | VERSION := $(shell cat ../VERSION) 9 | NAME = SDL_bgi 10 | SRC = $(NAME).c 11 | OBJ = $(NAME).o 12 | HEADER1 = SDL_bgi.h 13 | HEADER2 = graphics.h 14 | 15 | # We assume that Dev-C++ is installed in C:\Dev-Cpp, 16 | # while SDL2 is installed in C:\SDL2-* 17 | SDL_DIR = /c/SDL2-* 18 | INC_DIR = /c/Dev-Cpp/MinGW64/include/ 19 | SDL_INC = $(SDL_DIR)/x86_64-w64-mingw32/include/ 20 | SDL_LIB = $(SDL_DIR)/x86_64-w64-mingw32/lib/ 21 | LIB_DIR = /c/Dev-Cpp/MinGW64/bin/ 22 | LIB = $(NAME).dll 23 | LDFLAGS = -L $(SDL_LIB) -lSDL2 24 | # Use gcc and strip provided by Dev-Cpp 25 | STRIP = strip.exe 26 | CC = gcc.exe 27 | CFLAGS = -O2 -g -std=gnu99 -c -Wall -I . -I $(INC_DIR) -I $(SDL_INC) 28 | 29 | .PHONY : all 30 | all: $(LIB) 31 | 32 | OBJ: 33 | $(CC) $(CFLAGS) $(SRC) 34 | 35 | $(LIB): $(OBJ) 36 | $(CC) -shared -o $(LIB) $(OBJ) $(LDFLAGS) ; \ 37 | $(STRIP) $(LIB) 38 | 39 | install: $(LIB) $(HEADER1) 40 | cp $(LIB) $(LIB_DIR) ; \ 41 | cp $(HEADER1) $(SDL_INC) ; \ 42 | cp $(HEADER2) $(INC_DIR) 43 | 44 | uninstall: 45 | rm -f $(SDL_INC)/$(HEADER1) ; \ 46 | rm -f $(INC_DIR)/$(HEADER2) 47 | rm -f $(LIB_DIR)/$(LIB) 48 | 49 | # End of Makefile.DevCpp 50 | -------------------------------------------------------------------------------- /src/graphics.h: -------------------------------------------------------------------------------- 1 | // graphics.h -*- C -*- 2 | 3 | // `SDL_bgi` is a multiplatform, SDL2-based `graphics.h` implementation. 4 | // Easy to use, pretty fast, and useful for porting old programs. 5 | // Guido Gonzato, PhD 6 | // April 19, 2022 7 | 8 | #include 9 | 10 | // --- End of file graphics.h 11 | -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | arc 2 | bar 3 | bar3d 4 | circle 5 | cleardevice 6 | clearviewport 7 | closegraph 8 | delay 9 | detectgraph 10 | drawpoly 11 | ellipse 12 | fillellipse 13 | fillpoly 14 | floodfill 15 | getarccoords 16 | getaspectratio 17 | getbkcolor 18 | getcolor 19 | getdefaultpalette 20 | getdrivername 21 | getfillpattern 22 | getfillsettings 23 | getgraphmode 24 | getimage 25 | getlinesettings 26 | getmaxcolor 27 | getmaxmode 28 | getmaxx 29 | getmaxy 30 | getmodename 31 | getmoderange 32 | getpalette 33 | getpalettesize 34 | gettextsettings 35 | getviewsettings 36 | getvisualpage 37 | getx 38 | gety 39 | graphdefaults 40 | grapherrormsg 41 | graphresult 42 | initgraph 43 | installuserfont 44 | line 45 | linerel 46 | lineto 47 | moverel 48 | moveto 49 | outtext 50 | outtextxy 51 | pieslice 52 | rectangle 53 | restorecrtmode 54 | sector 55 | setactivepage 56 | setallpalette 57 | setaspectratio 58 | setbkcolor 59 | setcolor 60 | setfillpattern 61 | setfillstyle 62 | setgraphbufsize 63 | setgraphmode 64 | setlinestyle 65 | setpalette 66 | settextjustify 67 | settextstyle 68 | setusercharsize 69 | setviewport 70 | setvisualpage 71 | setwritemode 72 | textheight 73 | textwidth 74 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for test commands 2 | 3 | # C compiler: gcc, clang, or tcc 4 | # CC = tcc -w -D SDL_DISABLE_IMMINTRIN_H 5 | CC = gcc 6 | 7 | # Detect the platform: GNU/Linux, Darwin (macOS), Mingw-w64 8 | PLATFORM := $(shell uname -s) 9 | 10 | # GNU/Linux 11 | ifeq ($(PLATFORM),Linux) 12 | CFLAGS = -std=gnu99 -O2 -g -I. -I/usr/include/SDL2 -Wall 13 | LIBS = -lSDL_bgi -lSDL2 14 | endif 15 | 16 | # macOS - tested on Catalina 17 | ifeq ($(PLATFORM),Darwin) 18 | CFLAGS = -std=gnu99 -O2 -g -I. -I/usr/local/include 19 | LIBS = -lSDL_bgi -lSDL2 -Wl,-rpath,/usr/local/lib 20 | endif 21 | 22 | # Latest MSYS2 + Mingw-w64 23 | msys := $(findstring _NT, $(PLATFORM)) 24 | ifeq ($(msys),_NT) 25 | # use MinGW-64 native SDL2 packages 26 | CFLAGS = -std=gnu99 -O2 -g -I. -I/mingw64/include -I/mingw64/include/SDL 27 | # -mconsole = open a console alongside the program 28 | # -mwindows = Windows-only program (no console) 29 | LIBS = -lmingw32 -L/mingw64/bin -lSDL_bgi -lSDL2main -lSDL2 -lm # -mwindows 30 | endif 31 | 32 | PROGRAMS = arc bar3d bar circle cleardevice clearviewport closegraph \ 33 | delay detectgraph drawpoly ellipse fillellipse fillpoly \ 34 | floodfill getarccoords getaspectratio getbkcolor getcolor \ 35 | getdefaultpalette getdrivername getfillpattern \ 36 | getfillsettings getgraphmode getimage getlinesettings \ 37 | getmaxcolor getmaxmode getmaxx getmaxy getmodename \ 38 | getmoderange getpalette getpalettesize getpixel \ 39 | gettextsettings getvisualpage getviewsettings getx gety \ 40 | graphdefaults grapherrormsg graphresult imagesize initgraph \ 41 | installuserfont kbhit line linerel lineto moverel moveto \ 42 | outtext outtextxy pieslice putimage putpixel rectangle \ 43 | restorecrtmode sector setactivepage setallpalette \ 44 | setaspectratio setbkcolor setcolor setfillpattern \ 45 | setfillstyle setgraphbufsize setgraphmode setlinestyle \ 46 | setpalette settextjustify settextstyle setusercharsize \ 47 | setviewport setvisualpage setwritemode textheight \ 48 | textwidth 49 | 50 | all: $(PROGRAMS) 51 | 52 | $(PROGRAMS): %: %.c 53 | $(CC) $(CFLAGS) -o $@ $< $(LIBS) 54 | 55 | clean: 56 | /bin/rm -f $(PROGRAMS) 57 | 58 | # --- end of Makefile 59 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | # Test Programs 2 | 3 | These programs have been adapted from the test programs available in 4 | the Borland C 3.1 Library Reference. They can be compiled with `SDL_bgi` 5 | and also with Turbo C / Borland C++ running in DOSBox. 6 | 7 | 8 | ## Using TC in DOSBox 9 | 10 | Assuming that Turbo C / Borland C is installed in `C:\TC`, 11 | you can compile the programs using these commands: 12 | 13 | ```` 14 | rem Run the following command only once 15 | path=c:\tc\bin;%path% 16 | rem cd to the directory where 'program.c' is, then: 17 | tcc program.c graphics.lib 18 | ```` 19 | -------------------------------------------------------------------------------- /test/USER.CHR: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/test/USER.CHR -------------------------------------------------------------------------------- /test/arc.c: -------------------------------------------------------------------------------- 1 | /* arc example */ 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | /* request autodetection */ 8 | int gdriver = DETECT, gmode; 9 | int midx, midy; 10 | int stangle = 45, endangle = 135; 11 | int radius = 100; 12 | 13 | /* initialize graphics and local variables */ 14 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 15 | 16 | midx = getmaxx() / 2; 17 | midy = getmaxy() / 2; 18 | setcolor(getmaxcolor()); 19 | 20 | /* draw arc */ 21 | arc(midx, midy, stangle, endangle, radius); 22 | 23 | /* clean up */ 24 | getch(); 25 | closegraph(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /test/bar.c: -------------------------------------------------------------------------------- 1 | /* bar example */ 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | /* request autodetection */ 8 | int gdriver = DETECT, gmode; 9 | int midx, midy, i; 10 | 11 | /* initialize graphics and local variables */ 12 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 13 | 14 | midx = getmaxx() / 2; 15 | midy = getmaxy() / 2; 16 | 17 | /* loop through the fill patterns */ 18 | for (i = SOLID_FILL; i < USER_FILL; i++) { 19 | /* set the fill style */ 20 | setfillstyle(i, getmaxcolor()); 21 | 22 | /* draw the bar */ 23 | bar(midx - 50, midy - 50, midx + 50, midy + 50); 24 | getch(); 25 | } 26 | 27 | /* clean up */ 28 | closegraph(); 29 | return 0; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /test/bar3d.c: -------------------------------------------------------------------------------- 1 | /* bar3d example */ 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | /* request autodetection */ 8 | int gdriver = DETECT, gmode; 9 | int midx, midy, i; 10 | 11 | /* initialize graphics and local variables */ 12 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 13 | 14 | midx = getmaxx() / 2; 15 | midy = getmaxy() / 2; 16 | 17 | /* loop through the fill patterns */ 18 | for (i = EMPTY_FILL; i < USER_FILL; i++) { 19 | /* set the fill style */ 20 | setfillstyle(i, getmaxcolor()); 21 | 22 | /* draw the 3-d bar */ 23 | bar3d(midx - 50, midy - 50, midx + 50, midy + 50, 10, 1); 24 | getch(); 25 | } 26 | 27 | /* clean up */ 28 | closegraph(); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /test/circle.c: -------------------------------------------------------------------------------- 1 | /* circle example */ 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | /* request autodetection */ 8 | int gdriver = DETECT, gmode; 9 | int midx, midy, radius = 100; 10 | 11 | /* initialize graphics and local variables */ 12 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 13 | 14 | midx = getmaxx() / 2; 15 | midy = getmaxy() / 2; 16 | setcolor(getmaxcolor()); 17 | 18 | /* draw the circle */ 19 | circle(midx, midy, radius); 20 | 21 | /* clean up */ 22 | getch(); 23 | closegraph(); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /test/cleardevice.c: -------------------------------------------------------------------------------- 1 | /* cleardevice example */ 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | /* request autodetection */ 8 | int gdriver = DETECT, gmode; 9 | int midx, midy; 10 | 11 | /* initialize graphics and local variables */ 12 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 13 | 14 | midx = getmaxx() / 2; 15 | midy = getmaxy() / 2; 16 | setcolor(getmaxcolor()); 17 | 18 | /* for centering screen messages */ 19 | settextjustify(CENTER_TEXT, CENTER_TEXT); 20 | 21 | /* output a message to the screen */ 22 | outtextxy(midx, midy, "Press any key to clear the screen:"); 23 | 24 | getch(); /* wait for a key */ 25 | cleardevice(); /* clear the screen */ 26 | 27 | /* output another message */ 28 | outtextxy(midx, midy, "Press any key to quit:"); 29 | 30 | /* clean up */ 31 | getch(); 32 | closegraph(); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /test/clearviewport.c: -------------------------------------------------------------------------------- 1 | /* clearviewport example */ 2 | 3 | #include 4 | 5 | #define CLIP_ON 1 /* activates clipping in viewport */ 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | /* request autodetection */ 10 | int gdriver = DETECT, gmode, ht; 11 | 12 | /* initialize graphics and local variables */ 13 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 14 | 15 | setcolor(getmaxcolor()); 16 | ht = textheight("W"); 17 | 18 | /* message in default full-screen viewport */ 19 | outtextxy(0, 0, "* <-- (0, 0) in default viewport"); 20 | 21 | /* create a smaller viewport */ 22 | setviewport(50, 50, getmaxx() - 50, getmaxy() - 50, CLIP_ON); 23 | 24 | /* display some messages */ 25 | outtextxy(0, 0, "* <-- (0, 0) in smaller viewport"); 26 | 27 | outtextxy(0, 2 * ht, "Press any key to clear viewport:"); 28 | 29 | getch(); /* wait for a key */ 30 | clearviewport(); /* clear the viewport */ 31 | /* output another message */ 32 | outtextxy(0, 0, "Press any key to quit:"); 33 | 34 | /* clean up */ 35 | getch(); 36 | closegraph(); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /test/closegraph.c: -------------------------------------------------------------------------------- 1 | /* closegraph example */ 2 | 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | /* request autodetection */ 9 | int gdriver = DETECT, gmode, x, y; 10 | 11 | /* initialize graphics mode */ 12 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 13 | 14 | x = getmaxx() / 2; 15 | y = getmaxy() / 2; 16 | 17 | /* output a message */ 18 | settextjustify(CENTER_TEXT, CENTER_TEXT); 19 | outtextxy(x, y, "Press a key to close the graphics system:"); 20 | 21 | getch(); /* wait for a key */ 22 | 23 | /* closes down the graphics system */ 24 | closegraph(); 25 | printf("We're now back in text mode.\n"); 26 | printf("Press any key to halt:"); 27 | getch(); 28 | return 0; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /test/conio.h: -------------------------------------------------------------------------------- 1 | // Minimal conio.h for old BGI programs 2 | // For a real implementation, have a look at 3 | // https://github.com/nowres/conio-for-linux 4 | 5 | #include 6 | 7 | void clrscr (void); 8 | void gotoxy (int, int); 9 | 10 | // ----- 11 | 12 | void clrscr (void) 13 | { 14 | // Clears the console 15 | 16 | printf ("\x1b[2J"); 17 | 18 | } // clrscr () 19 | 20 | // ----- 21 | 22 | void gotoxy (int x, int y) 23 | { 24 | // Moves the cursor to line y, column x 25 | 26 | printf ("\x1b[%d;%df", y, x); 27 | 28 | } // gotoxy () 29 | 30 | // ----- end of file conio.h 31 | -------------------------------------------------------------------------------- /test/delay.c: -------------------------------------------------------------------------------- 1 | /* delay example */ 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | int gdriver = DETECT, gmode; 8 | int midx, midy, i; 9 | 10 | /* initialize graphics and local variables */ 11 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 12 | 13 | midx = getmaxx() / 2; 14 | midy = getmaxy() / 2; 15 | 16 | /* loop through the fill patterns with 4 second delays */ 17 | for (i = SOLID_FILL; i < USER_FILL; i++) { 18 | /* set the fill style */ 19 | setfillstyle(i, getmaxcolor()); 20 | 21 | /* draw the bar */ 22 | bar(midx - 50, midy - 50, midx + 50, midy + 50); 23 | delay(500); 24 | } 25 | 26 | /* clean up */ 27 | closegraph(); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /test/detectgraph.c: -------------------------------------------------------------------------------- 1 | /* detectgraph example */ 2 | 3 | #include 4 | #include 5 | 6 | /* the names of the various cards supported */ 7 | char *dname[] = { "requests detection", 8 | "a CGA", 9 | "an MCGA", 10 | "an EGA", 11 | "a 64K EGA", 12 | "a monochrome EGA", 13 | "an IBM 8514", 14 | "a Hercules monochrome", 15 | "an AT&T 6300 PC", 16 | "a VGA", 17 | "an IBM 3270 PC" 18 | }; 19 | 20 | int main(int argc, char *argv[]) 21 | { 22 | /* used to return detected hardware info. */ 23 | int gdriver, gmode; 24 | 25 | /* detect the graphics hardware available */ 26 | detectgraph(&gdriver, &gmode); 27 | gdriver = 0; 28 | 29 | /* display the information detected */ 30 | clrscr(); 31 | printf("You have '%s' video display card.\n", dname[gdriver]); 32 | printf("Press any key to halt:"); 33 | getch(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/dos.h: -------------------------------------------------------------------------------- 1 | // dummy dos.h for bgidemo.c 2 | 3 | #include 4 | 5 | #ifndef _WIN32 6 | 7 | // K&R itoa() implementation, adapted from 8 | // https://en.wikibooks.org/wiki/C_Programming/stdlib.h/itoa 9 | 10 | /* reverse: reverse string s in place */ 11 | void 12 | reverse (char s[]) 13 | { 14 | int i, j; 15 | char c; 16 | 17 | for (i = 0, j = strlen (s) - 1; i < j; i++, j--) 18 | { 19 | c = s[i]; 20 | s[i] = s[j]; 21 | s[j] = c; 22 | } 23 | } 24 | 25 | /* itoa: convert n to characters in s */ 26 | char * 27 | itoa (int n, char *s, int base) 28 | { 29 | int i, sign; 30 | 31 | if ((sign = n) < 0) /* record sign */ 32 | n = -n; /* make n positive */ 33 | i = 0; 34 | do 35 | { /* generate digits in reverse order */ 36 | s[i++] = n % 10 + '0'; /* get next digit */ 37 | } 38 | while ((n /= 10) > 0); /* delete it */ 39 | if (sign < 0) 40 | s[i++] = '-'; 41 | s[i] = '\0'; 42 | reverse (s); 43 | return s; 44 | } 45 | 46 | #endif 47 | 48 | // --- end of file dos.h 49 | -------------------------------------------------------------------------------- /test/drawpoly.c: -------------------------------------------------------------------------------- 1 | /* drawpoly example */ 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | /* request autodetection */ 8 | int gdriver = DETECT, gmode; 9 | int maxx, maxy; 10 | 11 | int poly[10]; /* our polygon array */ 12 | 13 | /* initialize graphics and local variables */ 14 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 15 | 16 | maxx = getmaxx(); 17 | maxy = getmaxy(); 18 | poly[0] = 20; /* first vertex */ 19 | poly[1] = maxy / 2; 20 | poly[2] = maxx - 20; /* second vertex */ 21 | poly[3] = 20; 22 | poly[4] = maxx - 50; /* third vertex */ 23 | poly[5] = maxy - 20; 24 | poly[6] = maxx / 2; /* fourth vertex */ 25 | poly[7] = maxy / 2; 26 | poly[8] = poly[0]; /* drawpoly doesn't automatically close */ 27 | poly[9] = poly[1]; /* the polygon, so we close it */ 28 | 29 | drawpoly(5, poly); /* draw the polygon */ 30 | 31 | /* clean up */ 32 | getch(); 33 | closegraph(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/ellipse.c: -------------------------------------------------------------------------------- 1 | /* ellipse example */ 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | /* request autodetection */ 8 | int gdriver = DETECT, gmode; 9 | int midx, midy; 10 | int stangle = 0, endangle = 360; 11 | int xradius = 100, yradius = 50; 12 | 13 | /* initialize graphics and local variables */ 14 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 15 | 16 | midx = getmaxx() / 2; 17 | midy = getmaxy() / 2; 18 | setcolor(getmaxcolor()); 19 | 20 | /* draw ellipse */ 21 | ellipse(midx, midy, stangle, endangle, xradius, yradius); 22 | 23 | /* clean up */ 24 | getch(); 25 | closegraph(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /test/fillellipse.c: -------------------------------------------------------------------------------- 1 | /* fillellipse example */ 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | /* request autodetection */ 8 | int gdriver = DETECT, gmode; 9 | int midx, midy, i; 10 | int xradius = 100, yradius = 50; 11 | 12 | /* initialize graphics and local variables */ 13 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 14 | 15 | midx = getmaxx() / 2; 16 | midy = getmaxy() / 2; 17 | 18 | /* loop through the fill patterns */ 19 | for (i = EMPTY_FILL; i < USER_FILL; i++) { 20 | /* set fill pattern */ 21 | setfillstyle(i, getmaxcolor()); 22 | 23 | /* draw a filled ellipse */ 24 | fillellipse(midx, midy, xradius, yradius); 25 | getch(); 26 | } 27 | 28 | /* clean up */ 29 | closegraph(); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /test/fillpoly.c: -------------------------------------------------------------------------------- 1 | /* fillpoly example */ 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | /* request autodetection */ 8 | int gdriver = DETECT, gmode; 9 | int i, maxx, maxy; 10 | 11 | /* our polygon array */ 12 | int poly[8]; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | maxx = getmaxx(); 18 | maxy = getmaxy(); 19 | 20 | poly[0] = 20; /* first vertex */ 21 | poly[1] = maxy / 2; 22 | poly[2] = maxx - 20; /* second vertex */ 23 | poly[3] = 20; 24 | poly[4] = maxx - 50; /* third vertex */ 25 | poly[5] = maxy - 20; 26 | poly[6] = maxx / 2; /* fourth, fillpoly automatically */ 27 | poly[7] = maxy / 2; /* closes the polygon */ 28 | 29 | 30 | /* loop through the fill patterns */ 31 | for (i = EMPTY_FILL; i < USER_FILL; i++) { 32 | /* set fill pattern */ 33 | setfillstyle(i, getmaxcolor()); 34 | 35 | /* draw a filled polygon */ 36 | fillpoly(4, poly); 37 | getch(); 38 | } 39 | 40 | /* clean up */ 41 | closegraph(); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /test/floodfill.c: -------------------------------------------------------------------------------- 1 | /* floodfill example */ 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | /* request autodetection */ 8 | int gdriver = DETECT, gmode; 9 | int maxx, maxy; 10 | 11 | /* initialize graphics and local variables */ 12 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 13 | 14 | maxx = getmaxx(); 15 | maxy = getmaxy(); 16 | 17 | /* select drawing color */ 18 | setcolor(getmaxcolor()); 19 | 20 | /* select fill color */ 21 | setfillstyle(SOLID_FILL, getmaxcolor()); 22 | 23 | /* draw a border around the screen */ 24 | rectangle(0, 0, maxx, maxy); 25 | 26 | /* draw some circles */ 27 | circle(maxx / 3, maxy / 2, 50); 28 | circle(maxx / 2, 20, 100); 29 | circle(maxx - 20, maxy - 50, 75); 30 | circle(20, maxy - 20, 25); 31 | 32 | /* wait for a key */ 33 | getch(); 34 | 35 | /* fill in bounded region */ 36 | floodfill(2, 2, getmaxcolor()); 37 | 38 | /* clean up */ 39 | getch(); 40 | closegraph(); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /test/getactivepage.c: -------------------------------------------------------------------------------- 1 | /* getactivepage example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* select driver and mode that supports multiple pages */ 11 | int gdriver = DETECT, gmode; 12 | int x, y, ht; 13 | char msg[80]; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | x = getmaxx() / 2; 19 | y = getmaxy() / 2; 20 | ht = textheight("W"); 21 | 22 | /* select the off screen page for drawing */ 23 | setactivepage(1); 24 | 25 | /* draw a line on page #1 */ 26 | line(0, 0, getmaxx(), getmaxy()); 27 | 28 | /* output a message on page #1 */ 29 | settextjustify(CENTER_TEXT, CENTER_TEXT); 30 | sprintf(msg, "This is page #%d:", getactivepage()); 31 | outtextxy(x, y, msg); 32 | outtextxy(x, y + ht, "Press any key to halt:"); 33 | 34 | /* select drawing to page #0 */ 35 | setactivepage(0); 36 | 37 | /* output a message on page #0 */ 38 | sprintf(msg, "This is page #%d:", getactivepage()); 39 | outtextxy(x, y, msg); 40 | outtextxy(x, y + ht, "Press any key to view page #1:"); 41 | getch(); 42 | 43 | /* select page #1 as the visible page */ 44 | setvisualpage(1); 45 | 46 | /* clean up */ 47 | getch(); 48 | closegraph(); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /test/getarccoords.c: -------------------------------------------------------------------------------- 1 | /* getarccoords example */ 2 | 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | /* request autodetection */ 9 | int gdriver = DETECT, gmode; 10 | struct arccoordstype arcinfo; 11 | int midx, midy; 12 | int stangle = 45, endangle = 270; 13 | char sstr[80], estr[80]; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | midx = getmaxx() / 2; 19 | midy = getmaxy() / 2; 20 | 21 | /* draw arc and get coordinates */ 22 | setcolor(getmaxcolor()); 23 | arc(midx, midy, stangle, endangle, 100); 24 | getarccoords(&arcinfo); 25 | 26 | /* convert arc information into strings */ 27 | sprintf(sstr, "*- (%d, %d)", arcinfo.xstart, arcinfo.ystart); 28 | 29 | sprintf(estr, "*- (%d, %d)", arcinfo.xend, arcinfo.yend); 30 | 31 | /* output the arc information */ 32 | outtextxy(arcinfo.xstart, arcinfo.ystart, sstr); 33 | outtextxy(arcinfo.xend, arcinfo.yend, estr); 34 | 35 | /* clean up */ 36 | getch(); 37 | closegraph(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /test/getaspectratio.c: -------------------------------------------------------------------------------- 1 | /* getaspectratio example */ 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | /* request autodetection */ 8 | int gdriver = DETECT, gmode; 9 | int xasp, yasp, midx, midy; 10 | 11 | /* initialize graphics and local variables */ 12 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 13 | 14 | midx = getmaxx() / 2; 15 | midy = getmaxy() / 2; 16 | setcolor(getmaxcolor()); 17 | 18 | /* get current aspect ratio settings */ 19 | getaspectratio(&xasp, &yasp); 20 | 21 | /* draw normal circle */ 22 | circle(midx, midy, 100); 23 | getch(); 24 | 25 | /* draw wide circle */ 26 | cleardevice(); 27 | setaspectratio(xasp / 2, yasp); 28 | circle(midx, midy, 100); 29 | getch(); 30 | 31 | /* draw narrow circle */ 32 | cleardevice(); 33 | setaspectratio(xasp, yasp / 2); 34 | circle(midx, midy, 100); 35 | 36 | /* clean up */ 37 | getch(); 38 | closegraph(); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /test/getbkcolor.c: -------------------------------------------------------------------------------- 1 | /* getbkcolor example */ 2 | 3 | #include 4 | #include "dos.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | /* request autodetection */ 9 | int gdriver = DETECT, gmode; 10 | int bkcolor, midx, midy; 11 | char bkname[35]; 12 | 13 | /* initialize graphics and local variables */ 14 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 15 | 16 | midx = getmaxx() / 2; 17 | midy = getmaxy() / 2; 18 | setcolor(getmaxcolor()); 19 | 20 | /* for centering text on the display */ 21 | settextjustify(CENTER_TEXT, CENTER_TEXT); 22 | 23 | /* get the current background color */ 24 | bkcolor = getbkcolor(); 25 | 26 | /* convert color value into a string */ 27 | itoa(bkcolor, bkname, 10); 28 | strcat(bkname, " is the current background color."); 29 | 30 | /* display a message */ 31 | outtextxy(midx, midy, bkname); 32 | 33 | /* clean up */ 34 | getch(); 35 | closegraph(); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /test/getcolor.c: -------------------------------------------------------------------------------- 1 | /* getcolor example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int color, midx, midy; 13 | char colname[35]; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | midx = getmaxx() / 2; 19 | midy = getmaxy() / 2; 20 | setcolor(getmaxcolor()); 21 | 22 | /* for centering text on the display */ 23 | settextjustify(CENTER_TEXT, CENTER_TEXT); 24 | 25 | /* get the current drawing color */ 26 | color = getcolor(); 27 | 28 | /* convert color value into a string */ 29 | itoa(color, colname, 10); 30 | strcat(colname, " is the current drawing color."); 31 | 32 | /* display a message */ 33 | outtextxy(midx, midy, colname); 34 | 35 | /* clean up */ 36 | getch(); 37 | closegraph(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /test/getdefaultpalette.c: -------------------------------------------------------------------------------- 1 | /* getdefaultpalette example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | char str[80]; 13 | 14 | /* pointer to palette structure */ 15 | struct palettetype *pal = NULL; 16 | int i; 17 | 18 | /* initialize graphics and local variables */ 19 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 20 | 21 | /* return a pointer to the default palette */ 22 | pal = getdefaultpalette(); 23 | for (i = 0; i < pal->size; i++) { 24 | printf(str, "colors[%d] = %d\n", i, pal->colors[i]); 25 | getch(); 26 | } 27 | 28 | /* clean up */ 29 | getch(); 30 | closegraph(); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /test/getdrivername.c: -------------------------------------------------------------------------------- 1 | /* getdrivername example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | 13 | /* stores the device driver name */ 14 | char *drivername; 15 | 16 | /* initialize graphics and local variables */ 17 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 18 | setcolor(getmaxcolor()); 19 | 20 | /* get the name of the device driver in use */ 21 | drivername = getdrivername(); 22 | 23 | /* for centering text onscreen */ 24 | settextjustify(CENTER_TEXT, CENTER_TEXT); 25 | 26 | /* output the name of the driver */ 27 | outtextxy(getmaxx() / 2, getmaxy() / 2, drivername); 28 | 29 | /* clean up */ 30 | getch(); 31 | closegraph(); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /test/getfillpattern.c: -------------------------------------------------------------------------------- 1 | /* getfillpattern example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int maxx, maxy; 13 | char pattern[8] = { 0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04 }; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | maxx = getmaxx(); 19 | maxy = getmaxy(); 20 | setcolor(getmaxcolor()); 21 | 22 | /* select a user-defined fill pattern */ 23 | setfillpattern(pattern, getmaxcolor()); 24 | 25 | /* fill the screen with the pattern */ 26 | bar(0, 0, maxx, maxy); 27 | getch(); 28 | 29 | /* get the current user-defined fill pattern */ 30 | getfillpattern(pattern); 31 | 32 | /* alter the pattern we grabbed */ 33 | pattern[4] -= 1; 34 | pattern[5] -= 3; 35 | pattern[6] += 3; 36 | pattern[7] -= 4; 37 | 38 | /* select our new pattern */ 39 | setfillpattern(pattern, getmaxcolor()); 40 | 41 | /* fill the screen with the new pattern */ 42 | bar(0, 0, maxx, maxy); 43 | 44 | /* clean up */ 45 | getch(); 46 | closegraph(); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /test/getfillsettings.c: -------------------------------------------------------------------------------- 1 | /* getfillsettings example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /* the names of the fill styles supported */ 9 | char *fname[] = 10 | { "EMPTY_FILL", "SOLID_FILL", "LINE_FILL", "LTSLASH_FILL", 11 | "SLASH_FILL", "BKSLASH_FILL", "LTBKSLASH_FILL", "HATCH_FILL", 12 | "XHATCH_FILL", "INTERLEAVE_FILL", "WIDE_DOT_FILL", "CLOSE_DOT_FILL", 13 | "USER_FILL" }; 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | /* request autodetection */ 18 | int gdriver = DETECT, gmode; 19 | struct fillsettingstype fillinfo; 20 | 21 | int midx, midy; 22 | char patstr[40], colstr[40]; 23 | 24 | /* initialize graphics and local variables */ 25 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 26 | 27 | midx = getmaxx() / 2; 28 | midy = getmaxy() / 2; 29 | 30 | /* get info about current fill pattern and color */ 31 | getfillsettings(&fillinfo); 32 | 33 | /* convert fill information into strings */ 34 | sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]); 35 | sprintf(colstr, "%d is the fill color.", fillinfo.color); 36 | 37 | /* display the information */ 38 | settextjustify(CENTER_TEXT, CENTER_TEXT); 39 | outtextxy(midx, midy, patstr); 40 | outtextxy(midx, midy + 2 * textheight("W"), colstr); 41 | 42 | /* clean up */ 43 | 44 | getch(); 45 | closegraph(); 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /test/getgraphmode.c: -------------------------------------------------------------------------------- 1 | /* getgraphmode example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int midx, midy, mode; 13 | char numname[80], modename[80]; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | midx = getmaxx() / 2; 19 | midy = getmaxy() / 2; 20 | 21 | /* get mode number and name strings */ 22 | mode = getgraphmode(); 23 | sprintf(numname, "%d is the current mode number.", mode); 24 | sprintf(modename, "%s is the current graphics mode.", getmodename(mode)); 25 | 26 | /* display the information */ 27 | settextjustify(CENTER_TEXT, CENTER_TEXT); 28 | outtextxy(midx, midy, numname); 29 | outtextxy(midx, midy + 2 * textheight("W"), modename); 30 | 31 | /* clean up */ 32 | getch(); 33 | closegraph(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/getimage.c: -------------------------------------------------------------------------------- 1 | /* getimage example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void save_screen(void *buf[4]); 9 | void restore_screen(void *buf[4]); 10 | 11 | int maxx, maxy; 12 | int main(int argc, char *argv[]) 13 | { 14 | int gdriver = DETECT, gmode; 15 | void *ptr[4]; 16 | 17 | /* autodetect the graphics driver and mode */ 18 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 19 | 20 | maxx = getmaxx(); 21 | maxy = getmaxy(); 22 | 23 | /* draw an image on the screen */ 24 | rectangle(0, 0, maxx, maxy); 25 | line(0, 0, maxx, maxy); 26 | line(0, maxy, maxx, 0); 27 | save_screen(ptr); /* save the current screen */ 28 | getch(); /* pause screen */ 29 | cleardevice(); /* clear screen */ 30 | restore_screen(ptr); /* restore the screen */ 31 | getch(); /* pause screen */ 32 | 33 | closegraph(); 34 | return 0; 35 | } 36 | 37 | void save_screen(void *buf[4]) 38 | { 39 | unsigned size; 40 | int ystart = 0, yend, yincr, block; 41 | yincr = (maxy + 1) / 4; 42 | yend = yincr; 43 | 44 | /* get byte size of image */ 45 | size = imagesize(0, ystart, maxx, yend); 46 | for (block = 0; block <= 3; block++) { 47 | if ((buf[block] = malloc(size)) == NULL) { 48 | closegraph(); 49 | printf("Error: not enough heap space in save_screen().\n"); 50 | exit(1); 51 | } 52 | getimage(0, ystart, maxx, yend, buf[block]); 53 | 54 | ystart = yend + 1; 55 | yend += yincr + 1; 56 | } 57 | } 58 | 59 | void restore_screen(void *buf[4]) 60 | { 61 | int ystart = 0, yend, yincr, block; 62 | yincr = (maxy + 1) / 4; 63 | yend = yincr; 64 | for (block = 0; block <= 3; block++) { 65 | putimage(0, ystart, buf[block], COPY_PUT); 66 | free(buf[block]); 67 | ystart = yend + 1; 68 | 69 | yend += yincr + 1; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /test/getlinesettings.c: -------------------------------------------------------------------------------- 1 | /* getlinesettings example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | /* the names of the line styles supported */ 10 | char *lname[] = 11 | { "SOLID_LINE", "DOTTED_LINE", "CENTER_LINE", "DASHED_LINE", 12 | "USERBIT_LINE" }; 13 | 14 | int main(int argc, char *argv[]) 15 | { 16 | /* request autodetection */ 17 | int gdriver = DETECT, gmode; 18 | struct linesettingstype lineinfo; 19 | int midx, midy; 20 | char lstyle[80], lpattern[80], lwidth[80]; 21 | 22 | /* initialize graphics and local variables */ 23 | 24 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 25 | 26 | midx = getmaxx() / 2; 27 | midy = getmaxy() / 2; 28 | 29 | /* get information about current line settings */ 30 | getlinesettings(&lineinfo); 31 | 32 | /* convert line information into strings */ 33 | sprintf(lstyle, "%s is the line style.", lname[lineinfo.linestyle]); 34 | sprintf(lpattern, "0x%X is the user-defined line pattern.", 35 | lineinfo.upattern); 36 | sprintf(lwidth, "%d is the line thickness.", lineinfo.thickness); 37 | 38 | /* display the information */ 39 | settextjustify(CENTER_TEXT, CENTER_TEXT); 40 | outtextxy(midx, midy, lstyle); 41 | outtextxy(midx, midy + 2 * textheight("W"), lpattern); 42 | outtextxy(midx, midy + 4 * textheight("W"), lwidth); 43 | 44 | /* clean up */ 45 | getch(); 46 | closegraph(); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /test/getmaxcolor.c: -------------------------------------------------------------------------------- 1 | /* getmaxcolor example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int midx, midy; 13 | char colstr[80]; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | midx = getmaxx() / 2; 19 | midy = getmaxy() / 2; 20 | 21 | /* grab the color info. and convert it to a string */ 22 | sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); 23 | 24 | /* display the information */ 25 | settextjustify(CENTER_TEXT, CENTER_TEXT); 26 | outtextxy(midx, midy, colstr); 27 | 28 | /* clean up */ 29 | getch(); 30 | closegraph(); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /test/getmaxmode.c: -------------------------------------------------------------------------------- 1 | /* getmaxmode example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int midx, midy; 13 | char modestr[80]; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | midx = getmaxx() / 2; 19 | midy = getmaxy() / 2; 20 | 21 | /* grab the mode info. and convert it to a string */ 22 | sprintf(modestr, "This driver supports modes 0..%d", getmaxmode()); 23 | 24 | /* display the information */ 25 | settextjustify(CENTER_TEXT, CENTER_TEXT); 26 | outtextxy(midx, midy, modestr); 27 | 28 | /* clean up */ 29 | getch(); 30 | closegraph(); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /test/getmaxx.c: -------------------------------------------------------------------------------- 1 | /* getmaxx example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int midx, midy; 13 | char xrange[80], yrange[80]; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | midx = getmaxx() / 2; 19 | midy = getmaxy() / 2; 20 | 21 | /* convert max resolution values to strings */ 22 | sprintf(xrange, "X values range from 0..%d", getmaxx()); 23 | sprintf(yrange, "Y values range from 0..%d", getmaxy()); 24 | 25 | /* display the information */ 26 | settextjustify(CENTER_TEXT, CENTER_TEXT); 27 | outtextxy(midx, midy, xrange); 28 | outtextxy(midx, midy + textheight("W"), yrange); 29 | 30 | /* clean up */ 31 | getch(); 32 | closegraph(); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /test/getmaxy.c: -------------------------------------------------------------------------------- 1 | /* getmaxy example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int midx, midy; 13 | char xrange[80], yrange[80]; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | midx = getmaxx() / 2; 19 | midy = getmaxy() / 2; 20 | 21 | /* convert max resolution values into strings */ 22 | sprintf(xrange, "X values range from 0..%d", getmaxx()); 23 | sprintf(yrange, "Y values range from 0..%d", getmaxy()); 24 | 25 | /* display the information */ 26 | settextjustify(CENTER_TEXT, CENTER_TEXT); 27 | outtextxy(midx, midy, xrange); 28 | outtextxy(midx, midy + textheight("W"), yrange); 29 | 30 | /* clean up */ 31 | getch(); 32 | closegraph(); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /test/getmodename.c: -------------------------------------------------------------------------------- 1 | /* getmodename example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int midx, midy, mode; 13 | char numname[80], modename[80]; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | midx = getmaxx() / 2; 19 | midy = getmaxy() / 2; 20 | 21 | /* get mode number and name strings */ 22 | mode = getgraphmode(); 23 | sprintf(numname, "%d is the current mode number.", mode); 24 | sprintf(modename, "%s is the current graphics mode.", getmodename(mode)); 25 | 26 | /* display the information */ 27 | settextjustify(CENTER_TEXT, CENTER_TEXT); 28 | outtextxy(midx, midy, numname); 29 | outtextxy(midx, midy + 2 * textheight("W"), modename); 30 | 31 | /* clean up */ 32 | getch(); 33 | closegraph(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/getmoderange.c: -------------------------------------------------------------------------------- 1 | /* getmoderange example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int midx, midy; 13 | int low, high; 14 | char mrange[80]; 15 | 16 | /* initialize graphics and local variables */ 17 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 18 | 19 | midx = getmaxx() / 2; 20 | midy = getmaxy() / 2; 21 | 22 | /* get the mode range for this driver */ 23 | getmoderange(gdriver, &low, &high); 24 | 25 | /* convert mode range info. into strings */ 26 | sprintf(mrange, "This driver supports modes %d..%d", low, high); 27 | 28 | /* display the information */ 29 | settextjustify(CENTER_TEXT, CENTER_TEXT); 30 | outtextxy(midx, midy, mrange); 31 | 32 | /* clean up */ 33 | getch(); 34 | closegraph(); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /test/getpalette.c: -------------------------------------------------------------------------------- 1 | /* getpalette example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | 11 | /* request autodetection */ 12 | int gdriver = DETECT, gmode; 13 | struct palettetype pal; 14 | char psize[80], pval[80]; 15 | int i, ht; 16 | int y = 10; 17 | 18 | /* initialize graphics and local variables */ 19 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 20 | 21 | /* grab a copy of the palette */ 22 | getpalette(&pal); 23 | 24 | /* convert palette info into strings */ 25 | sprintf(psize, "The palette has %d modifiable entries.", pal.size); 26 | 27 | /* display the information */ 28 | outtextxy(0, y, psize); 29 | if (pal.size != 0) { 30 | ht = textheight("W"); 31 | y += 2 * ht; 32 | outtextxy(0, y, "Here are the current values:"); 33 | y += 2 * ht; 34 | for (i = 0; i < pal.size; i++, y += ht) { 35 | sprintf(pval, "palette[%02d]: 0x%02X", i, pal.colors[i]); 36 | outtextxy(0, y, pval); 37 | } 38 | } 39 | 40 | /* clean up */ 41 | getch(); 42 | closegraph(); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /test/getpalettesize.c: -------------------------------------------------------------------------------- 1 | /* getpalettesize example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int midx, midy; 13 | char psize[80]; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | midx = getmaxx() / 2; 19 | midy = getmaxy() / 2; 20 | 21 | /* convert palette size info into string */ 22 | sprintf(psize, "The palette has %d modifiable entries.", 23 | getpalettesize()); 24 | 25 | /* display the information */ 26 | settextjustify(CENTER_TEXT, CENTER_TEXT); 27 | outtextxy(midx, midy, psize); 28 | 29 | /* clean up */ 30 | getch(); 31 | closegraph(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /test/getpixel.c: -------------------------------------------------------------------------------- 1 | /* getpixel example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define PIXEL_COUNT 1000 10 | #define DELAY_TIME 100 /* in milliseconds */ 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | /* request autodetection */ 15 | int gdriver = DETECT, gmode; 16 | int i, x, y, color, maxx, maxy, maxcolor, seed; 17 | 18 | /* initialize graphics and local variables */ 19 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 20 | 21 | maxx = getmaxx() + 1; 22 | maxy = getmaxy() + 1; 23 | maxcolor = getmaxcolor() + 1; 24 | while (!kbhit()) { 25 | seed = random(32767); /* seed the random number generator */ 26 | srand(seed); 27 | for (i = 0; i < PIXEL_COUNT; i++) { 28 | 29 | x = random(maxx); 30 | y = random(maxy); 31 | color = random(maxcolor); 32 | putpixel(x, y, color); 33 | } 34 | delay(DELAY_TIME); 35 | srand(seed); 36 | for (i = 0; i < PIXEL_COUNT; i++) { 37 | x = random(maxx); 38 | y = random(maxy); 39 | color = random(maxcolor); 40 | if (color == getpixel(x, y)) 41 | putpixel(x, y, 0); 42 | } 43 | } 44 | 45 | /* clean up */ 46 | getch(); 47 | closegraph(); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /test/gettextsettings.c: -------------------------------------------------------------------------------- 1 | /* gettextsettings example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /* the names of the supported fonts */ 9 | char *font[] = 10 | { "DEFAULT_FONT", "TRIPLEX_FONT", "SMALL_FONT", "SANS_SERIF_FONT", 11 | "GOTHIC_FONT" }; 12 | 13 | /* the names of the text directions supported */ 14 | char *dir[] = { "HORIZ_DIR", "VERT_DIR" }; 15 | 16 | /* horizontal text justifications supported */ 17 | char *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; 18 | 19 | /* vertical text justifications supported */ 20 | 21 | char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | /* request autodetection */ 26 | int gdriver = DETECT, gmode; 27 | struct textsettingstype textinfo; 28 | int midx, midy, ht; 29 | char fontstr[80], dirstr[80], sizestr[80]; 30 | char hjuststr[80], vjuststr[80]; 31 | 32 | /* initialize graphics and local variables */ 33 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 34 | 35 | midx = getmaxx() / 2; 36 | midy = getmaxy() / 2; 37 | 38 | /* get information about current text settings */ 39 | gettextsettings(&textinfo); 40 | 41 | /* convert text information into strings */ 42 | sprintf(fontstr, "%s is the text style.", font[textinfo.font]); 43 | sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]); 44 | sprintf(sizestr, "%d is the text size.", textinfo.charsize); 45 | sprintf(hjuststr, "%s is the horizontal justification.", 46 | hjust[textinfo.horiz]); 47 | sprintf(vjuststr, "%s is the vertical justification.", 48 | vjust[textinfo.vert]); 49 | 50 | /* display the information */ 51 | ht = textheight("W"); 52 | settextjustify(CENTER_TEXT, CENTER_TEXT); 53 | outtextxy(midx, midy, fontstr); 54 | outtextxy(midx, midy + 2 * ht, dirstr); 55 | outtextxy(midx, midy + 4 * ht, sizestr); 56 | outtextxy(midx, midy + 6 * ht, hjuststr); 57 | 58 | outtextxy(midx, midy + 8 * ht, vjuststr); 59 | 60 | /* clean up */ 61 | getch(); 62 | closegraph(); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /test/getviewsettings.c: -------------------------------------------------------------------------------- 1 | /* getviewsettings example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | char *clip[] = { "OFF", "ON" }; 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | /* request autodetection */ 13 | int gdriver = DETECT, gmode; 14 | struct viewporttype viewinfo; 15 | int midx, midy, ht; 16 | char topstr[80], botstr[80], clipstr[80]; 17 | 18 | /* initialize graphics and local variables */ 19 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 20 | 21 | midx = getmaxx() / 2; 22 | midy = getmaxy() / 2; 23 | 24 | /* get information about current viewport */ 25 | getviewsettings(&viewinfo); 26 | 27 | /* convert text information into strings */ 28 | sprintf(topstr, "(%d, %d) is the upper left viewport corner.", 29 | viewinfo.left, viewinfo.top); 30 | 31 | sprintf(botstr, "(%d, %d) is the lower right viewport corner.", 32 | viewinfo.right, viewinfo.bottom); 33 | sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); 34 | 35 | /* display the information */ 36 | settextjustify(CENTER_TEXT, CENTER_TEXT); 37 | ht = textheight("W"); 38 | outtextxy(midx, midy, topstr); 39 | outtextxy(midx, midy + 2 * ht, botstr); 40 | outtextxy(midx, midy + 4 * ht, clipstr); 41 | 42 | /* clean up */ 43 | getch(); 44 | closegraph(); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /test/getvisualpage.c: -------------------------------------------------------------------------------- 1 | /* getvisualpage example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* select driver and mode that supports multiple pages */ 11 | int gdriver = DETECT, gmode; 12 | int x, y, ht, vp; 13 | char str[80]; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | x = getmaxx() / 2; 19 | y = getmaxy() / 2; 20 | ht = textheight("W"); 21 | 22 | /* select the off screen page for drawing */ 23 | setactivepage(1); 24 | 25 | /* draw a line on page #1 */ 26 | line(0, 0, getmaxx(), getmaxy()); 27 | 28 | /* output a message on page #1 */ 29 | settextjustify(CENTER_TEXT, CENTER_TEXT); 30 | outtextxy(x, y, "This is page #1:"); 31 | outtextxy(x, y + ht, "Press any key to halt:"); 32 | 33 | /* select drawing to page #0 */ 34 | vp = getvisualpage (); 35 | setactivepage(vp); 36 | 37 | /* output a message on page #0 */ 38 | sprintf (str, "This is page #%d.", vp); 39 | outtextxy(x, y, str); 40 | outtextxy(x, y + ht, "Press any key to view page #1:"); 41 | getch(); 42 | 43 | /* select page #1 as the visible page */ 44 | setvisualpage(1); 45 | 46 | /* clean up */ 47 | getch(); 48 | closegraph(); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /test/getx.c: -------------------------------------------------------------------------------- 1 | /* getx example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | char msg[80]; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | /* move to the screen center point */ 18 | moveto(getmaxx() / 2, getmaxy() / 2); 19 | 20 | /* create a message string */ 21 | sprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); 22 | 23 | /* display the message */ 24 | outtext(msg); 25 | 26 | /* clean up */ 27 | getch(); 28 | closegraph(); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /test/gety.c: -------------------------------------------------------------------------------- 1 | /* gety example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | char msg[80]; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | /* move to the screen center point */ 18 | moveto(getmaxx() / 2, getmaxy() / 2); 19 | 20 | /* create a message string */ 21 | sprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); 22 | 23 | /* display the message */ 24 | outtext(msg); 25 | 26 | /* clean up */ 27 | getch(); 28 | closegraph(); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /test/graphdefaults.c: -------------------------------------------------------------------------------- 1 | /* graphdefaults example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int maxx, maxy; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | maxx = getmaxx(); 18 | maxy = getmaxy(); 19 | 20 | /* output line with nondefault settings */ 21 | setlinestyle(DOTTED_LINE, 0, 3); 22 | line(0, 0, maxx, maxy); 23 | outtextxy(maxx / 2, maxy / 3, "Before default values are restored."); 24 | getch(); 25 | 26 | /* restore default values for everything */ 27 | graphdefaults(); 28 | 29 | /* clear the screen */ 30 | cleardevice(); 31 | 32 | /* output line with default settings */ 33 | line(0, 0, maxx, maxy); 34 | outtextxy(maxx / 2, maxy / 3, "After restoring default values."); 35 | 36 | /* clean up */ 37 | getch(); 38 | closegraph(); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /test/grapherrormsg.c: -------------------------------------------------------------------------------- 1 | /* grapherrormsg example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define NONSENSE -50 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | /* force an error to occur */ 13 | int gdriver = NONSENSE, gmode, errorcode; 14 | 15 | /* initialize graphics mode */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | /* read result of initialization */ 19 | errorcode = graphresult(); 20 | 21 | /* if an error occurred, then output descriptive error message */ 22 | if (errorcode != grOk) { 23 | printf("Graphics error: %s\n", grapherrormsg(errorcode)); 24 | 25 | printf("Press any key to halt:"); 26 | getch(); 27 | exit(1); /* terminate with an error code */ 28 | } 29 | 30 | /* draw a line */ 31 | line(0, 0, getmaxx(), getmaxy()); 32 | 33 | /* clean up */ 34 | getch(); 35 | closegraph(); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /test/graphresult.c: -------------------------------------------------------------------------------- 1 | /* graphresult example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode, errorcode; 12 | 13 | /* initialize graphics and local variables */ 14 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 15 | 16 | /* read result of initialization */ 17 | errorcode = graphresult(); 18 | 19 | if (errorcode != grOk) { /* an error occurred */ 20 | printf("Graphics error: %s\n", grapherrormsg(errorcode)); 21 | printf("Press any key to halt:"); 22 | getch(); 23 | exit(1); /* terminate with an error code */ 24 | } 25 | 26 | /* draw a line */ 27 | line(0, 0, getmaxx(), getmaxy()); 28 | 29 | /* clean up */ 30 | getch(); 31 | closegraph(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /test/imagesize.c: -------------------------------------------------------------------------------- 1 | /* imagesize example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define ARROW_SIZE 10 9 | 10 | void draw_arrow(int x, int y); 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | /* request autodetection */ 15 | int gdriver = DETECT, gmode; 16 | void *arrow; 17 | int x, y, maxx; 18 | unsigned int size; 19 | 20 | /* initialize graphics and local variables */ 21 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 22 | 23 | maxx = getmaxx(); 24 | x = 0; 25 | y = getmaxy() / 2; 26 | 27 | /* draw the image to be grabbed */ 28 | draw_arrow(x, y); 29 | 30 | /* calculate the size of the image */ 31 | size = 32 | imagesize(x, y - ARROW_SIZE, x + (4 * ARROW_SIZE), y + ARROW_SIZE); 33 | 34 | /* allocate memory to hold the image */ 35 | arrow = malloc(size); 36 | 37 | 38 | /* grab the image */ 39 | getimage(x, y - ARROW_SIZE, x + (4 * ARROW_SIZE), y + ARROW_SIZE, arrow); 40 | 41 | /* repeat until a key is pressed */ 42 | while (!kbhit()) { 43 | /* erase old image */ 44 | putimage(x, y - ARROW_SIZE, arrow, XOR_PUT); 45 | x += ARROW_SIZE; 46 | if (x >= maxx) 47 | x = 0; 48 | 49 | /* plot new image */ 50 | putimage(x, y - ARROW_SIZE, arrow, XOR_PUT); 51 | } 52 | 53 | /* clean up */ 54 | free(arrow); 55 | closegraph(); 56 | return 0; 57 | } 58 | 59 | void draw_arrow(int x, int y) 60 | { 61 | /* draw an arrow on the screen */ 62 | moveto(x, y); 63 | linerel(4 * ARROW_SIZE, 0); 64 | linerel(-2 * ARROW_SIZE, -1 * ARROW_SIZE); 65 | linerel(0, 2 * ARROW_SIZE); 66 | linerel(2 * ARROW_SIZE, -1 * ARROW_SIZE); 67 | } 68 | -------------------------------------------------------------------------------- /test/initgraph.c: -------------------------------------------------------------------------------- 1 | /* initgraph example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | 13 | /* initialize graphics mode */ 14 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 15 | 16 | /* draw a line */ 17 | line(0, 0, getmaxx(), getmaxy()); 18 | 19 | /* clean up */ 20 | getch(); 21 | closegraph(); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /test/installuserfont.c: -------------------------------------------------------------------------------- 1 | /* installuserfont example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /* function prototype */ 9 | void checkerrors(void); 10 | int main(int argc, char *argv[]) 11 | { 12 | /* request autodetection */ 13 | int gdriver = DETECT, gmode; 14 | int userfont; 15 | int midx, midy; 16 | 17 | /* initialize graphics and local variables */ 18 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 19 | 20 | midx = getmaxx() / 2; 21 | midy = getmaxy() / 2; 22 | 23 | /* install a user-defined font file */ 24 | userfont = installuserfont("USER.CHR"); 25 | 26 | /* select the user font */ 27 | settextstyle(userfont, HORIZ_DIR, 4); 28 | 29 | /* output some text */ 30 | outtextxy(midx, midy, "Testing!"); 31 | 32 | /* clean up */ 33 | getch(); 34 | closegraph(); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /test/kbhit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include // Provides sprintf 3 | 4 | void outintxy(int x, int y, int value); 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | int gdriver = DETECT, gmode, i; 9 | 10 | // Initialize the graphics window. 11 | initgraph (&gdriver, &gmode, "C:\\TC\\BGI"); 12 | 13 | // Convert some numbers to strings and draw them in graphics window: 14 | outtextxy(20, 130, "Click in this graphics window,"); 15 | outtextxy(20, 140, "and then press a key to stop."); 16 | outtextxy(10, 10, "Here are some numbers:"); 17 | for (i = 0; !kbhit(); i++) { 18 | outintxy(20 + (i / 10) * 40, (i % 10) * +10, i); 19 | delay(1000); 20 | } 21 | 22 | closegraph(); 23 | } 24 | 25 | void outintxy(int x, int y, int value) 26 | { 27 | char digit_string[20]; 28 | sprintf(digit_string, "%d", value); 29 | outtextxy(x, y, digit_string); 30 | } 31 | -------------------------------------------------------------------------------- /test/line.c: -------------------------------------------------------------------------------- 1 | /* line example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | 11 | /* request autodetection */ 12 | int gdriver = DETECT, gmode; 13 | int xmax, ymax; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | setcolor(getmaxcolor()); 19 | xmax = getmaxx(); 20 | ymax = getmaxy(); 21 | 22 | /* draw a diagonal line */ 23 | line(0, 0, xmax, ymax); 24 | 25 | /* clean up */ 26 | getch(); 27 | closegraph(); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /test/linerel.c: -------------------------------------------------------------------------------- 1 | /* linerel example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | char msg[80]; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | /* move the CP to location (20,30) */ 18 | moveto(20, 30); 19 | 20 | /* create and output a message at (20,30) */ 21 | sprintf(msg, " (%d, %d)", getx(), gety()); 22 | outtextxy(20, 30, msg); 23 | 24 | /* draw line to a point a relative distance away from current CP */ 25 | linerel(100, 100); 26 | 27 | /* create and output a message at CP */ 28 | sprintf(msg, " (%d, %d)", getx(), gety()); 29 | outtext(msg); 30 | 31 | /* clean up */ 32 | getch(); 33 | closegraph(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/lineto.c: -------------------------------------------------------------------------------- 1 | /* lineto example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | char msg[80]; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | /* move the CP to location (20,30) */ 18 | moveto(20, 30); 19 | 20 | /* create and output a message at (20,30) */ 21 | sprintf(msg, " (%d, %d)", getx(), gety()); 22 | outtextxy(20, 30, msg); 23 | 24 | /* draw a line to (100,100) */ 25 | lineto(100, 100); 26 | 27 | /* create and output a message at CP */ 28 | sprintf(msg, " (%d, %d)", getx(), gety()); 29 | outtext(msg); 30 | 31 | /* clean up */ 32 | getch(); 33 | closegraph(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/moverel.c: -------------------------------------------------------------------------------- 1 | /* moverel example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | char msg[80]; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | /* move the CP to location (20,30) */ 18 | moveto(20, 30); 19 | 20 | /* plot a pixel at the CP */ 21 | putpixel(getx(), gety(), getmaxcolor()); 22 | 23 | /* create and output a message at (20,30) */ 24 | sprintf(msg, " (%d, %d)", getx(), gety()); 25 | outtextxy(20, 30, msg); 26 | 27 | /* move to a point a relative distance away from the current CP */ 28 | moverel(100, 100); 29 | 30 | /* plot a pixel at the CP */ 31 | putpixel(getx(), gety(), getmaxcolor()); 32 | 33 | /* create and output a message at CP */ 34 | sprintf(msg, " (%d, %d)", getx(), gety()); 35 | outtext(msg); 36 | 37 | /* clean up */ 38 | getch(); 39 | closegraph(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /test/moveto.c: -------------------------------------------------------------------------------- 1 | /* moveto example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | char msg[80]; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | /* move the CP to location (20,30) */ 18 | moveto(20, 30); 19 | 20 | /* plot a pixel at the CP */ 21 | putpixel(getx(), gety(), getmaxcolor()); 22 | 23 | /* create and output a message at (20,30) */ 24 | sprintf(msg, " (%d, %d)", getx(), gety()); 25 | outtextxy(20, 30, msg); 26 | 27 | /* move to (100,100) */ 28 | moveto(100, 100); 29 | 30 | /* plot a pixel at the CP */ 31 | putpixel(getx(), gety(), getmaxcolor()); 32 | 33 | /* create and output a message at CP */ 34 | sprintf(msg, " (%d, %d)", getx(), gety()); 35 | outtext(msg); 36 | 37 | /* clean up */ 38 | getch(); 39 | closegraph(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /test/outtext.c: -------------------------------------------------------------------------------- 1 | /* outtext example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int midx, midy; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | midx = getmaxx() / 2; 18 | midy = getmaxy() / 2; 19 | 20 | /* move the CP to the center of the screen */ 21 | moveto(midx, midy); 22 | 23 | /* output text starting at the CP */ 24 | outtext("This "); 25 | outtext("is "); 26 | outtext("a "); 27 | outtext("test."); 28 | 29 | /* clean up */ 30 | getch(); 31 | closegraph(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /test/outtextxy.c: -------------------------------------------------------------------------------- 1 | /* outtextxy example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int midx, midy; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | midx = getmaxx() / 2; 18 | midy = getmaxy() / 2; 19 | 20 | /* output text at center of the screen; CP doesn't get changed */ 21 | outtextxy(midx, midy, "This is a test."); 22 | 23 | /* clean up */ 24 | getch(); 25 | closegraph(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /test/pieslice.c: -------------------------------------------------------------------------------- 1 | /* pieslice example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int midx, midy; 13 | int stangle = 45, endangle = 135, radius = 100; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | midx = getmaxx() / 2; 19 | midy = getmaxy() / 2; 20 | 21 | /* set fill style and draw a pie slice */ 22 | setfillstyle(EMPTY_FILL, getmaxcolor()); 23 | pieslice(midx, midy, stangle, endangle, radius); 24 | 25 | /* clean up */ 26 | getch(); 27 | closegraph(); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /test/putimage.c: -------------------------------------------------------------------------------- 1 | /* putimage example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define ARROW_SIZE 10 9 | 10 | void draw_arrow(int x, int y); 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | /* request autodetection */ 15 | int gdriver = DETECT, gmode; 16 | void *arrow; 17 | int x, y, maxx; 18 | unsigned int size; 19 | 20 | /* initialize graphics and local variables */ 21 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 22 | 23 | maxx = getmaxx(); 24 | x = 0; 25 | y = getmaxy() / 2; 26 | draw_arrow(x, y); 27 | 28 | /* calculate the size of the image and allocate space for it */ 29 | size = 30 | imagesize(x, y - ARROW_SIZE, x + (4 * ARROW_SIZE), y + ARROW_SIZE); 31 | arrow = malloc(size); 32 | 33 | /* grab the image */ 34 | getimage(x, y - ARROW_SIZE, x + (4 * ARROW_SIZE), y + ARROW_SIZE, arrow); 35 | 36 | /* repeat until a key is pressed */ 37 | while (!kbhit()) { 38 | /* erase old image */ 39 | putimage(x, y - ARROW_SIZE, arrow, XOR_PUT); 40 | x += ARROW_SIZE; 41 | if (x >= maxx) 42 | x = 0; 43 | 44 | /* plot new image */ 45 | putimage(x, y - ARROW_SIZE, arrow, XOR_PUT); 46 | } 47 | 48 | free(arrow); 49 | closegraph(); 50 | return 0; 51 | } 52 | 53 | void draw_arrow(int x, int y) 54 | { 55 | moveto(x, y); 56 | linerel(4 * ARROW_SIZE, 0); 57 | linerel(-2 * ARROW_SIZE, -1 * ARROW_SIZE); 58 | linerel(0, 2 * ARROW_SIZE); 59 | 60 | linerel(2 * ARROW_SIZE, -1 * ARROW_SIZE); 61 | } 62 | -------------------------------------------------------------------------------- /test/putpixel.c: -------------------------------------------------------------------------------- 1 | /* putpixel example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define PIXEL_COUNT 1000 10 | #define DELAY_TIME 100 /* in milliseconds */ 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | /* request autodetection */ 15 | int gdriver = DETECT, gmode; 16 | int i, x, y, color, maxx, maxy, maxcolor, seed; 17 | 18 | /* initialize graphics and local variables */ 19 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 20 | 21 | maxx = getmaxx() + 1; 22 | maxy = getmaxy() + 1; 23 | maxcolor = getmaxcolor() + 1; 24 | 25 | while (!kbhit()) { 26 | /* seed the random number generator */ 27 | seed = random(32767); 28 | srand(seed); 29 | for (i = 0; i < PIXEL_COUNT; i++) { 30 | 31 | x = random(maxx); 32 | y = random(maxy); 33 | color = random(maxcolor); 34 | putpixel(x, y, color); 35 | } 36 | delay(DELAY_TIME); 37 | srand(seed); 38 | for (i = 0; i < PIXEL_COUNT; i++) { 39 | x = random(maxx); 40 | y = random(maxy); 41 | color = random(maxcolor); 42 | if (color == getpixel(x, y)) 43 | putpixel(x, y, 0); 44 | } 45 | } 46 | 47 | /* clean up */ 48 | getch(); 49 | closegraph(); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /test/rectangle.c: -------------------------------------------------------------------------------- 1 | /* rectangle example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int left, top, right, bottom; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | left = getmaxx() / 2 - 50; 18 | top = getmaxy() / 2 - 50; 19 | right = getmaxx() / 2 + 50; 20 | bottom = getmaxy() / 2 + 50; 21 | 22 | /* draw a rectangle */ 23 | rectangle(left, top, right, bottom); 24 | 25 | /* clean up */ 26 | getch(); 27 | closegraph(); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /test/restorecrtmode.c: -------------------------------------------------------------------------------- 1 | /* restorecrtmode example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int x, y; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | x = getmaxx() / 2; 18 | y = getmaxy() / 2; 19 | 20 | /* output a message */ 21 | settextjustify(CENTER_TEXT, CENTER_TEXT); 22 | outtextxy(x, y, "Press any key to exit graphics:"); 23 | getch(); 24 | 25 | /* restore system to text mode */ 26 | restorecrtmode(); 27 | printf("We're now in text mode.\n"); 28 | printf("Press any key to return to graphics mode:"); 29 | getch(); 30 | 31 | /* return to graphics mode */ 32 | setgraphmode(getgraphmode()); 33 | 34 | /* output a message */ 35 | settextjustify(CENTER_TEXT, CENTER_TEXT); 36 | outtextxy(x, y, "We're back in graphics mode."); 37 | outtextxy(x, y + textheight("W"), "Press any key to halt:"); 38 | 39 | /* clean up */ 40 | getch(); 41 | closegraph(); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /test/sector.c: -------------------------------------------------------------------------------- 1 | /* sector example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int midx, midy, i; 13 | int stangle = 45, endangle = 135; 14 | int xrad = 100, yrad = 50; 15 | 16 | /* initialize graphics and local variables */ 17 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 18 | 19 | midx = getmaxx() / 2; 20 | midy = getmaxy() / 2; 21 | 22 | /* loop through the fill patterns */ 23 | for (i = EMPTY_FILL; i < USER_FILL; i++) { 24 | 25 | /* set the fill style */ 26 | setfillstyle(i, getmaxcolor()); 27 | 28 | /* draw the sector slice */ 29 | sector(midx, midy, stangle, endangle, xrad, yrad); 30 | 31 | getch(); 32 | } 33 | 34 | /* clean up */ 35 | closegraph(); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /test/setactivepage.c: -------------------------------------------------------------------------------- 1 | /* setactivepage example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* select driver and mode that supports multiple pages */ 11 | int gdriver = DETECT, gmode; 12 | int x, y, ht; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | x = getmaxx() / 2; 18 | y = getmaxy() / 2; 19 | ht = textheight("W"); 20 | 21 | /* select the off screen page for drawing */ 22 | setactivepage(1); 23 | 24 | /* draw a line on page #1 */ 25 | line(0, 0, getmaxx(), getmaxy()); 26 | 27 | /* output a message on page #1 */ 28 | settextjustify(CENTER_TEXT, CENTER_TEXT); 29 | outtextxy(x, y, "This is page #1:"); 30 | outtextxy(x, y + ht, "Press any key to halt:"); 31 | 32 | /* select drawing to page #0 */ 33 | setactivepage(0); 34 | 35 | /* output a message on page #0 */ 36 | outtextxy(x, y, "This is page #0."); 37 | outtextxy(x, y + ht, "Press any key to view page #1:"); 38 | getch(); 39 | 40 | /* select page #1 as the visible page */ 41 | setvisualpage(1); 42 | 43 | /* clean up */ 44 | getch(); 45 | closegraph(); 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /test/setallpalette.c: -------------------------------------------------------------------------------- 1 | /* setallpalette example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | struct palettetype pal; 13 | int color, maxcolor, ht; 14 | int y = 10; 15 | char msg[80]; 16 | 17 | /* initialize graphics and local variables */ 18 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 19 | 20 | maxcolor = getmaxcolor(); 21 | ht = 2 * textheight("W"); 22 | 23 | /* grab a copy of the palette */ 24 | getpalette(&pal); 25 | 26 | /* display the default palette colors */ 27 | for (color = 1; color <= maxcolor; color++) { 28 | setcolor(color); 29 | sprintf(msg, "Color: %d", color); 30 | outtextxy(1, y, msg); 31 | y += ht; 32 | } 33 | 34 | /* wait for a key */ 35 | getch(); 36 | 37 | /* black out the colors one by one */ 38 | for (color = 1; color <= maxcolor; color++) { 39 | setpalette(color, BLACK); 40 | getch(); 41 | } 42 | 43 | /* restore the palette colors */ 44 | /* in Turbo C, onscreen pixels are also chenged */ 45 | setallpalette(&pal); 46 | 47 | /* !!! ADDED - display the default palette colors */ 48 | y = 0; 49 | for (color = 1; color <= maxcolor; color++) { 50 | setcolor(color); 51 | sprintf(msg, "Color: %d", color); 52 | outtextxy(1, y, msg); 53 | y += ht; 54 | } 55 | 56 | /* clean up */ 57 | getch(); 58 | closegraph(); 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /test/setaspectratio.c: -------------------------------------------------------------------------------- 1 | /* setaspectratio example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int xasp, yasp, midx, midy; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | midx = getmaxx() / 2; 18 | midy = getmaxy() / 2; 19 | setcolor(getmaxcolor()); 20 | 21 | /* get current aspect ratio settings */ 22 | getaspectratio(&xasp, &yasp); 23 | 24 | /* draw normal circle */ 25 | circle(midx, midy, 100); 26 | getch(); 27 | 28 | /* clear the screen */ 29 | cleardevice(); 30 | 31 | /* adjust the aspect for a wide circle */ 32 | setaspectratio(xasp / 2, yasp); 33 | 34 | circle(midx, midy, 100); 35 | getch(); 36 | 37 | /* adjust the aspect for a narrow circle */ 38 | cleardevice(); 39 | setaspectratio(xasp, yasp / 2); 40 | circle(midx, midy, 100); 41 | 42 | /* clean up */ 43 | getch(); 44 | closegraph(); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /test/setbkcolor.c: -------------------------------------------------------------------------------- 1 | /* setbkcolor example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* _select driver and mode that supports multiple background colors */ 11 | int gdriver = DETECT, gmode; 12 | int bkcol, maxcolor, x, y; 13 | char msg[80]; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | /* maximum color index supported */ 19 | maxcolor = getmaxcolor(); 20 | 21 | /* for centering text messages */ 22 | settextjustify(CENTER_TEXT, CENTER_TEXT); 23 | x = getmaxx() / 2; 24 | y = getmaxy() / 2; 25 | 26 | /* loop through the available colors */ 27 | for (bkcol = 0; bkcol <= maxcolor; bkcol++) { 28 | 29 | /* clear the screen */ 30 | cleardevice(); 31 | 32 | /* select a new background color */ 33 | setbkcolor(bkcol); 34 | 35 | /* output a messsage */ 36 | if (bkcol == WHITE) 37 | setcolor(BLUE); 38 | sprintf(msg, "Background color: %d", bkcol); 39 | outtextxy(x, y, msg); 40 | getch(); 41 | } 42 | 43 | /* clean up */ 44 | closegraph(); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /test/setcolor.c: -------------------------------------------------------------------------------- 1 | /* setcolor example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* select driver and mode that supports multiple drawing colors */ 11 | int gdriver = DETECT, gmode; 12 | int color, maxcolor, x, y; 13 | char msg[80]; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | /* maximum color index supported */ 19 | maxcolor = getmaxcolor(); 20 | 21 | /* for centering text messages */ 22 | settextjustify(CENTER_TEXT, CENTER_TEXT); 23 | x = getmaxx() / 2; 24 | y = getmaxy() / 2; 25 | 26 | /* loop through the available colors */ 27 | for (color = 1; color <= maxcolor; color++) { 28 | cleardevice(); /* clear the screen */ 29 | setcolor(color); /* select new background color */ 30 | 31 | /* output a messsage */ 32 | sprintf(msg, "Color: %d", color); 33 | outtextxy(x, y, msg); 34 | getch(); 35 | } 36 | 37 | /* clean up */ 38 | closegraph(); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /test/setfillpattern.c: -------------------------------------------------------------------------------- 1 | /* setfillpattern example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int maxx, maxy; 13 | 14 | /* a user-defined fill pattern */ 15 | char pattern[8] = { 0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00 }; 16 | 17 | /* initialize graphics and local variables */ 18 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 19 | 20 | maxx = getmaxx(); 21 | maxy = getmaxy(); 22 | setcolor(getmaxcolor()); 23 | 24 | /* select a user-defined fill pattern */ 25 | setfillpattern(pattern, getmaxcolor()); 26 | 27 | /* fill the screen with the pattern */ 28 | bar(0, 0, maxx, maxy); 29 | 30 | /* clean up */ 31 | getch(); 32 | closegraph(); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/setfillstyle.c: -------------------------------------------------------------------------------- 1 | /* setfillstyle example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /* the names of the fill styles supported */ 10 | char *fname[] = 11 | { "EMPTY_FILL", "SOLID_FILL", "LINE_FILL", "LTSLASH_FILL", 12 | "SLASH_FILL", "BKSLASH_FILL", "LTBKSLASH_FILL", "HATCH_FILL", 13 | "XHATCH_FILL", "INTERLEAVE_FILL", "WIDE_DOT_FILL", "CLOSE_DOT_FILL", 14 | "USER_FILL" }; 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | /* request autodetection */ 19 | int gdriver = DETECT, gmode; 20 | int style, midx, midy; 21 | 22 | char stylestr[40]; 23 | 24 | /* initialize graphics and local variables */ 25 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 26 | 27 | midx = getmaxx() / 2; 28 | midy = getmaxy() / 2; 29 | 30 | for (style = EMPTY_FILL; style < USER_FILL; style++) { 31 | /* select the fill style */ 32 | setfillstyle(style, getmaxcolor()); 33 | 34 | /* convert style into a string */ 35 | strcpy(stylestr, fname[style]); 36 | 37 | /* fill a bar */ 38 | bar3d(0, 0, midx - 10, midy, 0, 0); 39 | 40 | /* output a message */ 41 | outtextxy(midx, midy, stylestr); 42 | 43 | /* wait for a key */ 44 | getch(); 45 | cleardevice(); 46 | } 47 | 48 | /* clean up */ 49 | getch(); 50 | closegraph(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /test/setgraphbufsize.c: -------------------------------------------------------------------------------- 1 | /* setgraphbufsize example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define BUFSIZE 1000 /* internal graphics buffer size */ 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | /* request autodetection */ 13 | int gdriver = DETECT, gmode; 14 | int x, y, oldsize; 15 | char msg[80]; 16 | 17 | /* _set size of internal graphics buffer before calling initgraph */ 18 | oldsize = setgraphbufsize(BUFSIZE); 19 | 20 | /* initialize graphics and local variables */ 21 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 22 | 23 | x = getmaxx() / 2; 24 | y = getmaxy() / 2; 25 | 26 | /* output some messages */ 27 | sprintf(msg, "Graphics buffer size: %d", BUFSIZE); 28 | settextjustify(CENTER_TEXT, CENTER_TEXT); 29 | 30 | outtextxy(x, y, msg); 31 | sprintf(msg, "Old graphics buffer size: %d", oldsize); 32 | outtextxy(x, y + textheight("W"), msg); 33 | 34 | /* clean up */ 35 | getch(); 36 | closegraph(); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /test/setgraphmode.c: -------------------------------------------------------------------------------- 1 | /* setgraphmode example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int x, y; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | x = getmaxx() / 2; 18 | y = getmaxy() / 2; 19 | 20 | /* output a message */ 21 | settextjustify(CENTER_TEXT, CENTER_TEXT); 22 | outtextxy(x, y, "Press any key to exit graphics:"); 23 | getch(); 24 | 25 | /* restore system to text mode */ 26 | restorecrtmode(); 27 | printf("We're now in text mode.\n"); 28 | printf("Press any key to return to graphics mode:"); 29 | getch(); 30 | 31 | /* return to graphics mode */ 32 | setgraphmode(getgraphmode()); 33 | 34 | /* output a message */ 35 | settextjustify(CENTER_TEXT, CENTER_TEXT); 36 | outtextxy(x, y, "We're back in graphics mode."); 37 | outtextxy(x, y + textheight("W"), "Press any key to halt:"); 38 | 39 | /* clean up */ 40 | getch(); 41 | closegraph(); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /test/setlinestyle.c: -------------------------------------------------------------------------------- 1 | /* setlinestyle example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /* the names of the line styles supported */ 10 | char *lname[] = 11 | { "SOLID_LINE", "DOTTED_LINE", "CENTER_LINE", "DASHED_LINE", 12 | "USERBIT_LINE" }; 13 | 14 | int main(int argc, char *argv[]) 15 | { 16 | /* request autodetection */ 17 | int gdriver = DETECT, gmode; 18 | int style, midx, midy, userpat; 19 | char stylestr[40]; 20 | 21 | /* initialize graphics and local variables */ 22 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 23 | 24 | midx = getmaxx() / 2; 25 | midy = getmaxy() / 2; 26 | 27 | /* a user-defined line pattern */ 28 | /* binary: "0000000000000001" */ 29 | userpat = 1; 30 | for (style = SOLID_LINE; style <= USERBIT_LINE; style++) { 31 | /* select the line style */ 32 | setlinestyle(style, userpat, 1); 33 | 34 | /* convert style into a string */ 35 | strcpy(stylestr, lname[style]); 36 | 37 | /* draw a line */ 38 | line(0, 0, midx - 10, midy); 39 | 40 | /* draw a rectangle */ 41 | rectangle(0, 0, getmaxx(), getmaxy()); 42 | 43 | /* output a message */ 44 | outtextxy(midx, midy, stylestr); 45 | 46 | /* wait for a key */ 47 | getch(); 48 | cleardevice(); 49 | } 50 | 51 | /* clean up */ 52 | closegraph(); 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /test/setpalette.c: -------------------------------------------------------------------------------- 1 | /* setpalette example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int color, maxcolor, ht; 13 | int y = 10; 14 | char msg[80]; 15 | 16 | /* initialize graphics and local variables */ 17 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 18 | 19 | maxcolor = getmaxcolor(); 20 | ht = 2 * textheight("W"); 21 | 22 | /* display the default colors */ 23 | for (color = 1; color <= maxcolor; color++) { 24 | setcolor(color); 25 | sprintf(msg, "Color: %d", color); 26 | outtextxy(1, y, msg); 27 | y += ht; 28 | } 29 | 30 | /* wait for a key */ 31 | getch(); 32 | 33 | /* black out the colors one by one */ 34 | for (color = 1; color <= maxcolor; color++) { 35 | setpalette(color, BLACK); 36 | getch(); 37 | } 38 | 39 | /* clean up */ 40 | closegraph(); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /test/settextjustify.c: -------------------------------------------------------------------------------- 1 | /* settextjustify example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /* function prototype */ 9 | void xat(int x, int y); 10 | 11 | /* horizontal text justification settings */ 12 | char *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; 13 | 14 | /* vertical text justification settings */ 15 | char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | /* request autodetection */ 20 | int gdriver = DETECT, gmode; 21 | int midx, midy, hj, vj; 22 | 23 | char msg[80]; 24 | 25 | /* initialize graphics and local variables */ 26 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 27 | 28 | midx = getmaxx() / 2; 29 | midy = getmaxy() / 2; 30 | 31 | /* loop through text justifications */ 32 | for (hj = LEFT_TEXT; hj <= RIGHT_TEXT; hj++) 33 | for (vj = LEFT_TEXT; vj <= RIGHT_TEXT; vj++) { 34 | cleardevice(); 35 | 36 | /* set the text justification */ 37 | settextjustify(hj, vj); 38 | 39 | /* create a message string */ 40 | sprintf(msg, "%s %s", hjust[hj], vjust[vj]); 41 | 42 | /* create crosshairs on the screen */ 43 | xat(midx, midy); 44 | 45 | /* output the message */ 46 | outtextxy(midx, midy, msg); 47 | 48 | getch(); 49 | } 50 | 51 | /* clean up */ 52 | closegraph(); 53 | return 0; 54 | } 55 | 56 | void xat(int x, int y) 57 | { /* draw an x at (x,y) */ 58 | line(x - 4, y, x + 4, y); 59 | line(x, y - 4, x, y + 4); 60 | } 61 | -------------------------------------------------------------------------------- /test/settextstyle.c: -------------------------------------------------------------------------------- 1 | /* settextstyle example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /* the names of the text styles supported */ 9 | char *fname[] = { "DEFAULT font", "TRIPLEX font", 10 | "SMALL font", "SANS SERIF_font", 11 | "GOTHIC_font", "SCRIPT font", 12 | "SIMPLEX font", "TRIPLEX SCRIPT font", 13 | "COMPLEX font", "EUROPEAN font", 14 | "BOLD font" 15 | }; 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | /* request autodetection */ 20 | 21 | int gdriver = DETECT, gmode; 22 | int style, midx, midy; 23 | int size = 1; 24 | 25 | /* initialize graphics and local variables */ 26 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 27 | 28 | midx = getmaxx() / 2; 29 | midy = getmaxy() / 2; 30 | settextjustify(CENTER_TEXT, CENTER_TEXT); 31 | 32 | /* loop through the available text styles */ 33 | for (style = DEFAULT_FONT; style <= BOLD_FONT; style++) { 34 | cleardevice(); 35 | if (style == TRIPLEX_FONT) 36 | size = 4; 37 | /* select the text style */ 38 | settextstyle(style, HORIZ_DIR, size); 39 | 40 | /* output a message */ 41 | outtextxy(midx, midy, fname[style]); 42 | getch(); 43 | } 44 | /* clean up */ 45 | 46 | closegraph(); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /test/setusercharsize.c: -------------------------------------------------------------------------------- 1 | /* setusercharsize example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | 13 | /* initialize graphics and local variables */ 14 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 15 | 16 | /* select a text style */ 17 | settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); 18 | 19 | /* move to the text starting position */ 20 | moveto(0, getmaxy() / 2); 21 | 22 | /* output some normal text */ 23 | outtext("Norm "); 24 | 25 | /* make the text 1/3 the normal width */ 26 | setusercharsize(1, 3, 1, 1); 27 | outtext("Short "); 28 | 29 | /* make the text 3 times normal width */ 30 | setusercharsize(3, 1, 1, 1); 31 | 32 | outtext("Wide"); 33 | 34 | /* clean up */ 35 | getch(); 36 | closegraph(); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /test/setviewport.c: -------------------------------------------------------------------------------- 1 | /* setviewport example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define CLIP_ON 1 /* activates clipping in viewport */ 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | /* request autodetection */ 13 | int gdriver = DETECT, gmode; 14 | 15 | /* initialize graphics and local variables */ 16 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 17 | 18 | setcolor(getmaxcolor()); 19 | 20 | /* message in default full-screen viewport */ 21 | outtextxy(0, 0, "* <-- (0, 0) in default viewport"); 22 | 23 | /* create a smaller viewport */ 24 | setviewport(50, 50, getmaxx() - 50, getmaxy() - 50, CLIP_ON); 25 | 26 | /* display some text */ 27 | outtextxy(0, 0, "* <-- (0, 0) in smaller viewport"); 28 | 29 | /* clean up */ 30 | getch(); 31 | closegraph(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /test/setvisualpage.c: -------------------------------------------------------------------------------- 1 | /* setvisualpage example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* select driver and mode that supports multiple pages */ 11 | int gdriver = DETECT, gmode; 12 | int x, y, ht; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | x = getmaxx() / 2; 18 | y = getmaxy() / 2; 19 | ht = textheight("W"); 20 | 21 | /* select the off screen page for drawing */ 22 | setactivepage(1); 23 | 24 | /* draw a line on page #1 */ 25 | line(0, 0, getmaxx(), getmaxy()); 26 | 27 | /* output a message on page #1 */ 28 | settextjustify(CENTER_TEXT, CENTER_TEXT); 29 | outtextxy(x, y, "This is page #1:"); 30 | outtextxy(x, y + ht, "Press any key to halt:"); 31 | 32 | /* select drawing to page #0 */ 33 | setactivepage(0); 34 | 35 | /* output a message on page #0 */ 36 | outtextxy(x, y, "This is page #0."); 37 | outtextxy(x, y + ht, "Press any key to view page #1:"); 38 | getch(); 39 | 40 | /* select page #1 as the visible page */ 41 | setvisualpage(1); 42 | 43 | /* clean up */ 44 | getch(); 45 | closegraph(); 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /test/setwritemode.c: -------------------------------------------------------------------------------- 1 | /* setwritemode example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int xmax, ymax; 13 | 14 | /* initialize graphics and local variables */ 15 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 16 | 17 | xmax = getmaxx(); 18 | ymax = getmaxy(); 19 | 20 | /* select XOR drawing mode */ 21 | setwritemode(XOR_PUT); 22 | 23 | /* draw a line */ 24 | line(0, 0, xmax, ymax); 25 | getch(); 26 | 27 | /* erase the line by drawing over it */ 28 | line(0, 0, xmax, ymax); 29 | getch(); 30 | 31 | /* select overwrite drawing mode */ 32 | setwritemode(COPY_PUT); 33 | 34 | /* draw a line */ 35 | line(0, 0, xmax, ymax); 36 | 37 | /* clean up */ 38 | getch(); 39 | closegraph(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /test/textheight.c: -------------------------------------------------------------------------------- 1 | /* textheight example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int y = 0; 13 | int i; 14 | char msg[80]; 15 | 16 | /* initialize graphics and local variables */ 17 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 18 | 19 | /* draw some text on the screen */ 20 | for (i = 1; i < 11; i++) { 21 | /* select the text style, direction, and size */ 22 | settextstyle(TRIPLEX_FONT, HORIZ_DIR, i); 23 | 24 | /* create a message string */ 25 | sprintf(msg, "Size: %d", i); 26 | 27 | /* output the message */ 28 | outtextxy(1, y, msg); 29 | 30 | /* advance to the next text line */ 31 | y += textheight(msg); 32 | } 33 | 34 | /* clean up */ 35 | getch(); 36 | closegraph(); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /test/textwidth.c: -------------------------------------------------------------------------------- 1 | /* textwidth example */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | /* request autodetection */ 11 | int gdriver = DETECT, gmode; 12 | int x = 0, y = 0; 13 | int i; 14 | char msg[80]; 15 | 16 | /* initialize graphics and local variables */ 17 | initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); 18 | 19 | y = getmaxy() / 2; 20 | settextjustify(LEFT_TEXT, CENTER_TEXT); 21 | for (i = 1; i < 11; i++) { 22 | /* select the text style, direction, and size */ 23 | settextstyle(TRIPLEX_FONT, HORIZ_DIR, i); 24 | 25 | /* create a message string */ 26 | sprintf(msg, "Size: %d", i); 27 | 28 | /* output the message */ 29 | outtextxy(x, y, msg); 30 | 31 | /* advance to the end of the text */ 32 | x += textwidth(msg); 33 | } 34 | 35 | /* clean up */ 36 | getch(); 37 | closegraph(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /tmp/README.md: -------------------------------------------------------------------------------- 1 | These are helper programs: 2 | 3 | - `bgi_palette.png` is a screenshot taken from Turbo C 2.01 running in 4 | DosBox. The `bgi_orig_palette` palette uses colours picked up from this 5 | file. 6 | 7 | - `chr_decoder.c` dumps a `.CHR` font in a more readable format. 8 | 9 | - `dumpchar.c` is used to dump VGA characters used by Turbo C 2.01 in 10 | DosBox. 11 | 12 | - `icon.c` writes the `icon.bmp` icon, later converted to PNG. 13 | 14 | - `truncate.c` shows a bug in Turbo C 2.01; text is not truncated out 15 | of the viewport as it should be. This bug is fixed in Turbo C++ 3. 16 | -------------------------------------------------------------------------------- /tmp/bgi_palette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergev/SDL_bgi/217057ec5727a74b34adf29738a9ebcb52324e21/tmp/bgi_palette.png -------------------------------------------------------------------------------- /tmp/dumpchar.c: -------------------------------------------------------------------------------- 1 | /* dumpchar.c */ 2 | 3 | /* This program dumps the bytes that make up a character */ 4 | 5 | #include 6 | #include 7 | 8 | FILE 9 | *dump; 10 | 11 | void dumpchar (unsigned char ch) 12 | { 13 | int 14 | x, y; 15 | char 16 | str[2]; 17 | unsigned char 18 | byte; 19 | 20 | str[0] = ch; 21 | str[1] = '\0'; 22 | cleardevice (); 23 | outtextxy (0, 0, str); 24 | 25 | for (y = 0; y < 8; y++) { 26 | byte = 0; 27 | for (x = 0; x < 8; x++) 28 | if (RED == getpixel (x, y)) 29 | byte |= (1 << (7 - x)); 30 | fprintf (dump, "0x%02x,", byte & 0xff); 31 | } 32 | fprintf (dump, " // %02d 0x%02x '%c'\n", ch, ch & 0xff, ch); 33 | } 34 | 35 | /* ----- */ 36 | 37 | int main (int argc, char *argv[]) 38 | { 39 | int 40 | x, y, 41 | gd = DETECT, gm, 42 | byte; 43 | 44 | dump = fopen ("vgadump.dat", "w"); 45 | 46 | initgraph (&gd, &gm, ""); 47 | setcolor (RED); 48 | setbkcolor (BLACK); 49 | 50 | for (byte = 0; byte < 256; byte++) 51 | dumpchar ((unsigned char) byte); 52 | 53 | closegraph (); 54 | fclose (dump); 55 | 56 | } 57 | 58 | /* --- end of file dumpchar.c */ 59 | -------------------------------------------------------------------------------- /tmp/icon.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (int argc, int *argv[]) 4 | { 5 | SDL_Surface *surface; 6 | 7 | initwindow (256, 256); 8 | setbkcolor (COLOR (240, 240, 240)); 9 | setfillstyle (SOLID_FILL, WHITE); 10 | cleardevice (); 11 | fillellipse (128, 128, 110, 110); 12 | settextstyle (TRIPLEX_FONT, HORIZ_DIR, 9); 13 | for (int r = 110; r < 180; r++) { 14 | setcolor (COLOR (r / 2, 30 + r / 2, 60 + r / 2)); 15 | circle (128, 128, r); 16 | } 17 | setcolor (COLOR (0, 0, 160)); 18 | outtextxy (42, 40, "SDL"); 19 | outtextxy (43, 40, "SDL"); 20 | outtextxy (42, 41, "SDL"); 21 | outtextxy (43, 41, "SDL"); 22 | setcolor (COLOR (180, 0, 0)); 23 | outtextxy (72, 90, "BGI"); 24 | outtextxy (73, 90, "BGI"); 25 | outtextxy (72, 91, "BGI"); 26 | outtextxy (73, 91, "BGI"); 27 | refresh (); 28 | surface = SDL_GetWindowSurface (bgi_window); 29 | SDL_SaveBMP (surface, "icon.bmp"); 30 | 31 | getch (); 32 | closegraph (); 33 | } -------------------------------------------------------------------------------- /tmp/truncate.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This program shows a bug in Turbo C 2.01; the first string is not 4 | truncated in TC, but is truncated in SDL_bgi as per original Borland 5 | documentation: "If a string is printed with the default font using 6 | outtext or outtextxy, any part of the string that extends outside the 7 | current viewport is truncated." (Borland Turbo C 2.0 Reference Guide 8 | 1988, pag. 261) 9 | 10 | */ 11 | 12 | #include 13 | 14 | int main (int argc, char *argv[]) 15 | { 16 | int 17 | gd = DETECT, gm; 18 | 19 | initgraph (&gd, &gm, ""); 20 | setbkcolor (WHITE); 21 | setcolor (RED); 22 | cleardevice (); 23 | rectangle (100, 100, 500, 400); 24 | setviewport (100, 100, 500, 400, 1); 25 | outtextxy (0, 0, "The text below is NOT truncated:"); 26 | outtextxy (0, 40, "The text below is truncated:"); 27 | settextjustify (CENTER_TEXT, CENTER_TEXT); 28 | outtextxy (0, 20, "Truncated"); 29 | settextstyle (TRIPLEX_FONT, HORIZ_DIR, 4); 30 | outtextxy (0, 80, "Truncated"); 31 | 32 | getch (); 33 | closegraph (); 34 | 35 | } 36 | 37 | /* --- end of file truncate.c */ 38 | --------------------------------------------------------------------------------