Closed GeorgeFlorian closed 5 years ago
Hello !
I am trying to make a simple code that can output a line of text on the display. But the font isn't loading.
This is what I've used to load the desired font:
const char *fontFile = "fonts/10x20.bdf"; //const char *fontFile = "10x20.bdf";
static void TextLine(Canvas *canvas, int x, int y, const char* line) { canvas->Fill(0,0,0); rgb_matrix::Color mRed(225, 20, 34); rgb_matrix::Color blackBg(0, 0, 0); rgb_matrix::Font font; if(!font.LoadFont(fontFile)) { std::cout<<"Couldn't load font file\n"; } rgb_matrix::DrawText(canvas, font, x, y, mRed, &blackBg, line); int k = 10; while (k != 0) { TextLine(canvas,0,0,"Test 1"); k--; usleep(1 * 1000); } canvas->Clear(); delete canvas; }
This is the full code:
#include "led-matrix.h" #include "graphics.h" #include <iostream> #include <unistd.h> #include <math.h> #include <stdio.h> #include <signal.h> using rgb_matrix::GPIO; using rgb_matrix::RGBMatrix; using rgb_matrix::Canvas; volatile bool interrupt_received = false; static void InterruptHandler(int signo) { interrupt_received = true; } const char *fontFile = "fonts/10x20.bdf"; static void TextLine(Canvas *canvas, int x, int y, const char* line) { canvas->Fill(0,0,0); rgb_matrix::Color mRed(225, 20, 34); rgb_matrix::Color blackBg(0, 0, 0); rgb_matrix::Font font; if(!font.LoadFont(fontFile)) { std::cout<<"Couldn't load font file\n"; } rgb_matrix::DrawText(canvas, font, x, y, mRed, &blackBg, line); } int main(int argc, char *argv[]) { RGBMatrix::Options defaults; defaults.hardware_mapping = "regular"; // or e.g. "adafruit-hat" defaults.rows = 32; defaults.chain_length = 1; defaults.parallel = 1; defaults.show_refresh_rate = true; Canvas *canvas = rgb_matrix::CreateMatrixFromFlags(&argc, &argv, &defaults); if (canvas == NULL) return 1; // It is always good to set up a signal handler to cleanly exit when we // receive a CTRL-C for instance. The DrawOnCanvas() routine is looking // for that. signal(SIGTERM, InterruptHandler); signal(SIGINT, InterruptHandler); int k = 10; while (k != 0) { TextLine(canvas,0,0,"Test 1"); k--; usleep(1 * 1000); } canvas->Clear(); delete canvas; return 0; }
How do I properly load a font file ? Where did I go wrong ?
Guess what ? const char *fontFile = "rpi-rgb-led-matrix/fonts/10x20.bdf"; worked ! The font appears to be loading, but the code doesn't do anything. The display is black.
const char *fontFile = "rpi-rgb-led-matrix/fonts/10x20.bdf";
Hello !
I am trying to make a simple code that can output a line of text on the display. But the font isn't loading.
This is what I've used to load the desired font:
This is the full code:
How do I properly load a font file ? Where did I go wrong ?