|
wx_BGI_Graphics
Classic BGI-compatible graphics API with modern OpenGL extension API
|
wx BGI Graphics is a C/C++ shared library that implements a classic BGI-compatible API (Borland Graphics Interface) on top of OpenGL, GLFW, GLEW and wxWidgets. The goal is to keep old Pascal/C/C++ graphics programs usable with minimal source changes while staying cross-platform on Windows, Linux, and macOS.
The download URLs above always point to the newest tagged GitHub Release asset with the matching filename.
| Document | Contents |
|---|---|
| Building.md | Dependencies, compile requirements, CMake flags, build commands for Windows / Linux / macOS, running examples |
| Tests.md | All 24 CTest targets, how to run them, test categories, test seam security policy, CI integration |
| Tutorial.md | BGI double-buffering deep dive: page buffers, setactivepage, swapbuffers, animation loops |
| WxWidgets.md | wxWidgets embedded canvas guide: WxBgiCanvas, standalone wx API, event routing, 3D in wx mode |
| DDS.md | Drawing Description Data Structure: scene graph, CHDOP hierarchy, wxbgi_dds_* API, JSON/YAML serialization |
| Camera3D_Map.md | 3-D camera code map: Camera3D struct, GLM math, wxbgi_cam_* API |
| Camera2D_Map.md | 2-D overhead camera: pan/zoom/rotation, wxbgi_cam2d_* API |
| InputsProcessing.md | Keyboard and mouse event handling, keyboard queue, DOS-style extended keys, input hooks |
| VisualAids.md | Visual overlay system: reference grid, UCS axes, crosshair, selection cursor |
| ScreenShots.md | Annotated screenshots of example programs |
The library now includes classic BGI-style support for:
initgraph, closegraph, graphresult, graphdefaultsline, lineto, linerel, rectangle, bar, bar3d, circle, arc, ellipse, pieslice, sectorfloodfill, fillpoly, fillellipse, setfillstyle, setfillpatternsetviewport, getviewsettings, setpalette, setrgbpalette, setbkcolor, setwritemodeouttext, outtextxy, settextstyle, settextjustify, textwidth, textheightimagesize, getimage, putimagesetactivepage, setvisualpage, getactivepage, getvisualpage, swapbufferswxbgi_cam_*, wxbgi_cam2d_*, wxbgi_ucs_*, and wxbgi_world_*wxbgi_dds_*wxbgi_solid_*wxbgi_solid_set_light_*wx_bgi_wx) with OpenGL 3.3 texture-quad compositing and automatic legacy fallbackPublic API declarations are available in:
src/wx_bgi.h (classic BGI API)src/wx_bgi_ext.h (modern extension helpers)src/wx_bgi_3d.h (camera, UCS, world-coordinate extension API)src/wx_bgi_dds.h (Drawing Description Data Structure – DDS/CHDOP/DDJ/DDY)See DDS.md for a full explanation of the DDS acronyms, the CHDOP object hierarchy, all wxbgi_dds_* functions, and usage examples.
The library provides two camera modes, both built on the Camera3D struct:
wxbgi_cam_* API, serialization, and the file dependency diagram.is2D = true): pan/zoom/rotation math, wxbgi_cam2d_* API, zoom-at pivot formula, and usage example.See ScreenShots.md for annotated screenshots of the example programs.
Please see ./examples/bgidemo-pascal/README.md.
In addition to classic BGI, the library now exports an optional non-BGI extension API for modern control paths such as explicit event pumping, context control, swap interval, size queries, frame begin/end, and pixel readback.
src/wx_bgi_ext.hwxbgi_ prefixThis extension API is intended to complement BGI compatibility, not replace it.
The project now includes a dedicated camera/UCS extension layer for engineering-style world coordinates while keeping classic BGI behavior unchanged.
Highlights:
"default" is created by initwindow / initgraph.wxbgi_cam_*.wxbgi_cam2d_*.wxbgi_ucs_*.wxbgi_set_world_extents, wxbgi_expand_world_extents, and wxbgi_cam_fit_to_extents.wxbgi_world_line, wxbgi_world_circle, wxbgi_ucs_line, and wxbgi_ucs_outtextxy project through the active camera into the classic BGI pixel pipeline.Minimal camera setup example:
The extension API also exposes a small keyboard input layer for GUI-style event waits that do not rely on terminal or console input.
wxbgi_key_pressed() reports whether a translated key event is waiting in the internal queue.wxbgi_read_key() consumes the next queued key code.wxbgi_is_key_down(glfwKey) checks raw key-down state for a GLFW key code such as GLFW_KEY_ESCAPE or GLFW_KEY_LEFT.Input is captured from the graphics window through GLFW callbacks.
Esc, Enter, and Tab are queued as their classic ASCII control values.wxbgi_read_key() returns 0 first, then returns the scan code on the next read.This makes it practical to port old Pascal and BGI programs that used KeyPressed and ReadKey style control flow without falling back to Crt.
For the complete keyboard input reference, test seam security policy, and CI integration details see Tests.md.
The snippet below shows a minimal frame loop using the wx standalone API (default mode):
GLFW-mode (with WXBGI_ENABLE_WX=OFF) uses the classic initwindow / frame loop pattern:
You can also query runtime information independently of the draw loop:
wxWidgets is the default rendering backend. The DLL is built with wx support automatically — no extra CMake flag needed:
The library ships two wx integration options:
Open a wx window using only the C API — no wx C++ required:
This is how the Python (bgi_api_coverage.py) and FreePascal programs work.
For C++ apps that need menus, status bars, or custom wx controls alongside the BGI surface, use wx_bgi_wx.lib + WxBgiCanvas:
To build without wxWidgets (GLFW-only):
See WxWidgets.md for the full integration guide, standalone API reference, event routing table, 3D camera setup in wx mode, and automated tests.
The wx_bgi_dds.h header exposes retained-mode 3D solid primitives that are stored in the DDS scene graph and rendered through any Camera3D via wxbgi_render_dds().
| Constant | Description |
|---|---|
WXBGI_SOLID_WIREFRAME | Edge-only rendering using the current line colour. |
WXBGI_SOLID_SOLID / WXBGI_SOLID_FLAT | Filled faces; flat Phong shading via GPU depth pass (pending GL-5). |
WXBGI_SOLID_SMOOTH | Smooth per-vertex Gouraud/Phong shading (pending GL-5). |
Configure the key and fill lights plus material properties:
Note: Phong-shaded GPU solid rendering (depth buffer, correct occlusion) is infrastructure-complete (shaders in
bgi_gl_shaders.h,LightStateinBgiState) but the wiring to the draw pipeline (GL-5 through GL-8) is pending. Current solid rendering uses the CPU-side projected-triangle path; depth-ordering artefacts may be visible.
In wx mode the BGI pixel buffer is composited via an OpenGL 3.3 texture quad. The library detects the available GL version at runtime and falls back to the legacy GL_POINTS path automatically on older hardware. To force the legacy path explicitly:
The text renderer now uses a scalable stroke-font implementation rather than the earlier fixed 5x7 bitmap glyphs. That change improves compatibility in a few important ways:
settextstyle now affects font family/profile instead of only storing metadatacharsize and setusercharsize instead of enlarging a tiny bitmaptextwidth and textheight now reflect the actual scaled stroke layout more closelyThe current stroke-font implementation is still lightweight, but it is materially closer to classic BGI behavior than the old bitmap-only path.
The library has one shared glyph dataset used by all 5 font profiles (DEFAULT_FONT, TRIPLEX_FONT, SMALL_FONT, SANS_SERIF_FONT, GOTHIC_FONT). The profiles apply different scale, thickness, and slant on top of the same strokes – so adding glyphs once covers all fonts. All printable ASCII Glyphs are included now with Release v1.1.0.
Please read more about this at Tutorial.md.
The examples are under the ./examples/ folder.
| Source | Language | What it exercises |
|---|---|---|
examples/cpp/bgi_api_coverage.cpp | C++ | Classic BGI API (standalone GLFW/wx) |
examples/python/bgi_api_coverage.py | Python | ctypes BGI API coverage |
examples/demoFreePascal/demo_bgi_api_coverage.pas | FreePascal | BGI API — GLFW → wx-standalone path |
examples/demoFreePascal/demo_bgi_canvas_coverage.pas | FreePascal | BGI API — wx-only path (no GLFW) |
examples/wx/wx_bgi_canvas_coverage_test.cpp | C++ / wx | BGI API — embedded WxBgiCanvas (timer-based phases) |
| Source | Language | Description |
|---|---|---|
examples/cpp/wxbgi_camera_demo.cpp | C++ | Camera/UCS/world-coordinate interactive demo |
examples/cpp/wxbgi_keyboard_queue.cpp | C++ | DOS-style keyboard queue |
examples/demoFreePascal/demo_bgi_wrapper.pas | FreePascal | Minimal BGI wrapper demo |
examples/demoFreePascal/demo_bgi_wrapper_gui.pas | FreePascal | GUI subsystem BGI demo |
examples/demoFreePascal/demo_wxbgi_keyboard_queue.pas | FreePascal | Keyboard queue from Pascal |
examples/wx/wx_bgi_3d_orbit_test.cpp | C++ / wx | 3-D orbit animation in embedded canvas |
examples/wx/wx_bgi_solids_test.cpp | C++ / wx | 3-D solids in embedded canvas |
examples/wx/wx_bgi_app.cpp | C++ / wx | Interactive 2-D mouse/keyboard demo |
examples/wx/wx_bgi_3d_app.cpp | C++ / wx | Interactive 3-D orbiting camera with solids |
See Building.md for interactive run commands on every platform.
See Tests.md for CTest commands, test categories, and CI details.
See Building.md for full dependency details.
FetchContent on Windows/Linux.brew install glfw wxwidgets and configure with -DWXBGI_SYSTEM_GLFW=ON -DWXBGI_SYSTEM_WX=ON (FetchContent builds fail on macOS 15 / Apple Clang 17).See Building.md for full build and test instructions.
Quick start (Windows):
Quick start (Linux):
Quick start (macOS Apple Silicon — system GLFW and wxWidgets required):
See Tests.md — CI Integration for the full CI setup, release tagging instructions, and GitHub Pages deployment guide.
This code is Open Source and Free to use with no warranties or claims.
This repository is based on Open-Source Code from 8 different sources:
Depends on C/C++ Template created by Luke of devmindscapetutorilas: