vindar
Well-known member
Hello,
I have been working on a new graphics library for a few week: tgx - Tiny/Teensy GraphicX library available here: https://github.com/vindar/tgx.
With the advent of powerful MCU like Teensy 4 which has lots of RAM, it becomes possible to use memory framebuffers... and that it what this library does: it just creates images on RAM. Then you can choose whatever method you prefer to send the image to a display. As such, the library does care about hardware and it is cross-platform. It should work with any 32bit MCU/CPU. For instance, it works well on my Ryzen 7 (which is perfectly useless
). However, the library has been optimized with T4/T4.1 in mind so this is where it really shines. The library supports "tile rendering" which enables to reduce the framebuffer size so it should theoretically also be usable on T3.5/T3.6 but I have not tried it yet...
I know that are already some nice libraries out there. For example Adafruit GFX Canvas and KurtE's ILI9341_t3n for 2D drawing and mjs513 pseudo-OpenGL for 3D but they are all lacking some features I wanted. There is also JarkkoL 3D graphics library which looks amazing but i believe it is not publicly available. Anyway, I always wanted to write my own triangle rasterizer so this was a good excuse to reinvent the wheel one more time...
The library contains methods for both 2D and 3D graphics. Here is the sales pitch:
2D graphics
3D graphics
For the time being, there is no standalone documentation for the library but all the header files are heavily commented and there is a docstring attached with all public methods to explain its purpose and usage. Also, the examples show how to use most features. It is still very much a work in progress so I expect there are many bugs to be found but I think it is already usable. Please let me know if you find bugs, thanks !
Here are a few videos that show what the library can do. I am sorry for the poor video quality and I blame my crappy cellphone for the colors all washed out. Trust me, it looks my better in reality
Everything below is running on a T4.1 and I am using my ILI9341_T4 https://github.com/vindar/ILI9341_T4 to push the memory framebuffer to the ILI9341 display. SPI is running at 30Mhz which means that the theoretical maximum framerate when redrawing the whole screen at each frame is 25FPS. Here, using differential updates makes a impressive improvement as you can see with the FPS counter on the top right corner of the screen that shows the real number of frames rendered and pushed to the screen each second.
(1) Basic test models Comparison between flat vs Gouraud shading (Gouraud here means that colors and not the normals are interpolated to get the pixels colors, however the color on the triangles vertices are computed using Phong's shading/lightning model).
(2) Testing texture mapping. Textures are just Image object that can be stored in RAM or flash.
I have been working on a new graphics library for a few week: tgx - Tiny/Teensy GraphicX library available here: https://github.com/vindar/tgx.
With the advent of powerful MCU like Teensy 4 which has lots of RAM, it becomes possible to use memory framebuffers... and that it what this library does: it just creates images on RAM. Then you can choose whatever method you prefer to send the image to a display. As such, the library does care about hardware and it is cross-platform. It should work with any 32bit MCU/CPU. For instance, it works well on my Ryzen 7 (which is perfectly useless
I know that are already some nice libraries out there. For example Adafruit GFX Canvas and KurtE's ILI9341_t3n for 2D drawing and mjs513 pseudo-OpenGL for 3D but they are all lacking some features I wanted. There is also JarkkoL 3D graphics library which looks amazing but i believe it is not publicly available. Anyway, I always wanted to write my own triangle rasterizer so this was a good excuse to reinvent the wheel one more time...
The library contains methods for both 2D and 3D graphics. Here is the sales pitch:
2D graphics
- Support for multiple color types: RGB16, RGB24, RGB32, RGBf. 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 should be faster in most cases.
- Support for Adafruit's fonts as well as PJRC's ILI9341_t3 v1 and v2.3 (anti-aliased) fonts.
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.
For the time being, there is no standalone documentation for the library but all the header files are heavily commented and there is a docstring attached with all public methods to explain its purpose and usage. Also, the examples show how to use most features. It is still very much a work in progress so I expect there are many bugs to be found but I think it is already usable. Please let me know if you find bugs, thanks !
Here are a few videos that show what the library can do. I am sorry for the poor video quality and I blame my crappy cellphone for the colors all washed out. Trust me, it looks my better in reality
Everything below is running on a T4.1 and I am using my ILI9341_T4 https://github.com/vindar/ILI9341_T4 to push the memory framebuffer to the ILI9341 display. SPI is running at 30Mhz which means that the theoretical maximum framerate when redrawing the whole screen at each frame is 25FPS. Here, using differential updates makes a impressive improvement as you can see with the FPS counter on the top right corner of the screen that shows the real number of frames rendered and pushed to the screen each second.
(1) Basic test models Comparison between flat vs Gouraud shading (Gouraud here means that colors and not the normals are interpolated to get the pixels colors, however the color on the triangles vertices are computed using Phong's shading/lightning model).
(2) Testing texture mapping. Textures are just Image object that can be stored in RAM or flash.