In the previous article, I explained how to control the color of a particular LED of the RGB LED matrix panel. Thanks to that knowledge, you can draw simple graphics: points, circles, lines and so on. But how can we easily draw a rotating triangle? Or a mesh like a torus? Or any 3D scene? Answer in this article!
GeeXLab comes with a powerful feature used in almost any 3D game: render targets. In short, a render target allows to draw a 3D scene into a texture and then apply any kind of effects on that texture before displaying it.
That’s cool, but how will a render target help us to draw on our 32×32 RGB LED panel?
Wanting to try and create a Dot Matrix clock using the pi zero. Going to get an RTC module so it keeps time while offline and was looking at the dot matrix panels. (Just something cheap, doesn't need to be RGB) I was thinking an 8x32 module would be fine (using military time so 1 number per 8x8 module would fit perfectly). If you’ve followed the previous Pi-Lite setup article you should have a working Pi-Lite. The example Python scripts are great but I wanted to show a simple example of my own demonstrating the basics of sending scrolling text to the Pi-Lite.
Simply by drawing into a 32×32 pixels render target. Once the scene has been rendered in the render target, we can read each pixel of the render target texture and then use the gh_rpi.rgbmatrix_set_pixel_u8() function (see the previous article) to update the LED panel.
All following code samples and demos are available in two places:
– in the gl-21/rpi/rpi_rgb_matrix/ folder of the code sample pack.
– in the demos/rpi_rgb_matrix/ folder included with GeeXLab for Raspberry Pi.
– in the gl-21/rpi/rpi_rgb_matrix/ folder of the code sample pack.
– in the demos/rpi_rgb_matrix/ folder included with GeeXLab for Raspberry Pi.
These demos require GeeXLab for Raspberry Pi with OpenGL 2.1 support. This version of GeeXLab can be downloaded from this page.
How to run a demo?
In GeeXLab’s folder you will find a file called demos.sh. Edit this file and uncomment/comment the lines that start with sudo. If necessary, update the /demofile parameter with correct path + file name of the demo.
You can now run the demos.sh file. The demos.sh file has the execution bit set, so you can launch it by double-clicking on it. Or you can run it in command line with:
RGB LED matrix demos requires root level because they use the GPIO to control the RGB Matrix HAT.
Here is a code snippet in Lua (you can do the same thing in Python) that shows how to render a rotating triangle on the RGB LED matrix display. rt01 is the render target, vertex_color_prog is a simple vertex color GLSL program, camera is a perspective camera and triangle is a simple mesh made up of 3 vertices.
You can find the rotating triangle demo in the code sample pack here: gl-21/rpi/rpi_rgb_matrix/demo02_rpi_gl21.xml
Now let’s replace the simple RGB triangle by a torus with a Phong shader and a background image. You can find this demo in the code sample pack: gl-21/rpi/rpi_rgb_matrix/demo05_rpi_gl21.xml
A simple background image… (available here: gl-21/rpi/rpi_rgb_matrix/demo03_rpi_gl21.xml)
And what about some animated text? The following demo (available here: gl-21/rpi/rpi_rgb_matrix/demo04_rpi_gl21.xml) shows an animated text (based on a True Type Font)
Render targets are a powerful tool for real time graphics and are the key to easily display 3D stuff on a RGB LED matrix panel with a Raspberry Pi. Render targets are easy to use and are supported by GeeXLab on all platforms including, of course, the Raspberry Pi. As you can see, when you know how to render a 3D scene in a render target, you can draw what you want on a RGB LED matrix panel.
![Game pi zero dot matrix dmg code download Game pi zero dot matrix dmg code download](/uploads/1/2/5/8/125821962/983288812.jpg)
Update (2016.12.19)
I updated the code sample pack with a demo that shows how to render an anti-aliased triangle. The demo is available here: gl-21/rpi/rpi_rgb_matrix/demo06_rpi_gl21.xml
The principle is to render the main scene (here a simple rotating triangle) into a 64×64 render target. The 64×64 render target texture is then copied (with a render target blit function) to a second render target with a size of 32×32 pixels. This second render target will be used to update the RGB LED matrix. The result is a nice rotating triangle. All details are available in the demo source code.
The triangle rendered without anti-aliasing:
The same triangle rendered with anti-aliasing:
Related posts: