diff --git a/BUGS b/BUGS index 64410fe..06e1815 100644 --- a/BUGS +++ b/BUGS @@ -1,17 +1,15 @@ BUGS ---- -- visualisation problems on NVIDIA GK208BM (GeForce 920M) with -nvidia-driver-450 on GNU/Linux. As far as I can say, this is an NVIDIA +- automatic refresh does not work on NVIDIA GK208BM (GeForce 920M) with +nvidia-driver-* on GNU/Linux. As far as I can say, this is an NVIDIA driver problem. -- In MSYS2 + Mingw-w64, the getch() function may hang. This is a -problem in MSYS2/Mingw-w64 console handling. +- In MSYS2 + Mingw-w64, the getch() function may hang. Apparently, +this is a problem in MSYS2/Mingw-w64 console handling. -- According to the original BGI documentation: "If a string is printed -with the default font using outtext or outtextxy, any part of the -string that extends outside the current viewport is truncated." -SDL_bgi follows this rule, but bgidemo.c running in Turbo C 2.01 does -not. This is a Turbo C bug; please see `tmp/truncate.c`. +- in Raspbian 10 for ARM, the 'p' letter is drawn incorrectly in +SCRIPT_FONT. The bug does not affect Raspbian 10 for i386. +Reported by Ioulianos Kakoulidis. Please report bugs if you find any. diff --git a/CMakeLists.txt b/CMakeLists.txt index 912cc81..5867f87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ # CMakeLists.txt for SDL_bgi -# GG, 2020-07-08 +# GG, 2021-02-24 # --- Building, thanks to cmake cmake_minimum_required (VERSION 3.5.0) -set (SDL_BGI_VERSION 2.4.2) +set (SDL_BGI_VERSION 2.4.3) # Project name project (SDL_bgi VERSION ${SDL_BGI_VERSION} LANGUAGES C) @@ -56,6 +56,10 @@ install (FILES AUTHORS BUGS ChangeLog INSTALL_Linux.md INSTALL_macOS.md file (GLOB docs doc/*) install (FILES ${docs} DESTINATION ${CMAKE_INSTALL_DOCDIR}/doc) +# Install man page +file (GLOB man doc/graphics.3.gz) +install (FILES ${man} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3) + # Install test programs file (GLOB test test/*) install (FILES ${test} DESTINATION ${CMAKE_INSTALL_DOCDIR}/test) @@ -80,14 +84,14 @@ set (CPACK_DEBIAN_PACKAGE_NAME "sdl_bgi") set (CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}) set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${ARCH_DEB}) set (CPACK_DEBIAN_PACKAGE_MAINTAINER ${CONTACT}) -set (CPACK_DEBIAN_PACKAGE_DESCRIPTION "BGI-compatible, SDL2-based library") +set (CPACK_DEBIAN_PACKAGE_DESCRIPTION "SDL2-based 'GRAPHICS.H' implementation") set (CPACK_DEBIAN_PACKAGE_SECTION "libs") set (CPACK_DEBIAN_COMPRESSION_TYPE "gzip") set (CPACK_DEBIAN_PACKAGE_PRIORITY "optional") set (CPACK_DEBIAN_PACKAGE_DEPENDS "libsdl2-dev (>= 2.0.0)") # RPM (Fedora) package -set (CPACK_RPM_PACKAGE_SUMMARY "BGI-compatible, SDL2-based library") +set (CPACK_RPM_PACKAGE_SUMMARY "SDL2-based 'GRAPHICS.H' implementation") set (CPACK_RPM_PACKAGE_NAME ${CPACK_PACKAGE_NAME}) set (CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}) set (CPACK_PACKAGE_ARCHITECTURE ${ARCH_RPM}) @@ -95,7 +99,8 @@ set (CPACK_RPM_PACKAGE_RELEASE "1") set (CPACK_RPM_PACKAGE_LICENSE "zlib") set (CPACK_RPM_PACKAGE_GROUP "Development/Libraries") set (CPACK_RPM_PACKAGE_VENDOR "GG") -set (CPACK_RPM_PACKAGE_DESCRIPTION "SDL_bgi is a Borland Graphics Interface (BGI) emulation library based on SDL2. This library strictly emulates most BGI functions, making it possible to compile SDL versions of programs written for Turbo/Borland C. ARGB extensions and basic mouse support are also implemented; further, native SDL2 functions may be used in SDL_bgi programs.") +set (CPACK_RPM_PACKAGE_DESCRIPTION "SDL_bgi is a Borland Graphics Interface ('GRAPHICS.H') implementation based on SDL2. This library strictly emulates BGI functions, making it possible to compile SDL2 versions of programs written for Turbo C/Borland C++. ARGB colours, vector fonts, mouse support, and multiple +windows are also implemented; further, native SDL2 functions may be used in SDL_bgi programs.") set (CPACK_RPM_PACKAGE_REQUIRES "SDL2-devel >= 2.0.0") set (CPACK_PACKAGE_CONTACT ${CONTACT}) diff --git a/ChangeLog b/ChangeLog index b90af88..708a40a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,15 @@ Changelog --------- +v. 2.4.3, 2021-02-24 +- modified getscreensize() behaviour (suggested by Fanourios Attard) +- added setwintitle() +- added man page (graphics.3) +- documentation fixes and updates +- changed test/simple.c to avoid getch() bug on MSYS2 +- updated Windows Makefiles to SDL2-2.0.14 and latest releases of + Code::Blocks and DevCpp + v. 2.4.2, 2020-11-11 - implemented native vector fonts, compatible with Borland .CHR fonts - implemented long-forgotten graphics error checks! diff --git a/INSTALL_Linux.md b/INSTALL_Linux.md index 9e3bc6c..16fab4a 100644 --- a/INSTALL_Linux.md +++ b/INSTALL_Linux.md @@ -19,7 +19,7 @@ you'll also need `make` and a C compiler; `gcc` or `clang` are fine. To compile and install `SDL_bgi`, run the following commands: - $ VERSION=2.4.2 + $ VERSION=2.4.3 $ tar zxvf SDL_bgi-$VERSION.tar.gz $ cd SDL_bgi-$VERSION/src $ make @@ -27,9 +27,9 @@ To compile and install `SDL_bgi`, run the following commands: Files will be installed in appropriate directories: -`SDL_bgi.h` -> `/usr/include/SDL2/` -`graphics.h` -> `/usr/include/` -`libSDL_bgi.so` -> `/usr/lib/`. + SDL_bgi.h -> /usr/include/SDL2/ + graphics.h -> /usr/include/ + libSDL_bgi.so -> /usr/lib/ ### Using `cmake` @@ -38,7 +38,7 @@ This only works if `cmake` and `cpack` are installed. To compile the `SDL_bgi` library and make `.deb` or `.rpm` packages: - $ VERSION=2.4.2 + $ VERSION=2.4.3 $ tar zxvf SDL_bgi-$VERSION.tar.gz $ cd SDL_bgi-$VERSION $ ./build.sh @@ -54,6 +54,10 @@ If you prefer the usual way: $ cmake .. $ make && sudo make install +To uninstall: + + $ make uninstall + ## Test Programs diff --git a/INSTALL_Windows.md b/INSTALL_Windows.md index d26d64e..2bae443 100644 --- a/INSTALL_Windows.md +++ b/INSTALL_Windows.md @@ -17,26 +17,28 @@ The following sections were tested with: Let's assume you installed SDL2 as native package, that is `mingw-w64-x86_64-SDL2`. -Start the MSYS2 shell, unzip the `SDL_bgi` archive, then copy -`src/graphics.h` to `/mingw64/include/`, `src/SDL_bgi.h` to -`/mingw64/include/SDL2/`, and `bin/Mingw64/SDL_bgi.dll` to -`/mingw64/bin`. +Start the MSYS2 shell, unzip the `SDL_bgi` archive, then copy: + + src/graphics.h -> /mingw64/include/ + src/SDL_bgi.h -> /mingw64/include/SDL2/ + bin/Mingw64/SDL_bgi.dll -> /mingw64/bin Please note that to run a program compiled with `SDL_bgi` outside of -the MSYS2 environment, you will need to copy `SDL_bgi.dll` and -`SDL2.dll` to the same directory as the program. +the MSYS2 environment (e.g. in an ordinary command prompt), you will need +to copy `SDL_bgi.dll` and `SDL2.dll` to the same directory as the program. ## Installing the Code::Blocks Binaries Let's assume that you installed CodeBlocks in `C:\CodeBlocks` and SDL2 -development libraries in in `C:\SDL2-2.0.12`. Change the following +development libraries in in `C:\SDL2-2.0.14`. Change the following instructions as needed for your installation. -Unzip `SDL_bgi` archive, then copy `src/graphics.h` to -`C:\CodeBlocks\MinGW\include`, `src/SDL_bgi.h` to -`C:\SDL2-2.0.12\i686-w64-mingw32\include\SDL2`, and -`bin/CodeBlocks/SDL_bgi.dll` to `C:\CodeBlocks\MinGW\bin`. +Unzip `SDL_bgi` archive, then copy: + + src/graphics.h -> C:\CodeBlocks\MinGW\include + src/SDL_bgi.h -> C:\SDL2-2.0.14\i686-w64-mingw32\include\SDL2 + bin/CodeBlocks/SDL_bgi.dll -> C:\CodeBlocks\MinGW\bin To learn how to compile programs, please see `howto_CodeBlocks.md`. @@ -44,13 +46,14 @@ To learn how to compile programs, please see `howto_CodeBlocks.md`. ## Installing the Dev-C++ Binaries Let's assume that you installed Dev-C++ in `C:\DevCpp` and SDL2 -in `C:\SDL2-2.0.12`. Change the following instructions as needed for +in `C:\SDL2-2.0.14`. Change the following instructions as needed for your installation. -Unzip `SDL_bgi` archive, then copy `src/graphics.h` to -`C:\SDL2-2.0.12\i686-w64-mingw32\include`, `src/SDL_bgi.h` to -`C:\SDL2-2.0.12\i686-w64-mingw32\include\SDL2`, and -`bin/DevCpp/SDL_bgi.dll` to `C:\DevCpp\MinGW64\bin`. +Unzip `SDL_bgi` archive, then copy: + + src/graphics.h -> C:\SDL2-2.0.14\i686-w64-mingw32\include + src/SDL_bgi.h -> C:\SDL2-2.0.14\i686-w64-mingw32\include\SDL2 + bin/DevCpp/SDL_bgi.dll -> C:\DevCpp\MinGW64\bin To learn how to compile programs, please see `howto_DevCpp.md`. @@ -67,14 +70,15 @@ install `make`, `mingw-w64-x86_64-SDL2`, and `mingw-w64-x86_64-gcc`. $ pacman -S make mingw-w64-x86_64-SDL2 mingw-w64-x86_64-gcc # ... - $ # expand the $PATH variable + $ # expand the $PATH variable if necessary $ echo export PATH=/mingw64/bin:$PATH >> $HOME/.bashrc + ## MSYS2 + Mingw-w64 Start the MSYS2 shell, then run the following commands: - $ VERSION=2.4.2 + $ VERSION=2.4.3 $ tar zxvf SDL_bgi-$VERSION.tar.gz $ cd SDL_bgi-$VERSION/src $ make @@ -82,47 +86,51 @@ Start the MSYS2 shell, then run the following commands: Files will be installed in these directories: -`SDL_bgi_.h` -> `/mingw64/include/SDL2/` -`graphics.h` -> `/mingw64/include/` -`SDL_bgi.dll` -> `/mingw64/bin/` + SDL_bgi.h -> /mingw64/include/SDL2/ + graphics.h -> /mingw64/include/ + SDL_bgi.dll -> /mingw64/bin/ + +To uninstall: + + $ make uninstall ## MSYS2 + Code::Blocks Start the MSYS2 shell, then run the following commands: - $ VERSION=2.4.2 + $ VERSION=2.4.3 $ tar zxvf SDL_bgi-$VERSION.tar.gz $ cd SDL_bgi-$VERSION/src $ PATH=/c/CodeBlocks/MinGW/bin/:$PATH && make -f Makefile.CodeBlocks $ make install Assuming that you installed CodeBlocks in `C:\CodeBlocks` and SDL2 -development libraries in in `C:\SDL2-2.0.12`, files will be installed +development libraries in in `C:\SDL2-2.0.14`, files will be installed in these directories: -`SDL_bgi_.h` -> `C:\SDL2-2.0.12\i686-w64-mingw32\include\SDL2` -`graphics.h` -> `C:\CodeBlocks\MinGW\include` -`SDL_bgi.dll` -> `C:\CodeBlocks\MinGW\bin` + SDL_bgi_.h -> C:\SDL2-2.0.14\i686-w64-mingw32\include\SDL2 + graphics.h -> C:\CodeBlocks\MinGW\include + SDL_bgi.dll -> C:\CodeBlocks\MinGW\bin ## MSYS2 + Dev-C++ Start the MSYS2 shell, then run the following commands: - $ VERSION=2.4.2 + $ VERSION=2.4.3 $ tar zxvf SDL_bgi-$VERSION.tar.gz $ cd SDL_bgi-$VERSION/src $ PATH=/c/CodeBlocks/MinGW/bin/:$PATH && make -f Makefile.DevCpp $ make install Assuming that you installed Dev-C++ in `C:\DevCpp` and SDL2 -development libraries in in `C:\SDL2-2.0.12`, files will be installed +development libraries in in `C:\SDL2-2.0.14`, files will be installed in these directories: -`SDL_bgi_.h` -> `C:\SDL2-2.0.12\i686-w64-mingw32\include\SDL2` -`graphics.h` -> `C:\SDL2-2.0.12\i686-w64-mingw32\include` -`SDL_bgi.dll` -> `C:\DevCpp\MinGW64\bin` + SDL_bgi_.h -> C:\SDL2-2.0.14\i686-w64-mingw32\include\SDL2 + graphics.h -> C:\SDL2-2.0.14\i686-w64-mingw32\include + SDL_bgi.dll -> C:\DevCpp\MinGW64\bin ## Test Programs diff --git a/INSTALL_macOS.md b/INSTALL_macOS.md index 2d57341..aafb1a0 100644 --- a/INSTALL_macOS.md +++ b/INSTALL_macOS.md @@ -5,7 +5,7 @@ The easiest way to install `SDL_bgi` requires the Terminal, the Full Xcode is not needed. - open the Terminal and type `clang`. If it's missing, you'll be - prompted to install it, as part of the Command Line Tools. + prompted to install it, as part of Xcode's Command Line Tools. - go to and install Homebrew using the provided command. It will take a few minutes. @@ -24,7 +24,7 @@ You're now ready to compile `SDL_bgi`. To compile and install `SDL_bgi`, start Terminal and run the following commands: - % VERSION=2.4.2 + % VERSION=2.4.3 % tar xvf SDL_bgi-$VERSION.tar % cd SDL_bgi-$VERSION/src % make @@ -32,9 +32,13 @@ commands: Files will be installed in these directories: -`SDL_bgi.h` -> `/usr/local/include/SDL2` -`graphics.h` -> `/usr/local/include/` -`libSDL_bgi.so` -> `/usr/local/lib/` + SDL_bgi.h -> /usr/local/include/SDL2/ + graphics.h -> /usr/local/include/ + libSDL_bgi.so -> /usr/local/lib/ + +To uninstall: + + % make uninstall ## Test Programs diff --git a/LICENSE b/LICENSE index 212a7e8..19cbdde 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ // ZLib License -Copyright (c) 2014-2020 Guido Gonzato, PhD +Copyright (c) 2014-2021 Guido Gonzato, PhD This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/README.md b/README.md index 125c75f..5921625 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ README `SDL_bgi` is a multiplatform, SDL2-based `GRAPHICS.H` implementation. -Its name refers to BGI, the Borland Graphics Interface that was the +The name refers to BGI, the Borland Graphics Interface that was the 'de facto' standard in PC graphics back in DOS days; it was made popular by Borland Turbo C/C++ compilers. I wrote `SDL_bgi` because I wanted a simple to use but fast graphics library for my experiments @@ -14,7 +14,7 @@ in Turbo C 2.01 and Borland C++ 1.0; for instance, it compiles and runs the original `bgidemo.c`. `SDL_bgi` also provides nearly full compatibility with another BGI implementation, WinBGIm (see links below). One of the aims of `SDL_bgi` is the preservation of old -software written for BGI, but not only. +software written for BGI; but not only that. `SDL_bgi` provides graphics primitives, and is much easier to use than plain SDL2. It should be especially useful for beginners, i.e. in @@ -26,8 +26,8 @@ programs, too. `SDL_bgi` should compile on any platform supported by SDL2; it has been tested on GNU/Linux, MS Windows (MSYS2 + Mingw-w64, CodeBlocks, -Dev-C++), macOS (High Sierra and Catalina), and Raspberry Pi. A few -example programs are provided in the `test/` directory. +Dev-C++), macOS (High Sierra and Catalina), and Raspios (ARM, i386). A +few example programs are provided in the `test/` directory. If you don't need BGI compatibility, I suggest that you check out `SDL_gfx`, a graphics library that is more complete and more powerful diff --git a/TODO b/TODO index 96ae0d7..0984479 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,6 @@ TODO ---- +Nothing at the moment. + Your suggestions are welcome! diff --git a/VERSION b/VERSION index 8e8299d..35cee72 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.4.2 +2.4.3 diff --git a/bin/CodeBlocks/README b/bin/CodeBlocks/README new file mode 100644 index 0000000..88f7e6f --- /dev/null +++ b/bin/CodeBlocks/README @@ -0,0 +1 @@ +Built with CodeBlocks 20.03 + Mingw64 diff --git a/bin/CodeBlocks/SDL_bgi.dll b/bin/CodeBlocks/SDL_bgi.dll index a2e164a..b0d703d 100644 Binary files a/bin/CodeBlocks/SDL_bgi.dll and b/bin/CodeBlocks/SDL_bgi.dll differ diff --git a/bin/Dev-Cpp/README b/bin/Dev-Cpp/README new file mode 100644 index 0000000..9fa1275 --- /dev/null +++ b/bin/Dev-Cpp/README @@ -0,0 +1 @@ +Built with Orwell Dev-Cpp 5.11 and TDM64-GCC 9.2.0 diff --git a/bin/Dev-Cpp/SDL_bgi.dll b/bin/Dev-Cpp/SDL_bgi.dll index a2e164a..cf7d6ec 100644 Binary files a/bin/Dev-Cpp/SDL_bgi.dll and b/bin/Dev-Cpp/SDL_bgi.dll differ diff --git a/bin/Mingw64/README b/bin/Mingw64/README new file mode 100644 index 0000000..4a75e49 --- /dev/null +++ b/bin/Mingw64/README @@ -0,0 +1 @@ +Built with native Mingw64 tools in MSYS2 diff --git a/bin/Mingw64/SDL_bgi.dll b/bin/Mingw64/SDL_bgi.dll index 267239f..4617c45 100644 Binary files a/bin/Mingw64/SDL_bgi.dll and b/bin/Mingw64/SDL_bgi.dll differ diff --git a/doc/compatibility.md b/doc/compatibility.md index 963b47b..ed16309 100644 --- a/doc/compatibility.md +++ b/doc/compatibility.md @@ -25,25 +25,26 @@ library. Compatibility with the original `GRAPHICS.H` is nearly perfect, but 100% compatibility with old programs written for Turbo C or Borland -C++ is simply *impossible*. By design, Borland compilers were tied to -the PC/DOS platform, and implemented low-level details such as -hardware key codes, memory models, DOS and BIOS calls, online -assembly, and so on. Besides, different graphic drivers were not fully -compatible with one another. For example, programs written for the -`IBM8514.BGI` driver needed modifications to compile and run on the -`EGAVGA.BGI` driver. +C++ is simply *impossible* to attain. By design, Borland compilers +were not portable; they were specifically designed for the PC/DOS +platform. Hence, they implemented low-level details such as hardware +key codes, memory models, DOS and BIOS calls, online assembly, and so +on. Besides, even in the original Turbo C / Borland C++ different +graphic drivers were not fully compatible with one another. For +example, programs written for the `IBM8514.BGI` driver needed +modifications to compile and run on the `EGAVGA.BGI` driver. Full compatibility is only possible in a hardware emulator like -DOSBox. If a program uses `CONIO.H`, `DOS.H`, `BIOS.H` and the like, +DOSBox. If a program uses `CONIO.H`, `DOS.H`, `BIOS.H` and the like, chances are you won't be able to compile it. Please consider using -DOSBox and one of the original Borland compilers that available as +DOSBox and one of the original Borland compilers that are available as freeware. That said, `SDL_bgi` is almost perfectly compatible with the original `GRAPHICS.H`. It has been tested on the original `BGIDEMO.C` included in Turbo C 2.01 and Borland C++ 1.01, and on the sample programs [available here](http://winbgim.codecutter.org/V6_0/doc). These sample -programs were copied from the Borland C Library Reference. +programs were copied from the original Borland C Library Reference. Nearly all functions are correctly implemented and work just like in old BGI; in most cases, output is pixel-perfect. @@ -56,7 +57,8 @@ releases of `SDL_bgi`. - colour names with `CGA_` and `EGA_` prefix have the same value as standard colours. For example, the `EGA_BROWN` constant is 6, like -`BROWN`, instead of 20 as in Turbo C or Borland C++; +`BROWN`, instead of 20 as in Turbo C or Borland C++. This difference +should be irrelevant; - these functions may be called, but have no effect: @@ -82,14 +84,14 @@ errorcode = registerbgidriver(EGAVGA_driver); you must add `-D EGAVGA_driver` to the `gcc` command line. You'll get a compiler warning, but the program will compile and run. -- the `colors` member of `struct palette` is defined as `Uint32` -instead of `signed char`, because colours are implemented as ARGB in -`SDL_bgi`: +- the `size` and `colors` members of `struct palette` are defined as +`Uint32` instead of `char`, because colours are implemented as +ARGB integers in `SDL_bgi`: ```` struct palettetype { - unsigned char size; - Uint32 colors[MAXCOLORS + 1]; + Uint32 size; // unsigned char in Turbo C / Borland C++ + Uint32 colors[MAXCOLORS + 1]; // signed char in Turbo C / Borland C++ }; ```` @@ -103,8 +105,9 @@ behaviour as in old Turbo C; - `setusercharsize()` also works with `DEFAULT_FONT`; -- `setrgbpalette()` works on the extended ARGB palette. To change -colours in the default palette, use `setpalette()` like this: +- `setrgbpalette()` works on the extended ARGB palette. To change the +RGB components of colours in the default palette, use `setpalette()` +like this: ```` setpalette (RED, COLOR (0xa0, 0x10, 0x10)); diff --git a/doc/compatibility.pdf b/doc/compatibility.pdf index 04eaaf9..407cd06 100644 Binary files a/doc/compatibility.pdf and b/doc/compatibility.pdf differ diff --git a/doc/functions.md b/doc/functions.md index 39cf0d0..848eac4 100644 --- a/doc/functions.md +++ b/doc/functions.md @@ -77,7 +77,7 @@ void `getpalette` (struct palettetype \*palette); int `getpalettesize` (void); -unsigned `int` getpixel (int x, int y); +unsigned int `getpixel` (int x, int y); void `gettextsettings` (struct textsettingstype \*texttypeinfo); @@ -121,7 +121,7 @@ void `outtextxy` (int x, int y, char \*textstring); void `pieslice` (int x, int y, int stangle, int endangle, int radius); -void `putimage` (int, int, void \*, int); +void `putimage` (int left, int top, void \*bitmap, int op); void `putpixel` (int x, int y, int color); @@ -207,13 +207,19 @@ int `event` (void); int `eventtype` (void); -void `getbuffer` (Uint32 *); +void `getbuffer` (Uint32 \*buffer); int `getcurrentwindow` (void); +int `getevent` (void); + void `getleftclick` (void); -int `getevent` (void); +void `getlinebuffer` (int y, Uint32 \*linebuffer); + +int `getmaxheight` (void); + +int `getmaxwidth` (void); void `getmiddleclick` (void); @@ -229,13 +235,15 @@ int `initwindow` (int width, int height); int `ismouseclick` (int kind); -int `mouseclick`(void); +int `mouseclick` (void); int `mousex` (void); int `mousey` (void); -void `putbuffer` (Uint32 \*); +void `putbuffer` (Uint32 \*buffer); + +void `putlinebuffer` (int y, Uint32 \*buffer); void `readimagefile` (char \*filename, int x1, int y1, int x2, int y2); diff --git a/doc/graphics.3.gz b/doc/graphics.3.gz new file mode 100644 index 0000000..26fcb48 Binary files /dev/null and b/doc/graphics.3.gz differ diff --git a/doc/graphics.3.md b/doc/graphics.3.md new file mode 100644 index 0000000..5869af5 --- /dev/null +++ b/doc/graphics.3.md @@ -0,0 +1,888 @@ +% GRAPHICS(3) SDL_bgi 2.4.3 +% \ +% February 2021 + +[1]: # To turn this file to manpage: +[2]: # pandoc -s -t man graphics.3.md -o graphics.3 +[3]: # gzip graphics.3 + +# NAME + +graphics.h - compatibility header for SDL_bgi + +# SYNOPSIS + +**\#include ** + +# DESCRIPTION + +This header file must be included by programs that use the *SDL_bgi* +library. Actual definitions are in *SDL_bgi.h*, usually installed in +`/usr/include/SDL2`. + +*SDL_bgi* is a Borland Graphics Interface implementation based on +SDL2. This library strictly emulates BGI functions, making it possible +to compile SDL2 versions of programs written for Turbo C/Borland C++. +ARGB colours, vector fonts, mouse support, and multiple windows are +also implemented; further, native SDL2 functions may be used in +*SDL_bgi* programs. + +# VARIABLES + +``` +extern SDL_Window *bgi_window; +extern SDL_Renderer *bgi_renderer; +extern SDL_Texture *bgi_texture; +extern Uint32 PALETTE_SIZE; +``` + +# DEFINITIONS + +\ + +## Font definitions + +\ +``` +enum { + DEFAULT_FONT, // 8x8 bitmap + TRIPLEX_FONT, // trip.h + SMALL_FONT, // litt.h + SANS_SERIF_FONT, // sans.h + GOTHIC_FONT, // goth.h + SCRIPT_FONT, // scri.h + SIMPLEX_FONT, // simp.h + TRIPLEX_SCR_FONT, // tscr.h + COMPLEX_FONT, // lcom.h + EUROPEAN_FONT, // euro.h + BOLD_FONT, // bold.h + LAST_SPEC_FONT +}; + +enum { HORIZ_DIR, VERT_DIR }; + +#define USER_CHAR_SIZE 0 + +enum { + LEFT_TEXT, CENTER_TEXT, RIGHT_TEXT, + BOTTOM_TEXT = 0, TOP_TEXT = 2 +}; +``` + +## Colour definitions + +\ +``` +enum { + BLACK = 0, EGA_BLACK = 0, + BLUE = 1, EGA_BLUE = 1, + GREEN = 2, CGA_GREEN = 2, EGA_GREEN = 2, + CYAN = 3, CGA_CYAN = 3, EGA_CYAN = 3, + RED = 4, CGA_RED = 4, EGA_RED = 4, + MAGENTA = 5, CGA_MAGENTA = 5, EGA_MAGENTA = 5, + BROWN = 6, CGA_BROWN = 6, EGA_BROWN = 6, + LIGHTGRAY = 7, CGA_LIGHTGRAY = 7, EGA_LIGHTGRAY = 7, + DARKGRAY = 8, EGA_DARKGRAY = 8, + LIGHTBLUE = 9, EGA_LIGHTBLUE = 9, + LIGHTGREEN = 10, CGA_LIGHTGREEN = 10, EGA_LIGHTGREEN = 10, + LIGHTCYAN = 11, CGA_LIGHTCYAN = 11, EGA_LIGHTCYAN = 11, + LIGHTRED = 12, CGA_LIGHTRED = 12, EGA_LIGHTRED = 12, + LIGHTMAGENTA = 13, CGA_LIGHTMAGENTA = 13, EGA_LIGHTMAGENTA = 13, + YELLOW = 14, CGA_YELLOW = 14, EGA_YELLOW = 14, + WHITE = 15, CGA_WHITE = 15, EGA_WHITE = 15, + MAXCOLORS = 15 +}; + +enum { + ARGB_FG_COL = 16, + ARGB_BG_COL = 17, + ARGB_FILL_COL = 18, + ARGB_TMP_COL = 19, + TMP_COLORS = 4 +}; +``` + +## Drawing and filling styles + +\ +``` +enum { NORM_WIDTH = 1, THICK_WIDTH = 3 }; + +enum { SOLID_LINE, DOTTED_LINE, CENTER_LINE, DASHED_LINE, USERBIT_LINE }; + +enum { COPY_PUT, XOR_PUT, OR_PUT, AND_PUT, NOT_PUT }; + +enum { + EMPTY_FILL, SOLID_FILL, LINE_FILL, LTSLASH_FILL, SLASH_FILL, + BKSLASH_FILL, LTBKSLASH_FILL, HATCH_FILL, XHATCH_FILL, + INTERLEAVE_FILL, WIDE_DOT_FILL, CLOSE_DOT_FILL, USER_FILL +}; +``` + +## Mouse buttons + +\ +``` +#define WM_LBUTTONDOWN SDL_BUTTON_LEFT +#define WM_MBUTTONDOWN SDL_BUTTON_MIDDLE +#define WM_RBUTTONDOWN SDL_BUTTON_RIGHT +#define WM_WHEEL SDL_MOUSEWHEEL +#define WM_WHEELUP SDL_USEREVENT +#define WM_WHEELDOWN SDL_USEREVENT + 1 +#define WM_MOUSEMOVE SDL_MOUSEMOTION +``` + +## Keys + +\ +``` +#define KEY_HOME SDLK_HOME +#define KEY_LEFT SDLK_LEFT +#define KEY_UP SDLK_UP +#define KEY_RIGHT SDLK_RIGHT +#define KEY_DOWN SDLK_DOWN +#define KEY_PGUP SDLK_PAGEUP +#define KEY_PGDN SDLK_PAGEDOWN +#define KEY_END SDLK_END +#define KEY_INSERT SDLK_INSERT +#define KEY_DELETE SDLK_DELETE +#define KEY_F1 SDLK_F1 +#define KEY_F2 SDLK_F2 +#define KEY_F3 SDLK_F3 +#define KEY_F4 SDLK_F4 +#define KEY_F5 SDLK_F5 +#define KEY_F6 SDLK_F6 +#define KEY_F7 SDLK_F7 +#define KEY_F8 SDLK_F8 +#define KEY_F9 SDLK_F9 +#define KEY_F10 SDLK_F10 +#define KEY_F11 SDLK_F11 +#define KEY_F12 SDLK_F12 +#define KEY_CAPSLOCK SDLK_CAPSLOCK +#define KEY_LEFT_CTRL SDLK_LCTRL +#define KEY_RIGHT_CTRL SDLK_RCTRL +#define KEY_LEFT_SHIFT SDLK_LSHIFT +#define KEY_RIGHT_SHIFT SDLK_RSHIFT +#define KEY_LEFT_ALT SDLK_LALT +#define KEY_RIGHT_ALT SDLK_RALT +#define KEY_ALT_GR SDLK_MODE +#define KEY_LGUI SDLK_LGUI +#define KEY_RGUI SDLK_RGUI +#define KEY_MENU SDLK_MENU +#define KEY_TAB SDLK_TAB +#define KEY_BS SDLK_BACKSPACE +#define KEY_RET SDLK_RETURN +#define KEY_PAUSE SDLK_PAUSE +#define KEY_SCR_LOCK SDLK_SCROLLOCK +#define KEY_ESC SDLK_ESCAPE + +#define QUIT SDL_QUIT +``` + +## Graphics modes + +\ +``` +enum { + DETECT = -1, + SDL = 0, + // all modes @ 320x200 + SDL_320x200 = 1, SDL_CGALO = 1, CGA = 1, CGAC0 = 1, CGAC1 = 1, + CGAC2 = 1, CGAC3 = 1, MCGAC0 = 1, MCGAC1 = 1, MCGAC2 = 1, + MCGAC3 = 1, ATT400C0 = 1, ATT400C1 = 1, ATT400C2 = 1, ATT400C3 = 1, + // all modes @ 640x200 + SDL_640x200 = 2, SDL_CGAHI = 2, CGAHI = 2, MCGAMED = 2, + EGALO = 2, EGA64LO = 2, + // all modes @ 640x350 + SDL_640x350 = 3, SDL_EGA = 3, EGA = 3, EGAHI = 3, + EGA64HI = 3, EGAMONOHI = 3, + // all modes @ 640x480 + SDL_640x480 = 4, SDL_VGA = 4, VGA = 4, MCGAHI = 4, VGAHI = 4, + IBM8514LO = 4, + // all modes @ 720x348 + SDL_720x348 = 5, SDL_HERC = 5, + // all modes @ 720x350 + SDL_720x350 = 6, SDL_PC3270 = 6, HERCMONOHI = 6, + // all modes @ 800x600 + SDL_800x600 = 7, SDL_SVGALO = 7, SVGA = 7, + // all modes @ 1024x768 + SDL_1024x768 = 8, SDL_SVGAMED1 = 8, + // all modes @ 1152x900 + SDL_1152x900 = 9, SDL_SVGAMED2 = 9, + // all modes @ 1280x1024 + SDL_1280x1024 = 10, SDL_SVGAHI = 10, + // all modes @ 1366x768 + SDL_1366x768 = 11, SDL_WXGA = 11, + // other + SDL_USER = 12, SDL_FULLSCREEN = 13 +}; +``` + +## Error messages + +\ +``` +enum graphics_errors { + grOk = 0, + grNoInitGraph = -1, + grNotDetected = -2, + grFileNotFound = -3, + grInvalidDriver = -4, + grNoLoadMem = -5, + grNoScanMem = -6, + grNoFloodMem = -7, + grFontNotFound = -8, + grNoFontMem = -9, + grInvalidMode = -10, + grError = -11, + grIOerror = -12, + grInvalidFont = -13, + grInvalidFontNum = -14, + grInvalidVersion = -18 +}; +``` + +## Struct definitions + +\ +``` +struct arccoordstype { + int x; + int y; + int xstart; + int ystart; + int xend; + int yend; +}; + +struct date { + int da_year; + int da_day; + int da_mon; +}; + +struct fillsettingstype { + int pattern; + int color; +}; + +struct linesettingstype { + int linestyle; + unsigned int upattern; + int thickness; +}; + +struct palettetype { + Uint32 size; // unsigned char in Turbo C / Borland C++ + Uint32 colors[MAXCOLORS + 1]; // signed char in Turbo C / Borland C++ +}; + +struct textsettingstype { + int font; + int direction; + int charsize; + int horiz; + int vert; +}; + +struct viewporttype { + int left; + int top; + int right; + int bottom; + int clip; +}; +``` + +# FUNCTIONS + +\ + +## Standard BGI functions + +\ + +void *arc* (int x, int y, int stangle, int endangle, int radius); +: Draws a circular arc centered at (*x, y*), with a radius given + by *radius*, traveling counterclockwise from *stangle* to *endangle*. + +void *bar* (int left, int top, int right, int bottom); +: Draws a filled-in rectangle (bar), using the current fill colour and + fill pattern. + +void *bar3d* (int left, int top, int right, int bottom, int depth, int topflag); +: Draws a three-dimensional, filled-in rectangle (bar), using the + current fill colour and fill pattern. + +void *circle* (int x, int y, int radius); +: Draws a circle of the given *radius* at (*x, y*). + +void *cleardevice* (void); +: Clears the graphics screen, filling it with the current background + colour. + +void *clearviewport* (void); +: Clears the viewport, filling it with the current background colour. + +void *closegraph* (void); +: Closes the graphics system. + +void *delay* (int millisec) +: Waits for \A{millisec} milliseconds. + +void *detectgraph* (int \*graphdriver, int \*graphmode); +: Detects the graphics driver and default graphics mode to use; *SDL* + and *SDL_FULLSCREEN*, respectively. + +void *drawpoly* (int numpoints, int \*polypoints); +: Draws a polygon of *numpoints* vertices. + +void *ellipse* (int x, int y, int stangle, int endangle, int xradius, int yradius); +: Draws an elliptical arc centered at (*x*, *y*), with axes given by + *xradius* and *yradius*, traveling from *stangle* to *endangle*. + +void *fillellipse* (int x, int y, int xradius, int yradius); +: Draws an elliptical arc centered at (*x*, *y*), with axes given by + *xradius* and *yradius*, and fills it using the current fill + colour and fill pattern. + +void *fillpoly* (int numpoints, int \*polypoints); +: Draws a polygon of *numpoints* vertices and fills it using the + current fill colour. + +void *floodfill* (int x, int y, int border); +: Fills an enclosed area, containing the *x* and *y* points bounded + by the *border* colour. The area is filled using the current fill + colour. + +int *getactivepage* (void); +: Returns the active page number. + +void *getarccoords* (struct arccoordstype \*arccoords); +: Gets the coordinates of the last call to *arc*(), filling the + *arccoords* structure. + +void *getaspectratio* (int \*xasp, int \*yasp); +: Retrieves the current graphics mode's aspect ratio. In *SDL_bgi*, + *xasp* and *yasp* are both 10000 (i.e. pixels are squares). + +int *getbkcolor* (void); +: Returns the current background colour in the default palette. + +int *getch* (void); +: Waits for a key and returns its ASCII code. + +int *getcolor* (void); +: Returns the current drawing (foreground) colour in the default + palette. + +struct palettetype\* *getdefaultpalette* (void); +: Returns the default palette definition structure. + +char\* *getdrivername* (void); +: Returns a pointer to a string containing the name of the current + graphics driver. + +void *getfillpattern* (char \*pattern); +: Copies the user-defined fill pattern, as set by *setfillpattern*(), + into the 8-byte area pointed to by *pattern*. + +void *getfillsettings* (struct fillsettingstype \*fillinfo); +: Fills the *fillsettingstype* structure pointed to by + *fillinfo* with information about the current fill pattern and fill + colour. + +int *getgraphmode* (void); +: Returns the current graphics mode. + +void *getimage* (int left, int top, int right, int bottom, void \*bitmap); +: Copies a bit image of the specified region into the memory pointed by + *bitmap*. + +void *getlinesettings* (struct linesettingstype \*lineinfo); +: Fills the *linesettingstype* structure pointed by *lineinfo* + with information about the current line style, pattern, and thickness. + +int *getmaxcolor* (void); +: Returns the maximum colour value available (*MAXCOLORS*) in the + default palette. If ARGB colours are being used, it returns + *PALETTE\_SIZE*. + +int *getmaxmode* (void); +: Returns the maximum mode number for the current driver. In *SDL_bgi*, + the default is *SDL\_FULLSCREEN*. + +int *getmaxx* (void); +: Returns the maximum *x* screen coordinate. + +int *getmaxy* (void); +: Returns the maximum *y* screen coordinate. + +char\* *getmodename* (int mode_number); +: Returns a pointer to a string containing the name of the specified + graphics mode. + +void *getmoderange* (int graphdriver, int \*lomode, int \*himode); +: Returns the range of valid graphics modes. The *graphdriver* parameter + is ignored. + +void *getpalette* (struct palettetype \*palette); +: Fills the *palettetype* structure pointed by *palette* with + information about the current palette's size and colours. + +int *getpalettesize* (void); +: Returns the size of the palette (*MAXCOLORS* + 1 or + *MAXRGBCOLORS* + 1). + +unsigned int *getpixel* (int x, int y); +: Returns the colour of the pixel located at (*x*, *y*). + +void *gettextsettings* (struct textsettingstype \*texttypeinfo); +: Fills the *textsettingstype* structure pointed to by + *texttypeinfo* with information about the current text font, + direction, size, and justification. + +void *getviewsettings* (struct viewporttype \*viewport); +: Fills the *viewporttype* structure pointed to by *viewport* + with information about the current viewport. + +int *getvisualpage* (void); +: Returns the visual page number. + +int *getx* (void); +: Returns the current viewport's *x* coordinate. + +int *gety* (void); +: Returns the current viewport's *y* coordinate. + +void *graphdefaults* (void); +: Resets all graphics settings to their default values. + +char\* *grapherrormsg* (int errorcode); +: Returns a pointer to the error message string associated with + *errorcode*, returned by *graphresult*(). + +int *graphresult*(void); +: Returns the error code for the last unsuccessful graphics operation + and resets the error level to *grOk*. + +unsigned *imagesize* (int left, int top, int right, int bottom); +: Returns the size in bytes of the memory area required to store a bit + image. + +void *initgraph* (int \*graphdriver, int \*graphmode, char \*pathtodriver); +: Initializes the graphics system. + +int *installuserdriver* (char \*name, int huge (\*detect)(void)); +: Unimplemented. + +int *installuserfont* (char \*name); +: Loads and installs a *.CHR* font from disk. The function returns + an integer to be used as first argument in *settextstyle*. + +int *kbhit* (void); +: Returns 1 when a key is pressed, excluding special keys (Ctrl, Shift, + etc.) + +void *line* (int x1, int y1, int x2, int y2); +: Draws a line between two specified points. + +void *linerel* (int dx, int dy); +: Draws a line from the CP to a point that is (*dx*, *dy*) pixels + from the CP. The CP is then advanced by (*dx*, *dy*). + +void *lineto* (int x, int y); +: Draws a line from the CP to (*x*, *y*), then moves the CP to + (*dx*, *dy*). + +void *moverel* (int dx, int dy); +: Moves the CP by (*dx*, *dy*) pixels. + +void *moveto* (int x, int y); +: Moves the CP to the position (*x*, *y*), relative to the + viewport. + +void *outtext* (char \*textstring); +: Outputs *textstring* at the CP. + +void *outtextxy* (int x, int y, char \*textstring); +: Outputs *textstring* at (*x*, *y*). + +void *pieslice* (int x, int y, int stangle, int endangle, int radius); +: Draws and fills a pie slice centered at (*x*, *y*), with a radius + given by *radius*, traveling from *stangle* to *endangle*. + +void *putimage* (int left, int top, void \*bitmap, int op); +: Puts the bit image pointed to by *bitmap* onto the screen, with the + upper left corner of the image placed at (*left*, *top*). *op* + specifies the drawing mode (*COPY_PUT*, etc). + +void *putpixel* (int x, int y, int color); +: Plots a pixel at (*x*, *y*) in the colour defined by *color*. + +int *random* (int range) (macro) +: Returns a random number between 0 and \A{range - 1}. + +void *rectangle* (int left, int top, int right, int bottom); +: Draws a rectangle delimited by (*left*, *top*) and + (*right*, *bottom*). + +int *registerbgidriver* (void (\*driver)(void)); +: Unimplemented. + +int *registerbgifont* (void (\*font)(void)); +: Unimplemented. + +void *restorecrtmode* (void); +: Hides the graphics window. + +void *sector* (int x, int y, int stangle, int endangle, int xradius, int yradius); +: Draws and fills an elliptical pie slice centered at (*x*, *y*), + horizontal and vertical radii given by *xradius* and *yradius*, + traveling from *stangle* to *endangle*. + +void *setactivepage* (int page); +: Makes *page* the active page for all subsequent graphics output. + +void *setallpalette* (struct palettetype \*palette); +: Sets the current palette to the values given in *palette*. + +void *setaspectratio* (int xasp, int yasp); +: Changes the default aspect ratio of the graphics. + +void *setbkcolor* (int color); +: Sets the current background colour in the default palette. + +void *setcolor* (int color); +: Sets the current drawing colour in the default palette. + +void *setfillpattern* (char \*upattern, int color); +: Sets a user-defined fill pattern. + +void *setfillstyle* (int pattern, int color); +: Sets the fill pattern and fill colour. + +unsigned *setgraphbufsize* (unsigned bufsize); +: Unimplemented. + +void *setgraphmode* (int mode); +: Shows the window that was hidden by *restorecrtmode*(). + +void *setlinestyle* (int linestyle, unsigned upattern, int thickness); +: Sets the line width and style. + +void *setpalette* (int colornum, int color); +: Changes the standard palette *colornum* to *color*, which can also + be specified using the *COLOR()* function. + +void *settextjustify* (int horiz, int vert); +: Sets text justification. Text output will be justified around the CP + horizontally and vertically. + +void *settextstyle* (int font, int direction, int charsize); +: Sets the text font. + +void *setusercharsize* (int multx, int divx, int multy, int divy); +: Lets the user change the character width and height. + +void *setviewport* (int left, int top, int right, int bottom, int clip); +: Sets the current viewport for graphics output. + +void *setvisualpage* (int page); +: Sets the visual graphics page number. + +void *setwritemode* (int mode); +: Sets the writing mode for line drawing. + +int *textheight* (char \*textstring); +: Returns the height in pixels of a string. + +int *textwidth* (char \*textstring); +: Returns the width in pixels of a string. + +## *SDL_bgi* extensions + +\ + +int *ALPHA_VALUE* (int color); +: Returns the alpha (transparency) component of an ARGB colour in the + ARGB palette. + +int *BLUE_VALUE* (int color); +: Returns the blue component of an ARGB colour in the ARGB palette. + +int *COLOR* (int r, int g, int b); +: Can be used as an argument for *setcolor*(), *setbkcolor*(), + *setfillpattern*(), and *setfillstyle*() to set a colour + specifying its ARGB components. + +int *COLOR32*(Uint32 color); +: Can be used as an argument for *setcolor*(), *setbkcolor*(), + *setfillpattern*(), and *setfillstyle*() to set a colour as + ARGB integer. + +Uint32 *colorRGB* (int r, int g, int b) (macro) +: Can be used to compose a 32 bit colour with *r* *g* *b* + components. + +int *GREEN_VALUE*(int color); +: Returns the green component of an ARGB colour in the ARGB palette. + +int *IS_BGI_COLOR* (int color); +: Returns 1 if the *current* drawing colour is a standard BGI + colour (that is, not ARGB). The *color* argument is actually redundant. + +int *IS_RGB_COLOR*(int color); +: Returns 1 if the *current* drawing colour is ARGB. The *color* + argument is actually redundant. + +int *RED_VALUE* (int color); +: Returns the red component of an ARGB colour in the ARGB palette. + +void *_putpixel* (int x, int y); +: Plots a point at (*x*, *y*) using the current drawing colour. + +void *closewindow* (int id); +: Closes the window identified by *id*. + +int *edelay* (int msec); +: Waits for *msec* milliseconds. This function returns 1 if an event + occurs during the delay, otherwise it returns 0. + +int *event* (void); +: Returns 1 if an event (mouse click, key press, or *QUIT*) has + occurred. + +int *eventtype* (void); +: Returns the type of the last event; either *SDL_KEYPRESS* or + *SDL_MOUSEBUTTONDOWN*. + +void *getbuffer* (Uint32 *buffer); +: Copies the contents of the active window to *buffer*. + +int *getcurrentwindow* (void); +: Returns the *id* of the current window. + +int *getevent* (void); +: Waits for a keypress, mouse click, or *SDL_QUIT* event, and returns + the code of the key, mouse button, or *SDL_QUIT* + +void *getleftclick* (void); +: Waits for the left mouse button to be clicked and released. + +void getlinebuffer (int y, Uint32 \*linebuffer); +: Copies the *y*-th screen line to *linebuffer*. + +int *getmaxwidth (void); +: Returns the maximum possible height for a new window (actual screen + height in pixels). + +int *getmaxwidth (void); +: Returns the maximum possible width for a new window (actual screen + width in pixels). + +void *getmiddleclick* (void); +: Waits for the middle mouse button to be clicked and released. + +void *getmouseclick* (int kind, int \*x, int \*y); +: Sets the *x*, *y* coordinates of the last *kind* button click + expected by *ismouseclick*(). + +void *getrightclick* (void); +: Waits for the right mouse button to be clicked and released. + +void *getscreensize* (int *x, int *y); +: Reports the screen width and height in *width* and *height*, + regardless of current window dimensions. + +void *initpalette* (void); +: Initialises the BGI palette to the standard 16 colours. + +int *initwindow* (int width, int height); +: Initializes the graphics system, opening a *width* x *height* + window. + +int *ismouseclick* (int kind); +: Returns 1 if the *kind* mouse button was clicked. + +int *mouseclick* (void); +: Returns the code of the mouse button that was clicked, or 0 if none + was clicked. + +int *mousex* (void); +: Returns the *X* coordinate of the last mouse click. + +int *mousey* (void); +: Returns the *Y* coordinate of the last mouse click. + +void *putbuffer* (Uint32 \*buffer); +: Copies *buffer* to the current window. + +void *putlinebuffer* (int y, Uint32 \*buffer); +: Copies *linebuffer* to the *y* coordinate in the current window. + +void *readimagefile* (char \*filename, int x1, int y1, int x2, int y2); +: Reads a *.bmp* file and displays it immediately at (*x1*, *y1*). + +void *refresh* (void); +: Updates the screen contents, i.e. displays all graphics. + +void *resetwinoptions* (int id, char *title, int x, int y); +: Resets the window title *title* and position to (*x*, *y*) of + an existing window identified by *id*. + +int *resizepalette* (Uint32); +: Resizes the ARGB palette to *newsize*; returns 0 if successful, 1 + otherwise. + +void *sdlbgiauto* (void); +: Triggers *auto mode*, i.e. *refresh*() is performed + automatically. + +void *sdlbgifast* (void); +: Triggers *fast mode*, i.e. *refresh*() is needed to display + graphics. + +void *sdlbgislow* (void); +: Triggers *slow mode* i.e. *refresh*() is not needed to + display graphics. + +void *setalpha* (int col, Uint8 alpha); +: Sets alpha transparency for colour *col* to *alpha* (0--255); 0 + means full transparecy, 255 full opacity. + +void *setbkrgbcolor* (int color); +: Sets the current background colour using the *n*-th colour entry in + the ARGB palette. + +void *setblendmode* (int blendmode); +: Sets the blend mode to be used with screen refresh. + +void *setcurrentwindow* (int id); +: Sets the current active window to *id*. + +void *setrgbcolor* (int color); +: Sets the current drawing colour using the *n*-th colour entry in the + ARGB palette. + +void *setrgbpalette* (int colornum, int red, int green, int blue); +: Sets the *n*-th entry in the ARGB palette specifying the *r*, + *g*, and *b* components. + +void *setwinoptions* (char \*title, int x, int y, Uint32 flags); +: Sets the window title *title*, the initial position to (*x*, + *y*), and SDL2 flags OR'ed together. + +void *setwintitle* (int id, char \*title); +: Sets the title of the window identified by *id*. + +void *showerrorbox* (const char *message); +: Opens an error message box with the specified message. + +void *showinfobox* (const char *message); +: Opens an information message box with the specified message. + +void *swapbuffers* (void); +: Swaps the current active and the current visual graphics pages. + +void *writeimagefile* (char \*filename, int left, int top, int right, int bottom); +: Writes a *.bmp* file from the screen rectangle defined by + *left*, *top*, *right*, *bottom*. + +int *xkbhit* (void); +: Returns 1 when any key is pressed, including special keys (Ctrl, Shift, + etc.) + + +# ENVIRONMENT + +*SDL_BGI_RES*: when set to *VGA*, default resolution will be 640 +x 480 instead of 800 x 600. + +*SDL_BGI_RATE*: when set to *auto*, automatic screen refresh +will be performed. + +*SDL_BGI_PALETTE*: when set to *BGI*, the first 16 colours will +use the same RGB values as Turbo C 2.01. + + +# BUGS + +- Visualisation problems on NVIDIA GK208BM (GeForce 920M) with +nvidia-driver-\* on GNU/Linux. As far as I can say, this is an NVIDIA +driver problem. + +- On MSYS2 + Mingw-w64, the *getch*() function may hang. Apparently, +this is a problem in MSYS2/Mingw-w64 console handling. + +- On Raspios 10 ARM, the letter 'p' is drawn incorrectly in +SCRIPT_FONT. This bug does not affect Raspios 10 i386. + +Please report bugs if you find any. + + +# EXAMPLE + +``` +#include + +int main (int argc, char *argv[]) +{ + int i, gd = DETECT, gm; + initgraph (&gd, &gm, ""); + setbkcolor (BLACK); + cleardevice (); + outtextxy (0, 0, "Drawing 1000 lines..."); + for (i = 0; i < 1000; i++) { + setcolor (1 + random (15)); + line (random(getmaxx()), random(getmaxy()), + random (getmaxx()), random(getmaxy()) ); + } + getch (); + closegraph (); + return 0; +} +``` + +To compile this program on GNU/Linux, macOS or Raspios: + +``` +$ gcc -o program program.c -lSDL_bgi -lSDL2 +``` + +To compile this program in MSYS2 + mingw-w64: + +``` +$ gcc -o program.exe program.c -lmingw32 -L/mingw64/bin \ + -lSDL_bgi -lSDL2main -lSDL2 # -mwindows +``` + +# AUTHORS + +Main library: Guido Gonzato, PhD *guido dot gonzato at gmail dot com* + +Automatic refresh patch, CHR font support: +Marco Diego Aurélio Mesquita, *marcodiegomesquita at gmail dot com* + +# LICENSE + +*SDL_bgi* is released under the ZLib License. + +Copyright (c) 2014-2021 Guido Gonzato, PhD + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. + diff --git a/doc/howto_CodeBlocks.md b/doc/howto_CodeBlocks.md index 861e021..09e24a7 100644 --- a/doc/howto_CodeBlocks.md +++ b/doc/howto_CodeBlocks.md @@ -1,65 +1,87 @@ -How to compile SDL_bgi programs with CodeBlocks + + +How to compile `SDL_bgi` programs with CodeBlocks =============================================== These instructions show how to compile an `SDL_bgi` program using CodeBlocks; we will use `fern.c`, provided in the `test/` directory. -Let's assume that CodeBlocks (complete with MinGW and TDM-GCC) is -installed in `C:\CodeBlocks`, and that the SDL2 development libraries -(MinGW) are installed in `C:\SDL2-2.0.12`. If you installed the -software in different directories, change the following instructions -accordingly. +Let's assume that CodeBlocks is installed in `C:\CodeBlocks`, and that +the SDL2 development libraries for MinGW are installed in +`C:\SDL2-2.0.14`. If you installed the software in different +directories, change the following instructions accordingly. -The procedure was tested with CodeBlocks 17.12 and -SDL2-devel-2.0.12-mingw. +The procedure was tested with CodeBlocks 20.02 and +SDL2-devel-2.0.14-mingw.tar.gz. Links: + -- copy `SDL_bgi.dll` to `C:\CodeBlocks\MinGW\bin` +Installing `SDL_bgi` +-------------------- + +- copy `bin/CodeBlocks/SDL_bgi.dll` to\ + `C:\CodeBlocks\MinGW\bin` -- copy `C:\SDL2-2.0.12\i686-w64-mingw32\bin\SDL2.dll` to\ - `C:\CodeBlocks\MinGW\bin` +- copy `SDL_bgi.h` to\ + `C:\SDL2-2.0.14\x86_64-w64-mingw32\include\SDL2` -- copy `SDL_bgi.h` to `C:\SDL2-2.0.12\i686-w64-mingw32\include\SDL2` +- copy `graphics.h` to\ + `C:\SDL2-2.0.14\x86_64-w64-mingw32\include` -- copy `graphics.h` to `C:\CodeBlocks\MinGW\include` + +How to compile +-------------- - start CodeBlocks and click on `Create a new project` -- click on `SDL2 project` +- click on `SDL2 project`, then proceed - in the wizard, provide a project name (`fern`), pick a folder to - create the project in, then click on `Next>` + store the project, then click on `Next>` -- in the next window, pick `C:\SDL2-2.0.12\i686-w64-mingw32` +- in the next window (SDL2 location), pick + `C:\SDL2-2.0.14\x86_64-w64-mingw32`, then click on `Next>` -- in the next window, choose `Create "Release" configuration`, - then click on `Finish` +- in the next window, uncheck `Create "Debug" configuration`, check + `Create "Release" configuration`, then click on `Finish` - in the panel `Projects/Workspace/fern/Sources`, delete `main.cpp` + (Remove file from project) - in the panel `Projects/Workspace/fern`: right click, click on `Add files...`, pick `fern.c`, then click on `Ok` - from the menu `Project/Build options...` select the `Search directories` tab, click on `Add`, pick the directory\ - `C:\SDL2-2.0.12\i686-w64-mingw32\include`, and select `No` when asked - to `Keep this as a relative path?`. Click on `Ok` + `C:\SDL2-2.0.14\x86_64-w64-mingw32\include`, then select `No` when + asked to `Keep this as a relative path?`. Click on `Ok` - from the menu `Project/Build options...` select the `Linker settings` tab, click on `Add`, pick the files\ `C:\CodeBlocks\MinGW\bin\SDL_bgi.dll` and\ - `C:\CodeBlocks\MinGW\bin\SDL2.dll`, then click on `Ok` + `C:\SDL2-2.0.14\x86_64-w64-mingw32\bin\SDL2.dll`, then select + `No` when asked to `Keep this as a relative path?`. Click on `Ok` - from the menu `Build`, select `Build`. The executable `fern.exe` will be compiled. +- if you don't need to set environment variables, close the\ + `Global variable editor` window + - run `fern.exe`. + **Note 1**: if you release your compiled program, you must also provide `SDL2.dll` and `SDL_bgi.dll` in the same directory. @@ -67,3 +89,6 @@ also provide `SDL2.dll` and `SDL_bgi.dll` in the same directory. `printf()`, `scanf()`, etc.) you must also run a terminal. From the menu `"Project/Set program's arguments...`, check the box `Run host in terminal`. + + +[]: # Absurdly complicated. Give me a command line anytime. diff --git a/doc/howto_CodeBlocks.pdf b/doc/howto_CodeBlocks.pdf index bc193a6..aa7e816 100644 Binary files a/doc/howto_CodeBlocks.pdf and b/doc/howto_CodeBlocks.pdf differ diff --git a/doc/howto_Dev-Cpp.md b/doc/howto_Dev-Cpp.md index 7025d96..78d67b5 100644 --- a/doc/howto_Dev-Cpp.md +++ b/doc/howto_Dev-Cpp.md @@ -1,88 +1,102 @@ -How to compile SDL_bgi programs with Dev-C++ -============================================ + + +How to compile `SDL_bgi` programs with Dev-C++ +============================================== These instructions show how to compile an `SDL_bgi` program using -Dev-C++; we will use `fern.c`, provided in the `test/` -directory. +Dev-C++; we will use `fern.c`, provided in the `test/` directory. Let's assume that Dev-C++ is installed in `C:\Dev-Cpp`, and that the -SDL2 development libraries (MinGW) are installed in `C:\SDL2-2.0.12`. -If you installed the software in different directories, change the -following instructions accordingly. +SDL2 development libraries for MinGW are installed in +`C:\SDL2-2.0.14`. If you installed the software in different +directories, change the following instructions accordingly. -The procedure was tested with Orwell Dev-Cpp 5.11, TDM-GCC 5.1.0-3, -and SDL2-devel-2.0.12-mingw. +The procedure was tested with Orwell Dev-Cpp 5.11, TDM64-GCC 9.2.0, +and SDL2-devel-2.0.14-mingw.tar.gz. Links: - - + + Upgrading Dev-C++'s Compiler ---------------------------- -By default, Dev-C++ ships with TDM-GCC 4.9.2; this is an old version -that is not compatible with current SDL2 development libraries. -To compile `SDL_bgi` programs, you must upgrade TDM-GCC to the -latest release. +By default, Dev-C++ ships with TDM-GCC 4.9.2; this is a very old +version of `gcc` that is not compatible with current SDL2 development +libraries. To compile `SDL_bgi` programs, you must upgrade TDM-GCC to +a newer release. -- remove the directory `C:\Dev-Cpp\MinGW64`, or rename it as\ - `C:\Dev-Cpp\MinGW64_old` +- remove the directory `C:\Dev-Cpp\MinGW64` -- install TDM-GCC (32 bit) in `C:\Dev-Cpp\MinGW64` +- install TDM64-GCC in `C:\Dev-Cpp\MinGW64` -- start Dev-C++. A window will appear, informing that a suitable - compiler was not found. Click on `No` +- start Dev-C++. A window will appear, reporting missing compiler + directories. Click on `Yes` - from menu `Tools/Compiler Options.../Compiler set to configure`, - click on the `++` icon (Find and automatically configure compilers) + click on the `++` icon (`Find and automatically configure compilers`) - when asked to `Clear current compiler list?`, click on `Yes` -- select "TDM-GCC 5.1.0 64-bit release" as the "Compiler set to - configure" - -- restart Dev-C++. A window will appear, informing that `gdb` was not - found. From menu `Tools/Compiler Options...` select the tab - `Programs` and replace `gdb.exe` with `gdb32.exe` +- `TDM-GCC 9.2.0 64-bit release` will be set as the `Compiler set to + configure`. Click on `Ok` - test Dev-C++ and make sure that you can compile programs. -Compiling `SDL_bgi` Programs ----------------------------- +Installing `SDL_bgi` +-------------------- + +- copy `bin/Dev-Cpp/SDL_bgi.dll` to\ + `C:\Dev-Cpp\MinGW64\lib` -- copy `SDL_bgi.dll` to `C:\Dev-Cpp\MinGW64\lib` +- copy `src/SDL_bgi.h` to\ + `C:\SDL2-2.0.14\x86_64-w64-mingw32\include\SDL2` -- copy `SDL_bgi.h` to\ - `C:\SDL2-2.0.12\i686-w64-mingw32\include\SDL2` +- copy `src/graphics.h` to\ + `C:\SDL2-2.0.14\x86_64-w64-mingw32\include` -- copy `graphics.h` to `C:\SDL2-2.0.12\i686-w64-mingw32\include` + +How to compile +-------------- - Run Dev-C++ and start an empty project called `Fern`: menu `File/New/Project...`, tick "C Project", select "Empty Project", - insert the name "Fern", click on Ok, save the project file + insert the name "Fern", click on Ok, then save the project file - in the left-hand pane, click on tab `Project`, remove `Untitled`, - right click on `Fern`, click on `Add to project...`, pick `fern.c` + right click on `Fern`, click on `Add to project...`, then pick `fern.c` - menu `Project/Project options...`, tab `Parameters`, tab `Linker`: add the string `-lmingw32 -lSDL_bgi -lSDL2main -lSDL2 -mwindows` +- menu `Project/Project options...`, tab `Parameters`, tab `Linker`: + click on `Add library or object` and select `SDL_bgi` from\ + `C:\Dev-Cpp\MinGW64\lib` + - tab `Directories`, tab `Include Directories`: add\ - `C:\SDL2-2.0.12\i686-w64-mingw32\include\SDL2` and\ - `C:\SDL2-2.0.12\i686-w64-mingw32\include` + `C:\SDL2-2.0.14\x86_64-w64-mingw32\include\SDL2` and\ + `C:\SDL2-2.0.14\x86_64-w64-mingw32\include` -- tab `Library Directories`: add `C:\SDL2-2.0.12\i686-w64-mingw32\lib` - then click on Ok +- tab `Library Directories`: add\ + `C:\SDL2-2.0.14\x86_64-w64-mingw32\lib` and\ + `C:\Dev-Cpp\MinGW64\lib` then click on Ok - compile the program: menu `Execute/Compile` -- copy `SDL2.dll` and `SDL_bgi.dll` to the same directory as `fern.exe` +- copy ``C:\SDL2-2.0.14\x86_64-w64-mingw32\bin\SDL2.dll` and\ + `SDL_bgi.dll` to the same directory as `fern.exe` - run it: menu `Execute/Run`. @@ -92,3 +106,6 @@ also provide `SDL2.dll` and `SDL_bgi.dll` in the same directory. **Note 2**: if your code uses functions provided by `stdio.h` (e.g. `printf()`, `scanf()`, etc.) you must also run a terminal. Remove the option `-mwindows` from the linker parameters. + + +[]: # Absurdly complicated. Give me a command line anytime. diff --git a/doc/howto_Dev-Cpp.pdf b/doc/howto_Dev-Cpp.pdf index ce8d612..eec9f2f 100644 Binary files a/doc/howto_Dev-Cpp.pdf and b/doc/howto_Dev-Cpp.pdf differ diff --git a/doc/howto_howto_Dev-Cpp.pdf b/doc/howto_howto_Dev-Cpp.pdf new file mode 100644 index 0000000..fcccadb Binary files /dev/null and b/doc/howto_howto_Dev-Cpp.pdf differ diff --git a/doc/p2man.sh b/doc/p2man.sh new file mode 100644 index 0000000..3262b7e --- /dev/null +++ b/doc/p2man.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +if [ $# -eq 0 ] ; then + printf "Usage: p2man FILE.3.md\n" + exit 1 +fi + + +FILE=$(basename $1 .3.md) +pandoc -s -t man $FILE.3.md -o $FILE.3 + diff --git a/doc/sdl_bgi-quickref.pdf b/doc/sdl_bgi-quickref.pdf index 4ffbd75..8ae966c 100644 Binary files a/doc/sdl_bgi-quickref.pdf and b/doc/sdl_bgi-quickref.pdf differ diff --git a/doc/sdl_bgi-quickref.tex b/doc/sdl_bgi-quickref.tex index 8613f68..b83146a 100644 --- a/doc/sdl_bgi-quickref.tex +++ b/doc/sdl_bgi-quickref.tex @@ -1,7 +1,7 @@ % sdl_bgi-quickref.tex % % Guido Gonzato, PhD -% November 6, 2020 +% February 12, 2021 \documentclass[a4paper,12pt]{article} \usepackage{graphicx} @@ -22,7 +22,7 @@ \newcommand{\SDLbgi}{\texttt{SDL\_bgi}} -\newcommand{\version}{2.4.2} % !!! <<<=== Change here !!! +\newcommand{\version}{2.4.3} % !!! <<<=== Change here !!! \newcommand{\V}{\texttt{void}} % void \newcommand{\I}{\texttt{int}} % int @@ -98,7 +98,7 @@ \section{Introduction to \SDLbgi} obviously, it's less complete. Teachers may find \SDLbgi{} a useful tool for introductory computer graphics courses. -This is a minimal program that opens a window and draws 1000 random +This is a minimal program that opens a window and draws 1000 random lines: \begin{small} @@ -109,7 +109,7 @@ \section{Introduction to \SDLbgi} int main (int argc, char *argv[]) { int i, gd = DETECT, gm; - initgraph (&gd, &gm, ""); + initgraph (&gd, &gm, ""); // default: 800 x 600 setbkcolor (BLACK); cleardevice (); outtextxy (0, 0, "Drawing 1000 lines..."); @@ -146,8 +146,8 @@ \section{Introduction to \SDLbgi} \subsection{Constants} -Many constants are defined in \F{SDL\_bgi.h}. The most important are -the following: +\F{SDL\_bgi.h} contains many definitions the programmer should be +aware of. The most important are the following: \begin{small} \begin{spacing}{0.85} @@ -168,7 +168,7 @@ \subsection{Constants} #include // for sin(), cos() #include // for strlen(), memcpy() -#define SDL_BGI_VERSION 2.4.2 +#define SDL_BGI_VERSION 2.4.3 enum { NOPE, YEAH } ; #define BGI_WINTITLE_LEN 512 // more than enough @@ -370,17 +370,9 @@ \subsection{Constants} grInvalidFontNum = -14, grInvalidVersion = -18 }; -\end{verbatim} -\end{spacing} -\end{small} - -\subsection{Structs} -Some of the BGI functions use the following structs: +// structs -\begin{small} -\begin{spacing}{0.85} -\begin{verbatim} struct arccoordstype { int x; int y; @@ -408,9 +400,8 @@ \subsection{Structs} }; struct palettetype { - unsigned char size; - // signed char in Turbo C / Borland C++ - Uint32 colors[MAXCOLORS + 1]; + Uint32 size; // unsigned char in Turbo C / Borland C++ + Uint32 colors[MAXCOLORS + 1]; // signed char in Turbo C / Borland C++ }; struct textsettingstype { @@ -491,6 +482,7 @@ \subsection{Note for SDL2 Programmers} SDL_Window *bgi_window; SDL_Renderer *bgi_renderer; SDL_Texture *bgi_texture; +extern Uint32 PALETTE_SIZE; \end{verbatim} \end{spacing} \end{small} @@ -632,7 +624,7 @@ \section{Standard BGI Graphics Functions} \end{bgi} Detects the graphics driver and default graphics mode to use; \T{SDL} -and \T{SDL\_FULLSCREEN}, respectively. +and \T{SDL\_FULL\-SCREEN}, respectively. % ----- @@ -745,7 +737,7 @@ \section{Standard BGI Graphics Functions} \end{bgi} Returns the current background colour in the default palette. If the -background colour was set by \func{COLOR}, \func{getbkcolor} returns +background colour was set by \func{COLOR()}, \func{getbkcolor()} returns -1. % ----- @@ -758,8 +750,8 @@ \section{Standard BGI Graphics Functions} \end{bgi} Returns the current drawing (foreground) colour in the default -palette. If the foregroud colour was set by \func{COLOR}, -\func{getcolor} returns -1. +palette. If the foregroud colour was set by \func{COLOR()}, +\func{getcolor()} returns -1. % ----- @@ -916,7 +908,7 @@ \section{Standard BGI Graphics Functions} \A{*himode}); \end{bgi} -Gets the range of valid graphics modes. The \A{graphdriver} parameter +Returns the range of valid graphics modes. The \A{graphdriver} parameter is ignored. % ----- @@ -1022,10 +1014,11 @@ \section{Standard BGI Graphics Functions} \V{} \func{graphdefaults} (\V{}); \end{bgi} -Resets all graphics settings to their defaults: sets the viewport to -the entire screen, moves the CP to (0, 0), sets the default palette -colours, the default drawing and background colour, the default fill -style and pattern, the default text font and justification. +Resets all graphics settings to their default values: sets the +viewport to the entire screen, moves the CP to (0, 0), sets the +default palette colours, the default drawing and background colour, +the default fill style and pattern, the default text font and +justification. % ----- @@ -1049,7 +1042,7 @@ \section{Standard BGI Graphics Functions} \end{bgi} Returns the error code for the last unsuccessful graphics operation -and resets the error level to grOk. +and resets the error level to \texttt{grOk}. % ----- @@ -1085,7 +1078,7 @@ \section{Standard BGI Graphics Functions} You can also use \T{NULL} for \A{*graphdriver} and \A{*graphmode} to get the default resolution (800 $\times$ 600), or use -\func{detectgraph} (see above) to get fullscreen. +\func{detectgraph()} (see above) to get fullscreen. Multiple windows can be created, unless a fullscreen window is already present. @@ -1132,10 +1125,10 @@ \section{Standard BGI Graphics Functions} \end{bgi} Loads and installs a \file{.CHR} font from disk. The function returns -an integer to be used as first argument in \func{settextstyle}. +an integer to be used as first argument in \func{settextstyle()}. \emph{Note:} font metrics of loaded \file{.CHR} files are not -pixel-perfect yet. This function does not work on Windows. +pixel-perfect yet. % ----- @@ -1157,7 +1150,7 @@ \section{Standard BGI Graphics Functions} \V{} \func{linerel} (\I{} \A{dx}, \I{} \A{dy}); \end{bgi} -Draws a line from the CP to a point that is (\A{dx},\A{dy}) pixels +Draws a line from the CP to a point that is (\A{dx}, \A{dy}) pixels from the CP. The CP is then advanced by (\A{dx}, \A{dy}). % ----- @@ -1243,7 +1236,7 @@ \section{Standard BGI Graphics Functions} Puts the bit image pointed to by \A{bitmap} onto the screen, with the upper left corner of the image placed at (\A{left}, \A{top}). \A{op} -specifies the drawing mode (COPY\_PUT, etc). +specifies the drawing mode (\T{COPY\_PUT}, etc). % ----- @@ -1254,7 +1247,7 @@ \section{Standard BGI Graphics Functions} \V{} \func{putpixel} (\I{} \A{x}, \I{} \A{y}, \I{} \A{color}); \end{bgi} -Plots a point at (\A{x},\A{y}) in the colour defined by \A{color}. +Plots a pixel at (\A{x}, \A{y}) in the colour defined by \A{color}. % ----- @@ -1266,8 +1259,8 @@ \section{Standard BGI Graphics Functions} \I{} \A{bottom}); \end{bgi} -Draws a rectangle delimited by (\A{left},\A{top}) and -(\A{right},\A{bottom}). +Draws a rectangle delimited by (\A{left}, \A{top}) and +(\A{right}, \A{bottom}). % ----- @@ -1326,7 +1319,7 @@ \section{Standard BGI Graphics Functions} \end{bgi} Makes \A{page} the active page for all subsequent graphics output. In -multi-window mode, \func{setactivepage} only works for the first window. +multi-window mode, \func{setactivepage()} only works for the first window. % ----- @@ -1420,7 +1413,7 @@ \section{Standard BGI Graphics Functions} \end{bgi} Shows the window that was hidden by \func{restorecrtmode()}. The -\A{mode} parameter is ignored +\A{mode} parameter is ignored, % ----- @@ -1455,7 +1448,7 @@ \section{Standard BGI Graphics Functions} \end{bgi} Changes the standard palette \A{colornum} to \A{color}, which can also -be specified using the \func{COLOR} function. +be specified using the \func{COLOR()} function. % ----- @@ -1484,23 +1477,18 @@ \section{Standard BGI Graphics Functions} Sets the text font (8$\times$8 bitmap font \T{DEFAULT\_FONT} and vector fonts \T{TRIPLEX\_FONT}, \T{SMALL\-\_FONT}, \T{SANS\_SERIF\_FONT}, \T{GOTHIC\_FONT}, \T{SCRIPT\_FONT}, -\T{SIMPLEX\_FONT}, \T{TRIPLEX\_SCR\_FONT}), the text direction +\T{SIMPLEX\_FONT}, \T{TRI\-PLEX\_SCR\_FONT}), the text direction (\T{HORIZ\_DIR}, \T{VERT\_DIR}), and the size of the characters. \A{charsize} is a scaling factor for the text (max. 10). If \A{charsize} is 0, the text will either use the default size, or it will be scaled by the values set with \func{setusercharsize()}. -Vector fonts are implemented using built-in Hershey fonts. Fonts -\T{EUROPEAN\_FONT} and \T{BOLD\_FONT} have no Hershey equivalent, and -are mapped to \T{TRIPLEX\_FONT}. - Experimental feature: if a \file{.CHR} font is available in the same directory as the running program, it will be loaded and used instead -of its Hershey equivalent. +of its internal equivalent. -\emph{Note:} pixel-perfect font metrics are not supported yet. This -feature does not work on Windows. +\emph{Note:} pixel-perfect font metrics are not supported yet. % ----- @@ -1513,9 +1501,9 @@ \section{Standard BGI Graphics Functions} \end{bgi} Lets the user change the character width and height. If a previous -call to \func{settextstyle()} set \A{charsize} to 0, the default width -is scaled by \A{multx}/\A{divx}, and the default height is scaled by -\A{multy}/\A{divy}. +call to \func{settextsty\-le()} set \A{charsize} to 0, the default +width is scaled by \A{multx}/\A{divx}, and the default height is +scaled by \A{multy}/\A{divy}. % ----- @@ -1574,7 +1562,7 @@ \section{Standard BGI Graphics Functions} \I{} \func{textwidth} (\C{}\A{textstring}); \end{bgi} -Returns the height in pixels of a string. +Returns the width in pixels of a string. % ----- @@ -1672,8 +1660,8 @@ \section{\SDLbgi{} Additions} \T{ARGB\_TMP\_COL}, and it is also copied in one of the following: \T{ARGB\_FG\_COL}, \T{ARGB\_BG\_COL}, \T{ARGB\_FILL\_COL}. -Functions \func{ALPHA\_VALUE}, \func{BLUE\_VALUE}, -\func{GREEN\_VALUE}, and \func{RED\_VALUE} do not work on temporary +Functions \func{ALPHA\_VALUE()}, \func{BLUE\_VALUE()}, +\func{GREEN\_VALUE()}, and \func{RED\_VALUE()} do not work on temporary colours. % ----- @@ -1691,8 +1679,8 @@ \section{\SDLbgi{} Additions} also copied in one of the following: \T{ARGB\_FG\_COL}, \T{ARGB\_BG\_COL}, \T{ARGB\_FILL\_COL}. -Functions \func{ALPHA\_VALUE}, \func{BLUE\_VALUE}, -\func{GREEN\_VALUE}, and \func{RED\_VALUE} do not work on temporary +Functions \func{ALPHA\_VALUE()}, \func{BLUE\_VALUE()}, +\func{GREEN\_VALUE()}, and \func{RED\_VALUE()} do not work on temporary colours. % ----- @@ -1729,7 +1717,7 @@ \section{\SDLbgi{} Additions} \end{bgi} Returns 1 if the \emph{current} drawing colour is a standard BGI -colour (that is, not ARGB). +colour (that is, not ARGB). The \A{color} argument is actually redundant. % ----- @@ -1763,7 +1751,7 @@ \section{\SDLbgi{} Additions} \V{} \func{\_putpixel} (\I{} \A{x}, \I{} \A{y}); \end{bgi} -Plots a point at (\A{x},\A{y}) using the current drawing colour. This +Plots a point at (\A{x}, \A{y}) using the current drawing colour. This function may be faster than \func{putpixel()}. % ----- @@ -1775,17 +1763,17 @@ \section{\SDLbgi{} Additions} \V{} \func{closewindow} (\I{} \A{id}); \end{bgi} -Closes the window whose identifier is \A{id}. +Closes the window identified by \A{id}. % ----- \begin{bgi} -\I{} \func{edelay} (\I{} \A{millisec}); +\I{} \func{edelay} (\I{} \A{msec}); \end{bgi} -Waits for \A{millisec} milliseconds. In ``slow mode'', a screen +Waits for \A{msec} milliseconds. In ``slow mode'', a screen refresh is performed. If an event occurs during the delay, this -function returns 1, otherwise 0. Use \func{eventtype} to get the last +function returns 1, otherwise 0. Use \func{eventtype()} to get the last event. % ----- @@ -1794,10 +1782,11 @@ \section{\SDLbgi{} Additions} \phantomsection\label{sec:event} \begin{bgi} -\V{} \func{event} (\V{}); +\I{} \func{event} (\V{}); \end{bgi} -Returns 1 if an event (mouse click, key press, or \T{QUIT}) has occurred. +Returns 1 if an event (mouse click, key press, or \T{SDL\_QUIT}) has +occurred. % ----- @@ -1805,7 +1794,7 @@ \section{\SDLbgi{} Additions} \phantomsection\label{sec:eventtype} \begin{bgi} -\V{} \func{eventtype} (\V{}); +\I{} \func{eventtype} (\V{}); \end{bgi} Returns the type of the last event; either \T{SDL\_KEYPRESS} or @@ -1833,18 +1822,7 @@ \section{\SDLbgi{} Additions} \I{} \func{getcurrentwindow} (\V{}); \end{bgi} -Returns the integer \A{id} of the current window. - -% ----- - -\addcontentsline{toc}{subsection}{\texttt{getleftclick()}} -\phantomsection\label{sec:getleftclick} - -\begin{bgi} -\V{} \func{getleftclick} (\V{}); -\end{bgi} - -Waits for the left mouse button to be clicked and released. +Returns the \A{id} of the current window. % ----- @@ -1860,26 +1838,26 @@ \section{\SDLbgi{} Additions} % ----- -\addcontentsline{toc}{subsection}{\texttt{getlinebuffer()}} -\phantomsection\label{sec:getlinebuffer} +\addcontentsline{toc}{subsection}{\texttt{getleftclick()}} +\phantomsection\label{sec:getleftclick} \begin{bgi} -\V{} \func{getlinebuffer} (\I{} \A{y}, \Ut{} \A{*linebuffer}); +\V{} \func{getleftclick} (\V{}); \end{bgi} -Copies the \A{y}-th screen line to \A{linebuffer}, which must be a -\func{getmaxx()+1} array of \A{Uint32} in ARGB format. +Waits for the left mouse button to be clicked and released. % ----- -\addcontentsline{toc}{subsection}{\texttt{getmiddleclick()}} -\phantomsection\label{sec:getmiddleclick} +\addcontentsline{toc}{subsection}{\texttt{getlinebuffer()}} +\phantomsection\label{sec:getlinebuffer} \begin{bgi} -\V{} \func{getmiddleclick} (\V{}); +\V{} \func{getlinebuffer} (\I{} \A{y}, \Ut{} \A{*linebuffer}); \end{bgi} -Waits for the middle mouse button to be clicked and released. +Copies the \A{y}-th screen line to \A{linebuffer}, which must be a +\func{getmaxx()+1} array of \A{Uint32} in ARGB format. % ----- @@ -1891,7 +1869,8 @@ \section{\SDLbgi{} Additions} \end{bgi} Returns the maximum possible height for a new window (actual screen -height in pixels). +height in pixels). This function may be called before graphics +initialisation. % ----- @@ -1903,7 +1882,19 @@ \section{\SDLbgi{} Additions} \end{bgi} Returns the maximum possible width for a new window (actual screen -width in pixels). +width in pixels). This function may be called before graphics +initialisation. + +% ----- + +\addcontentsline{toc}{subsection}{\texttt{getmiddleclick()}} +\phantomsection\label{sec:getmiddleclick} + +\begin{bgi} +\V{} \func{getmiddleclick} (\V{}); +\end{bgi} + +Waits for the middle mouse button to be clicked and released. % ----- @@ -1914,7 +1905,7 @@ \section{\SDLbgi{} Additions} \V{} \func{getmouseclick} (\I{} \A{kind}, \I{}\A{*x}, \I{}\A{*y}); \end{bgi} -Sets the \A{x},\A{y} coordinates of the last \A{kind} button click +Sets the \A{x}, \A{y} coordinates of the last \A{kind} button click expected by \func{ismouseclick()}. % ----- @@ -1950,10 +1941,10 @@ \section{\SDLbgi{} Additions} \V{} \func{initpalette} (\V{}); \end{bgi} -Initialises the palette to the standard 16 colours. If the environment -variable \T{SDL\_BGI\_PALET\-TE} equals \T{BGI}, the first 16 colours -will use the same RGB values as Turbo C 2.01; otherwise, a brighter -palette will be used. +Initialises the BGI palette to the standard 16 colours. If the +environment variable \T{SDL\_BGI\-\_PALET\-TE} equals \T{BGI}, the +first 16 colours will use the same RGB values as Turbo C 2.01; +otherwise, a brighter palette will be used. % ----- @@ -2055,7 +2046,7 @@ \section{\SDLbgi{} Additions} Reads a \F{.bmp} file and displays it immediately at (\A{x1}, \A{y1}). If (\A{x2}, \A{y2}) are not 0, the bitmap is stretched to fit the -rectangle \A{x1},\A{y1}---\A{x2},\A{y2}; otherwise, the bitmap is +rectangle \A{x1}, \A{y1}---\A{x2}, \A{y2}; otherwise, the bitmap is clipped as necessary. % ----- @@ -2096,7 +2087,7 @@ \section{\SDLbgi{} Additions} \I{} \func{resizepalette} (\Ut{} \A{newsize}); \end{bgi} -Resizes the ARGB palette to \A{newsize}; returns 0 if successfull, 1 +Resizes the ARGB palette to \A{newsize}; returns 0 if successful, 1 otherwise. The initial size of the ARGB palette is 4096. % ----- @@ -2170,7 +2161,7 @@ \section{\SDLbgi{} Additions} \end{bgi} Sets the blend mode to be used with screen refresh. \A{blendmode} can -be \T{SDL\_BLENDMODE\_NONE} (default in ``slow mode'') or +be \T{SDL\_BLENDMODE\-\_NONE} (default in ``slow mode'') or \T{SDL\_BLENDMODE\_BLEND}. The latter enables alpha blending. % ----- @@ -2182,7 +2173,7 @@ \section{\SDLbgi{} Additions} \V{} \func{setcurrentwindow} (\I{} \A{id}); \end{bgi} -Sets the current active window to \I{} \A{id}. +Sets the current active window to \A{id}. % ----- @@ -2224,7 +2215,7 @@ \section{\SDLbgi{} Additions} Sets the window title \A{title}, the initial position to (\A{x}, \A{y}), and SDL2 flags OR'ed together. \A{x} and \A{y} can be set to -\T{SDL\_WINDOWPOS\_CENTERED} or \T{SDL\_WINDOWPOS\_UNDEFINED}. +\T{SDL\_WINDOWPOS\_CENTERED} or \T{SDL\_WINDOWPOS\_UNDEFI\-NED}. If \A{title} is an empty string, the window title is set to the default value \T{SDL\_bgi}. @@ -2232,13 +2223,24 @@ \section{\SDLbgi{} Additions} If either \A{x} or \A{y} is -1, the position parameters are ignored. If \A{flags} is -1, the parameter is ignored; otherwise, only the -values \T{SDL\_WINDOW\_FULLSCREEN}, +values \T{SDL\_WINDOW\_FULL\-SCREEN}, \T{SDL\_WIN\-DOW\_FULLSCREEN\_DESKTOP}, \T{SDL\_WINDOW\_SHOWN}, \T{SDL\_WINDOW\_HIDDEN}, \T{SDL\_WINDOW\-\_BORDERLESS}, and \T{SDL\_WINDOW\_MINIMIZED} can be applied. % ----- +\addcontentsline{toc}{subsection}{\texttt{setwintitle()}} +\phantomsection\label{sec:setwintitle} + +\begin{bgi} +\V{} \func{setwintitle} (\I{id}, \C{}\A{title}); +\end{bgi} + +Sets the title of the window identified by \A{id}. + +% ----- + \addcontentsline{toc}{subsection}{\texttt{showerrorbox()}} \phantomsection\label{sec:showerrorbox} @@ -2283,7 +2285,7 @@ \section{\SDLbgi{} Additions} \end{bgi} Writes a \F{.bmp} file from the screen rectangle defined by -\A{left},\A{top}---\A{right},\A{bottom}. +\A{left}, \A{top}---\A{right}, \A{bottom}. % ----- diff --git a/doc/turtlegraphics.pdf b/doc/turtlegraphics.pdf index 97186f2..58ad680 100644 Binary files a/doc/turtlegraphics.pdf and b/doc/turtlegraphics.pdf differ diff --git a/doc/turtlegraphics.tex b/doc/turtlegraphics.tex index a04b759..b17deca 100644 --- a/doc/turtlegraphics.tex +++ b/doc/turtlegraphics.tex @@ -80,7 +80,7 @@ \section{Turtle Graphics} more information: \url{https://en.wikipedia.org/wiki/Turtle_graphics} Some functions have aliases with the same name as their Python -counterparts; \url{https://docs.python.org/2/library/turtle.html} +counterparts; \url{https://docs.python.org/3/library/turtle.html} % ----- diff --git a/doc/using.md b/doc/using.md index 22ebffd..f2bc573 100644 --- a/doc/using.md +++ b/doc/using.md @@ -8,7 +8,6 @@ # Using `SDL_bgi` - Although `SDL_bgi` is almost perfectly compatible with the original `GRAPHICS.H` by Borland, a few minor differences have been introduced. The original BGI library mainly targeted the VGA video display @@ -17,10 +16,10 @@ colours. `SDL_bgi` uses modern graphics capabilities provided by `SDL2`, while retaining backwards compatibility as much as possible. -## Compiling programs +## Compiling Programs -To compile a C or C++ program on GNU/Linux or macOS you can use the -`gcc` or `clang` compiler: +To compile a C or C++ program on GNU/Linux, macOS or Raspios you can +use the `gcc` or `clang` compiler: $ gcc -o program program.c -lSDL_bgi -lSDL2 @@ -31,8 +30,8 @@ To compile a program in MSYS2 + mingw-w64: The `-mwindows` switch creates a window-only program, i.e. a terminal is not started. **Beware:** functions provided by `stdio.h` will not -work if you don't start a terminal. Your program will have to rely on -mouse input only! +work if you don't start a terminal; your program will have to rely on +mouse input only. Code::Blocks users should read the file `howto_CodeBlocks.md`. @@ -45,7 +44,7 @@ Windows users **must** declare the `main()` function as: even if `argc` and `argv` are not going to be used. Your program will not compile if you use a different `main()` definition (i.e. `int main (void)`), because of conflict with the `WinMain()` definition. It's an -SDL2 issue; please consult for +SDL2 feature; please consult for details. Most old programs that use the original BGI library should compile @@ -88,7 +87,8 @@ where `` can be one of the following: SDL_1366x768 1366x768 SDL_FULLSCREEN fullscreen -You may want to use `initwindow(int width, int height)` instead. +More less common resolutions are listed in `SDL_bgi.h`. You may want +to use `initwindow(int width, int height)` instead. `SDL_bgi.h` defines the `_SDL_BGI_H` constant. You can check for its presence and write programs that employ `SDL_bgi` extensions; please @@ -145,8 +145,7 @@ This is possibly the slowest `SDL_bgi` code one could write: This code, which plots pixels until an event occurs (mouse click or key press), is extremely inefficient. First of all, calling `event()` is relatively expensive; secondly, refreshing the screen after -plotting a single pixel is insane. You should write something like -this: +plotting a single pixel is insane. You should write code like this: counter = 0; stop = 0; @@ -172,7 +171,8 @@ Please see the accompanying document `compatibility`. ## Colours `SDL_bgi` has two colour palettes: one for compatibility with old BGI, -the other for ARGB colours. +the other for ARGB colours. Colour depth is always 32 bit; `SDL_bgi` +has not been tested on lesser colour depths. The default BGI palette includes 16 named colours (`BLACK`...`WHITE`); standard BGI functions, like `setcolor()` or `setbkcolor()`, use this @@ -183,8 +183,11 @@ if the environment variable `SDL_BGI_PALETTE` is set to `BGI`. An extended ARGB palette of `PALETTE_SIZE` additional colours can be used by functions like `setrgbcolor()` or `setbkrgbcolor()` -described below; please note the `rgb` in the function names. Please -see the example programs in the `test/` directory. +described below; please note the `rgb` in the function names. +`PALETTE_SIZE` is 4096 by default, but it can be increased using +`resizepalette()`. + +Please see the example programs in the `test/` directory. ## Fonts @@ -252,8 +255,8 @@ it may not work on some graphics cards. ### Multiple Windows Functions Subsequent calls to `initgraph()` or `initwindow()` make it possible -to open several windows; only one of them is active (= being drawn on) -at any given time, regardless of mouse focus. +to open several windows; only one of them is active (i.e. being drawn +on) at any given time, regardless of mouse focus. Functions `setvisualpage()` and `setactivepage()` only work properly in single window mode. @@ -379,12 +382,15 @@ needed). int bottom)` writes a `.bmp` file from the screen rectangle defined by (left,top--right,bottom). +- `void kbhit(void)` returns 1 when a key is pressed, excluding +Shift, Alt, etc. + + - `void xkbhit(void)` returns 1 when any key is pressed, including Shift, Alt, etc. -The Real Thing --------------- +## The Real Thing You may want to try the online Borland Turbo C 2.01 emulator at the Internet Archive: @@ -396,15 +402,9 @@ library. You can download it and compile it using `SDL_bgi`; in Windows, you will have to change its `main()` definition. -Bugs & Issues -------------- - -In GNU/Linux, there may be visualisation problems on NVIDIA GK208BM -(GeForce 920M) with `nvidia-driver-440`. As far as I can say, this -is an NVIDIA driver problem. +## Bugs & Issues -Console routines such as `getch()` may hang or not work properly in -MSYS2. This is a problem in Mingw/MSYS2 console handling. +Please see the accompanying document `BUGS`. Probably, this documentation is not 100% accurate. Your feedback is more than welcome. diff --git a/doc/using.pdf b/doc/using.pdf index 9ec1feb..0e501f4 100644 Binary files a/doc/using.pdf and b/doc/using.pdf differ diff --git a/sdl_bgi.spec b/sdl_bgi.spec index 055e48e..4ba3504 100644 --- a/sdl_bgi.spec +++ b/sdl_bgi.spec @@ -1,10 +1,10 @@ -# sdl_bgi.spec - tested on Fedora 31 +# sdl_bgi.spec - tested on Fedora 32 %global debug_package %{nil} -Summary: Multiplatform, SDL2-based 'graphics.h' implementation +Summary: SDL2-based 'GRAPHICS.H' implementation Name: SDL_bgi -Version: 2.4.2 +Version: 2.4.3 Release: 1 License: ZLib Group: Libraries @@ -14,13 +14,13 @@ BuildRequires: SDL2-devel Prefix: %{_prefix} BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot -%description -SDL_bgi is a Borland Graphics Interface (BGI, aka 'graphics.h') -emulation library based on SDL2. This library strictly emulates BGI -functions, making it possible to compile SDL2 versions of programs -written for Turbo C/Borland C. ARGB colours, vector fonts, mouse -support, and multiple windows are also implemented; further, native -SDL2 functions may be used in SDL_bgi programs. +%description +SDL_bgi is a Borland Graphics Interface ('GRAPHICS.H') implementation +based on SDL2. This library strictly emulates BGI functions, making it +possible to compile SDL2 versions of programs written for Turbo +C/Borland C++. ARGB colours, vector fonts, mouse support, and multiple +windows are also implemented; further, native SDL2 functions may be +used in SDL_bgi programs. %prep %setup -q -n %{name}-%{version} @@ -35,9 +35,12 @@ cd src mkdir -p $RPM_BUILD_ROOT/%{_libdir} mkdir -p $RPM_BUILD_ROOT/%{_includedir} mkdir -p $RPM_BUILD_ROOT/%{_includedir}/SDL2/ +mkdir -p $RPM_BUILD_ROOT/%{_mandir}/man3/ /usr/bin/install -m 644 graphics.h $RPM_BUILD_ROOT/%{_includedir} /usr/bin/install -m 644 SDL_bgi.h $RPM_BUILD_ROOT/%{_includedir}/SDL2/ /usr/bin/install -m 644 lib%{name}.so $RPM_BUILD_ROOT/%{_libdir} +cd ../doc/ +/usr/bin/install -m 644 graphics.3.gz $RPM_BUILD_ROOT/%{_mandir}/man3/ %clean rm -rf $RPM_BUILD_ROOT @@ -45,11 +48,12 @@ rm -rf $RPM_BUILD_ROOT %files %defattr(644,root,root,755) %doc AUTHORS BUGS ChangeLog doc/ INSTALL_Linux.md INSTALL_macOS.md -%doc INSTALL_Windows.md LICENSE LICENSE_fonts README.md +%doc INSTALL_Windows.md LICENSE README.md %doc sdl_bgi.spec test/ TODO VERSION %attr(644,root,root) %{_libdir}/lib%{name}.so %attr(644,root,root) %{_includedir}/SDL2/SDL_bgi.h %attr(644,root,root) %{_includedir}/graphics.h +%attr(644,root,root) %{_mandir}/man3/graphics.3.gz %changelog * Tue Jan 2 2018 Guido Gonzato diff --git a/src/SDL_bgi.h b/src/SDL_bgi.h index 381e6aa..45c21dd 100644 --- a/src/SDL_bgi.h +++ b/src/SDL_bgi.h @@ -7,7 +7,7 @@ // By Guido Gonzato, PhD // Automatic refresh patch, CHR font support: // Marco Diego Aurélio Mesquita -// November 4, 2020 +// Latest update: February 24, 2021 // ZLib License @@ -47,7 +47,7 @@ freely, subject to the following restrictions: #include // for sin(), cos() #include // for strlen(), memcpy() -#define SDL_BGI_VERSION 2.4.2 +#define SDL_BGI_VERSION 2.4.3 enum { NOPE, YEAH } ; #define BGI_WINTITLE_LEN 512 // more than enough @@ -302,9 +302,8 @@ struct linesettingstype { }; struct palettetype { - unsigned char size; - // signed char in Turbo C / Borland C++ - Uint32 colors[MAXCOLORS + 1]; + Uint32 size; // unsigned char in Turbo C / Borland C++ + Uint32 colors[MAXCOLORS + 1]; // signed char in Turbo C / Borland C++ }; struct textsettingstype { diff --git a/test/Makefile b/test/Makefile index debcf30..d7ded3c 100644 --- a/test/Makefile +++ b/test/Makefile @@ -20,8 +20,8 @@ LIBS = -lSDL_bgi -lSDL2 endif # Latest MSYS2 + Mingw-w64 -msys := $(findstring MSYS, $(PLATFORM)) -ifeq ($(msys),MSYS) +msys := $(findstring _NT, $(PLATFORM)) +ifeq ($(msys),_NT) CFLAGS = -std=gnu99 -O2 -g -I. -I/mingw64/include -I/mingw64/include/SDL # -mconsole = open a console alongside the program # -mwindows = Windows-only program (no console) @@ -103,7 +103,7 @@ psychedelia: psychedelia.c $(CC) $(CFLAGS) -o psychedelia psychedelia.c $(LIBS) -lm sdlbgidemo: sdlbgidemo.c - $(CC) $(CFLAGS) -I. -o sdlbgidemo sdlbgidemo.c $(LIBS) -lm + $(CC) $(CFLAGS) -o sdlbgidemo sdlbgidemo.c $(LIBS) -lm setpalette: setpalette.c $(CC) $(CFLAGS) -o setpalette setpalette.c $(LIBS) diff --git a/test/README.md b/test/README.md index 7f237c1..7c7fa90 100644 --- a/test/README.md +++ b/test/README.md @@ -7,7 +7,7 @@ This directory contains a few simple programs that show how to use some features of `SDL_bgi`; type `make` to compile them. You may want to compile the original `bgidemo.c` program by Borland. -It's not free software but it can be downloaded from several sources; +It's not free software, but it can be downloaded from several sources; type `make bgidemo` to download it and compile it. You need the `wget` tool in the $PATH. @@ -15,9 +15,6 @@ tool in the $PATH. declaration; the Makefiles changes `int main()` to `int main(int argc, char *argv[])`. -Original `.CHR` fonts are available here: - - There may be compiler warnings using gcc releases newer than 7, as in Ubuntu 20. @@ -45,10 +42,9 @@ the (horribly slow) GNU libgraph. - `floodfilltest.c` shows the speed of the new `floodfill()` routine. -- `fonts.c` shows the new Hershey-based vector fonts. If `.CHR` fonts -are available in the same directory, they will be used instead of the -Hershey fonts. This is an experimental feature that works in GNU/Linux -only. +- `fonts.c` shows the new vector fonts. If `.CHR` fonts are available +in the same directory, they will be used instead of the corresponding +internal fonts. - `hopalong.c` is an implementation of Barry Martin's algorithm, presented in the September 1986 issue of Scientific American. Run it @@ -62,6 +58,10 @@ fade away effect. `./life [number]`, where `[number]` is the initial percentage of living cells. +- `linebuffers.c` shows how to use `getlinebuffer()` and +`putlinebuffer()` to draw pixel-based stuff on the screen. Using +buffers (i.e. arrays) is much faster than using `putpixel()`. + - `mandelbrot.c` is a simple, non-optimised program to display the Mandelbrot set, . It shows how to setup and use RGB colour mode. Press '1', '2', '3' to @@ -72,18 +72,19 @@ initial boundary. - `mousetest.c` shows how to detect and use mouse clicks. Click around using all buttons and mouse wheel. -- `plasma.c` writes the window contents to a .bmp file. +- `multiwin.c` shows how to open multiple windows. -- `psychedelia.c` sets up an RGB palette and produces a plasma effect, -using either putpixel() or putbuffer(); left click to switch. -Algorithm is described at . +- `plasma.c` writes the window contents to a `.bmp` file. -- `scrolltext.c` shows how to use `getlinebuffer()` and -`putlinebuffer()`, which are faster than `getpixel()` and -`putpixel()`. +- `psychedelia.c` sets up an RGB palette and produces a plasma effect, +using either putpixel() or putbuffer(); left click to switch. The +algorithm is described at . - `sdlbgidemo.c` shows how to use some of `SDL_bgi`'s features. +- `setpalette.c` shows how to redefine the 16-colour palette and +restore it. + - `simple.c` displays simple shapes to test `SDL_bgi`'s speed. **Note**: this programs hangs in Mingw, because of a bug in its console routines (apparently). diff --git a/test/boo.c b/test/boo.c index 4d4e6c3..02b3672 100644 --- a/test/boo.c +++ b/test/boo.c @@ -35,6 +35,9 @@ int main (int argc, char *argv[]) winid, x, y, stop = 0; + + // physical screen size, regardless of window dimensions + getscreensize (&x, &y); setwinoptions ("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOW_BORDERLESS); @@ -42,10 +45,7 @@ int main (int argc, char *argv[]) setbkcolor (BLACK); cleardevice (); winid = getcurrentwindow (); - - // physical screen size, regardless of window dimensions - getscreensize (&x, &y); - + // make the window opaque SDL_SetWindowOpacity (bgi_window, 1.0); setcolor (RED); @@ -63,7 +63,7 @@ int main (int argc, char *argv[]) // make the window transparent (disappear) SDL_SetWindowOpacity (bgi_window, 0.0); refresh (); - stop = edelay (random (500)); + stop = edelay (random (1500)); // opaque again - reappear resetwinoptions (winid, "", random (x), random (y)); diff --git a/test/life.c b/test/life.c index 7d5f72c..4b1baab 100644 --- a/test/life.c +++ b/test/life.c @@ -3,7 +3,7 @@ * To compile: * gcc -o life life.c -lSDL_bgi -lSDL2 * - * Simple cellular automata, as described at + * Simple cellular automaton, as described at * http://mathworld.wolfram.com/ElementaryCellularAutomaton.html * * By Guido Gonzato, May 2015. diff --git a/test/linebuffers.c b/test/linebuffers.c index e8dba0d..3026b4b 100644 --- a/test/linebuffers.c +++ b/test/linebuffers.c @@ -64,11 +64,11 @@ int main (int argc, char *argv[]) refresh (); showinfobox ("Left click to switch between\n" "putlinebuffer() and putpixel();\n" - "press any key to exit."); + "any key to stop."); int mode = 1; - while (! kbhit ()) { + while (! xkbhit ()) { if (WM_LBUTTONDOWN == mouseclick ()) { mode ^= 1; @@ -97,7 +97,8 @@ int main (int argc, char *argv[]) delay (5); refresh (); - } + + } // while puts ("Bye!"); closegraph(); diff --git a/test/mandelbrot.c b/test/mandelbrot.c index 450ddcd..39483b9 100644 --- a/test/mandelbrot.c +++ b/test/mandelbrot.c @@ -125,14 +125,6 @@ void blue_palette (void) // ----- -int click (void) -{ - int p = mouseclick (); - return (p > 0 && p < WM_MOUSEMOVE); -} // click () - -// ----- - void explain (void) { int @@ -162,7 +154,7 @@ void explain (void) outtextxy (maxx / 2, maxy / 2, "middle click to restore the initial boundary;"); outtextxy (maxx / 2, maxy / 2 + c, - "'i' and 'd' to increase/decrease max iterations;"); + "'i' or '+', 'd' or '-' to increase/decrease max iterations;"); outtextxy (maxx / 2, maxy / 2 + 2*c, "arrow keys to move around;"); @@ -194,16 +186,18 @@ void explain (void) int main (int argc, char *argv[]) { int palette, c, init, redraw, flag; - double xm, ym, xstep, ystep, x1, y1, x2, y2; + double xm, ym, xstep, ystep, xmin, ymin, xmax, ymax; char s[20]; initwindow (0, 0); // fullscreen maxx = getmaxx (); maxy = getmaxy (); + // initial coordinates of the middle point of the screen xm = -1.2; ym = 0.0; - xstep = 1.6; + // initial range: xm +- xstep, ym +- ystep + xstep = (double) maxx / (double) maxy; ystep = 1.2; init = flag = redraw = 1; @@ -215,13 +209,13 @@ int main (int argc, char *argv[]) c = 'G'; while (c != KEY_ESC) { - x1 = xm - xstep; - y1 = ym - ystep; - x2 = xm + xstep; - y2 = ym + ystep; + xmin = xm - xstep; + ymin = ym - ystep; + xmax = xm + xstep; + ymax = ym + ystep; if (redraw) { - mandelbrot (x1, y1, x2, y2); + mandelbrot (xmin, ymin, xmax, ymax); // added! refresh (); if (flag) { @@ -240,18 +234,20 @@ int main (int argc, char *argv[]) case WM_LBUTTONDOWN: case WM_WHEELUP: - xm = x1 + (x2 - x1) * mousex () / maxx; - ym = y1 + (y2 - y1) * mousey () / maxy; - xstep /= 2; - ystep /= 2; + xm = xmin + 2 * xstep * mousex () / maxx; + ym = ymin + 2 * ystep * mousey () / maxy; + /* xm = xmin + (xmax - xmin) * mousex () / maxx; */ + /* ym = ymin + (ymax - ymin) * mousey () / maxy; */ + xstep /= 2.0; + ystep /= 2.0; init = 0; redraw = 1; break; case WM_RBUTTONDOWN: case WM_WHEELDOWN: - xstep *= 2; - ystep *= 2; + xstep *= 2.0; + ystep *= 2.0; init = 0; redraw = 1; break; @@ -291,6 +287,7 @@ int main (int argc, char *argv[]) break; case 'i': + case '+': max_iter += 50; if (max_iter > PALETTE_SIZE) max_iter = PALETTE_SIZE; @@ -301,6 +298,7 @@ int main (int argc, char *argv[]) break; case 'd': + case '-': max_iter -= 50; if (max_iter < 50) max_iter = 50; @@ -311,22 +309,22 @@ int main (int argc, char *argv[]) break; case KEY_LEFT: - xm += (x2 - x1) / 20; + xm -= (xmax - xmin) / 20; redraw = 1; break; case KEY_RIGHT: - xm -= (x2 - x1) / 20; + xm += (xmax - xmin) / 20; redraw = 1; break; case KEY_UP: - ym += (y2 - y1) / 20; + ym -= (ymax - ymin) / 20; redraw = 1; break; case KEY_DOWN: - ym -= (y2 - y1) / 20; + ym += (ymax - ymin) / 20; redraw = 1; break; diff --git a/test/multiwin.c b/test/multiwin.c index ae07780..84cf77a 100644 --- a/test/multiwin.c +++ b/test/multiwin.c @@ -77,18 +77,18 @@ int main (int argc, char *argv[]) getevent (); outtextxy (0, 20, "Shutting down..."); - /* - closegraph (); - return 0; - */ - - delay (1000); + setwintitle (win3, "Window 3 is shutting down..."); + delay (2000); printf ("Shutting down window %d\n", win3); closewindow (win3); - delay (1000); + + setwintitle (win2, "Window 2 is shutting down..."); + delay (2000); printf ("Shutting down window %d\n", win2); closewindow (win2); - delay (1000); + + setwintitle (win1, "Window 1 is shutting down..."); + delay (2000); printf ("Shutting down window %d\n", win1); closewindow (win1); diff --git a/test/psychedelia.c b/test/psychedelia.c index 7b14d55..617abf3 100644 --- a/test/psychedelia.c +++ b/test/psychedelia.c @@ -1,12 +1,12 @@ /* psychedelia.c -*- C -*- - * + * * To compile: * gcc -o psychedelia psychedelia.c -lSDL_bgi -lSDL2 -lm - * + * * Variation on 'plasma.c', as described here: * https://lodev.org/cgtutor/plasma.html * By Guido Gonzato, 2018 - 2019. - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -20,7 +20,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * + * */ #include @@ -43,10 +43,10 @@ int main (int argc, char **argv) // screen buffer. NOTE: height x width! Uint32 buffer [HEIGHT][WIDTH]; - + float k1, k2, k3; // plasma parameters - + // parameters are allowed to range from 0 to 256 k1 = 128.; @@ -55,64 +55,65 @@ int main (int argc, char **argv) d1 = -1; d2 = 1; d3 = 1; - + initwindow (WIDTH, HEIGHT); setbkcolor (BLACK); refresh (); - + // make a palette for (int i = 0; i < 255; i++) - setrgbpalette (i, + setrgbpalette (i, (int) fabs((128. - 127.*sinf((float)i*M_PI/32.))), (int) fabs((128. - 127.*sinf((float)i*M_PI/64.))), (int) fabs((128. - 127.*sinf((float)i*M_PI/128.))) ); - - int stop = 0; - - showinfobox ("Left click to switch between\nputbuffer() and putpixel()"); - + + showinfobox ("Left click to switch between\n" + "putbuffer() and putpixel();\n" + "any key to stop."); + int time = SDL_GetTicks (); - - do { + + while (! xkbhit()) { + int maxx = getmaxx (), maxy = getmaxy (); - + for (int y = 0; y < maxy; y++) { for (int x = 0; x < maxx; x++) { - + col = (int) ( sinf (x / 50.) * k1 + sinf (y / 40.) * k2 + sinf ((x + y) / 30.) * k3); - + while (col > 255) col -= 256; while (col < 0) col += 256; - + r = RED_VALUE (col); g = GREEN_VALUE (col); b = BLUE_VALUE (col); - + // this would be slow: // setrgbpalette (col, r, g, b); // setrgbcolor (col); // _putpixel (x, y); - + if (1 == use_buffer) buffer [y][x] = colorRGB (r, g, b); else putpixel (x, y, COLOR(r, g, b)); - + } // for x } // for y - + if (1 == use_buffer) putbuffer (buffer[0]); refresh (); counter++; - + if (SDL_GetTicks () >= time + 1000) { printf ("%d iterations/second\n", counter); time = SDL_GetTicks (); @@ -129,11 +130,7 @@ int main (int argc, char **argv) k3 += d3; if (k3 < 2 || k3 > 255) d3 *= -1; - - if (event()) - if (SDL_QUIT == eventtype ()) - stop = 1; - + if (1 == mouseclick()) { use_buffer ^= 1; if (use_buffer) @@ -141,9 +138,9 @@ int main (int argc, char **argv) else puts ("Using putpixel()"); } - - } while (!stop); - + + } // while + puts ("Bye!"); closegraph (); return 0; diff --git a/test/simple.c b/test/simple.c index 7d12770..a2005ff 100644 --- a/test/simple.c +++ b/test/simple.c @@ -120,16 +120,16 @@ void pixels (void) putpixel (random(maxx), random(maxy), col); } refresh (); - delay (1000); + stop = pause (1000); + if (stop) + break; srand (2015); for (i = 0; i < 300; i++) { col = 1 + random (MAXCOLORS); /* keep random () in sync */ putpixel (random(maxx), random(maxy), BLACK); - if (kbhit ()) - stop = 1; } refresh (); - delay (1000); + stop = pause (1000); cleardevice (); } // while