NEW VERSION 0.5 : the Z-buffer can now be either of type float
(32 bits) or uint16_t
(16 bits).
Note: A companion library tgx-font provides a collection of plain and anti-aliased fonts which can be used with this library.
This library implements a sets of classes that makes it easy to draw 2D and 3D graphics onto a memory framebuffer. The library is aimed and optimized toward 32bits MCUs yet it is cross-platform and also works on CPUs.
The library has been currently tested on:
- Teensy 3.5, 3.6, 4.0, 4.1
- ESP32
- desktop CPUs
Warning: The library's goal is to draw graphics on a memory framebuffer. As such, it does not provide any hardware/screen support. You will need a screen driver to display the memory framebuffer onto a physical screen. If you are using a Teensy 4.0/4.1 and an ILI9341 screen, you may consider using my optimized driver.
Here are the library main features.
- Support for multiple color types:
RGB565
,RGB24
,RGB32
,RGB64
,RGBf
andHSV
. Every 2D/3D drawing operation is available for each color type. - Template
Image
class that encapsulates a memory framebuffer and enables the creation of sub-images (i.e. views) that share the same buffer. This provides an elegant and efficient way to clip of all drawing operations to a particular region. - API (mostly) compatible with Adafruit's GFX and Bodmer's TFT_eSPI libraries, but with more drawing primitives and usually faster ! Primitives for drawing lines, triangles, rectangles, circles, ellipses...
- Methods for blitting sprites with or without a transparent mask, with rotation and scaling. High quality drawing is achieved using bilinear filtering and sub-pixel precision for very smooth animations.
- Image color type conversion and resizing.
- Transparency supported for all drawing methods. The color types
RGB32
andRGB64
have an alpha channel used for alpha blending. - Anti-aliased methods for drawing thick lines and circles.
- Support for Adafruit's fonts as well as PJRC's ILI9341_t3 v1 and v2.3 anti-aliased fonts (see also tgx-font).
- Python script to convert an image to a C file that can be directly imported into a project.
- Heavily optimized "pixel perfect" triangle rasterizer with selectable sub-pixels precision (2, 4, 6 or 8 bits precision).
- Depth buffer testing (selectable 16 bits or 32 bits precision).
- Two wire-frame drawing modes: fast (simple lines, low quality) or slow (high quality, sub-pixel precision, anti-aliasing, custom line thickness)
- Flat and Gouraud shading.
- Phong lightning model with separate ambient/diffuse/specular color components (currently only one directional light source).
- Per object material properties.
- Perspective-correct texture mapping with selectable point sampling / bilinear filtering. Selectable wrap mode: repeat (for power of two textures) and clamp to edge.
- Perspective and Orthographic projection.
- Optional backface culling.
- Tile rasterization: it is possible to render only part of the viewport at a time to save RAM by using a smaller image and a smaller zbuffer.
- Templates classes for all the needed maths:
Vec2
,Vec3
,Vec4
(vectors),Mat4
(4x4 matrix) andBox2
(2D box). - Optimized mesh data format: meshes and textures can be read directly from flash memory to save RAM.
- Python scripts for easy conversion of texture images and 3D meshes (in Wavefront's .obj format) into C files that can be directly imported into an Arduino project.
TODO
-
Documentation available in the docstrings located in the header files.
-
Basic library usage can be found by looking at the examples located in the
/examples
sub-directory. -
Python conversion scripts needed to import meshes and textures are located in the
/tools
sub-directory.