/tgx

tgx - a tiny/teensy 3D graphics library

Primary LanguageC++GNU Lesser General Public License v2.1LGPL-2.1

TGX - a tiny/teensy graphics library

Note: A companion library tgx-font provides a collection of plain and anti-aliased fonts which can be used with this library.

2D and 3D graphics library for 32bits microcontrollers.

This library implements a sets of classes that makes it simple 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 some of the library main features.

2D graphics.

  • Support for multiple color types: RGB565, RGB24, RGB32, RGB64, RGBf and HSV. 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 library, but with more primitives and faster ! Primitive for drawing, lines, triangles, rectangles circles, ellipses...
  • Methods for blitting sprites (with or without mask), image color type conversion and resizing.
  • Transparency / Alpha blending supported for all drawing methods.
  • 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 tgx-font).

3D graphics.

  • Heavily optimized "pixel perfect" triangle rasterizer with 8bits sub-pixels precision.
  • Depth buffer testing.
  • 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.
  • Perspective and Orthographic projection supported.
  • 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) and Box2 (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.

Using the library.

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.