Code Monkey home page Code Monkey logo

tgx's Introduction

NEW VERSION 0.6 : [breaking changes] removed viewport dimension as template parameter, the dimension can now be set at runtime.

NEW VERSION 0.5 : the Z-buffer can now be either of type float (32 bits) or uint16_t (16 bits).

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 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.

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 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 and RGB64 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.

3D graphics.

  • 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) 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.

tgx's People

Contributors

vindar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.