I'm having some slight difficulties with getting a custom font working. The TL;DR version is that the code compiles (see below for code), but when simulated using Simbuino, I get a beautifully pixelated mess instead of my font. Do I need to change my setup to get it to recognise the custom font, and/or do I need to alter the font file itself to make it more like the default Gamebuino fonts?
I created this font last night (using rodot's handy font editor tool) as a modified combination of Gamebuino's 5x7 font, and the European font used in the Pokémon Game Boy games. Feeling quite happy with it, I exported that font, and decided to test it out. What I first decided to do was alter the created export file, to match as closely as possible to the default Gamebuino fonts. This meant cutting it back to 128 characters, and adjusting a few define statements. Simple enough, I thought. I chucked that C file into the utility subdirectory of the Gamebuino library folder, and attempted to reference it from my code. When attempting to compile this, I just got a handful of confusing compiler errors from the Arduino IDE instead.
So, I decided to just use the exported code, just as rodot's font editor intended. I included the font code inside of my test project, and referenced it in much the same way the 'keyboard' and 'setFont' examples do in the Gamebuino library. Amazingly, it compiled just fine. The problem was when it came to testing it on Simbuino. Upon running it, it appears that my font just comes out as a bunch of garbled pixels instead.
Here's the current code as a reference:
(Font_Test.ino)
- Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
extern const byte Creatini_5x7[];
char userName[11] = "Your name";
void setup()
{
gb.begin();
gb.display.setFont(Creatini_5x7);
gb.titleScreen(F("Font Test"));
gb.keyboard(userName, 10);
}
void loop()
{
if (gb.update())
{
gb.display.println(F("Your name is:"));
gb.display.println(userName);
gb.display.fontSize = 2;
gb.display.println(F("Creatini 5x7 font\n"));
gb.display.println(F("The quick brown fox\njumps over the lazy dog"));
gb.display.fontSize = 1;
gb.display.println(F("Creatini 5x7 font\n"));
gb.display.println(F("The quick brown fox\njumps over the lazy dog"));
if (gb.buttons.pressed(BTN_C))
{
gb.titleScreen(F("Font Test"));
gb.keyboard(userName, 10);
}
}
}
(Creatini5x7_font.ino)
- Code: Select all
/*
* Creatini_5x7
* made by Liam Snow
*
* created with FontCreator
* written by F. Maximilian Thiele
*
* http://www.apetech.de/fontCreator
* me@apetech.de
*
* File Name : Creatini5x7_font
* Date : 16.04.2017
* Font size in bytes : 7263
* Font width : 5
* Font height : -8
* Font first char : 0
* Font last char : 177
* Font used chars : 177
*
* The font data are defined as
*
* struct _FONT_ {
* uint16_t font_Size_in_Bytes_over_all_included_Size_it_self;
* uint8_t font_Width_in_Pixel_for_fixed_drawing;
* uint8_t font_Height_in_Pixel_for_all_characters;
* unit8_t font_First_Char;
* uint8_t font_Char_Count;
*
* uint8_t font_Char_Widths[font_Last_Char - font_First_Char +1];
* // for each character the separate width in pixels,
* // characters < 128 have an implicit virtual right empty row
*
* uint8_t font_data[];
* // bit field of all characters
*/
#include <inttypes.h>
#include <avr/pgmspace.h>
#ifndef CREATINI_5X7_H
#define CREATINI_5X7_H
#define CREATINI_5X7_WIDTH 5
#define CREATINI_5X7_HEIGHT -8
const uint8_t Creatini_5x7[] PROGMEM = {
0x1C, 0x5F, // size
0x05, // width
0xF8, // height
0x00, // first char
0xB1, // char count
// char widths
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
// font data
0x7F, 0x41, 0x41, 0x41, 0x7F, // 0
0x3E, 0x4B, 0x6F, 0x4B, 0x3E, // 1 sad
0x3E, 0x4B, 0x5F, 0x4B, 0x3E, // 2 happy
0x1C, 0x3C, 0x78, 0x3C, 0x1C, // 3 heart
0x18, 0x3C, 0x7E, 0x3C, 0x18, // 4 diamond
0x1C, 0x57, 0x7D, 0x57, 0x1C, // 5 clover
0x1C, 0x5E, 0x7F, 0x5E, 0x1C, // 6 spade
0x00, 0x7E, 0x43, 0x43, 0x7E, // 7 bat low
0x00, 0x7E, 0x73, 0x73, 0x7E, // 8 bat med
0x00, 0x7E, 0x7F, 0x7F, 0x7E, // 9 bat high
0x7F, 0x41, 0x41, 0x41, 0x7F, // 10 line feed
0x24, 0x52, 0x5F, 0x52, 0x24, // 11 male
0x06, 0x29, 0x79, 0x29, 0x06, // 12 female
0x7F, 0x41, 0x41, 0x41, 0x7F, // 13 carriage return
0x60, 0x70, 0x3F, 0x02, 0x04, // 14 quaver
0x2A, 0x1C, 0x36, 0x1C, 0x2A, // 15 sun
0x7F, 0x7F, 0x3E, 0x1C, 0x08, // 16 right triangle
0x08, 0x1C, 0x3E, 0x7F, 0x7F, // 17 left triangle
0x14, 0x22, 0x7F, 0x22, 0x14, // 18 double arrow
0x3C, 0x3C, 0x3C, 0x7E, 0xFF, // 19 speaker
0x18, 0x42, 0x3C, 0x81, 0x7E, // 20 sound
0x3E, 0x63, 0x75, 0x63, 0x3E, // 21 A button
0x3E, 0x61, 0x6B, 0x63, 0x3E, // 22 B button
0x3E, 0x63, 0x6B, 0x6B, 0x3E, // 23 C button
0x04, 0x02, 0x7F, 0x02, 0x04, // 24 up arrow
0x10, 0x20, 0x7F, 0x20, 0x10, // 25 down arrow
0x08, 0x08, 0x2A, 0x1C, 0x08, // 26 right arrow
0x08, 0x1C, 0x2A, 0x08, 0x08, // 27 left arrow
0x14, 0x3E, 0x55, 0x41, 0x22, // 28 euro
0x63, 0x55, 0x49, 0x55, 0x63, // 29 timer
0x30, 0x38, 0x3C, 0x38, 0x30, // 30 up triangle
0x0C, 0x1C, 0x3C, 0x1C, 0x0C, // 31 down triangle
0x00, 0x00, 0x00, 0x00, 0x00, // 32 space
0x0E, 0xDF, 0xDF, 0x0E, 0x00, // 33 exclamation mark
0x00, 0x07, 0x00, 0x07, 0x00, // 34 quotation mark
0x14, 0x7F, 0x14, 0x7F, 0x14, // 35 hash
0x04, 0x2A, 0x7F, 0x2A, 0x10, // 36 dollar
0x23, 0x13, 0x08, 0x64, 0x62, // 37 percent
0x36, 0x49, 0x56, 0x20, 0x58, // 38 ampersand
0x00, 0x0B, 0x07, 0x00, 0x00, // 39 apostrophe
0x00, 0x1C, 0x22, 0x41, 0x41, // 40 open bracket
0x41, 0x41, 0x22, 0x1C, 0x00, // 41 close bracket
0x44, 0x28, 0x3E, 0x28, 0x44, // 42 asterisk
0x08, 0x08, 0x3E, 0x08, 0x08, // 43 plus
0x00, 0xB0, 0x70, 0x00, 0x00, // 44 comma
0x08, 0x08, 0x08, 0x08, 0x08, // 45 minus
0x00, 0x60, 0x60, 0x00, 0x00, // 46 full stop
0x40, 0x20, 0x10, 0x08, 0x04, // 47 forward slash
0x3C, 0x62, 0x42, 0x46, 0x3C, // 48 0
0x44, 0x7E, 0x7E, 0x40, 0x00, // 49 1
0x64, 0x76, 0x52, 0x5A, 0x4E, // 50 2
0x62, 0x42, 0x4A, 0x6E, 0x76, // 51 3
0x30, 0x3C, 0x26, 0x7E, 0x20, // 52 4
0x2E, 0x4E, 0x4A, 0x6A, 0x7A, // 53 5
0x3C, 0x7E, 0x4A, 0x4A, 0x32, // 54 6
0x06, 0x62, 0x72, 0x1A, 0x0E, // 55 7
0x34, 0x6A, 0x4A, 0x4A, 0x34, // 56 8
0x0C, 0x52, 0x52, 0x7A, 0x3C, // 57 9
0x00, 0x66, 0x66, 0x00, 0x00, // 58 colon
0x00, 0xB6, 0x76, 0x00, 0x00, // 59 semi-colon
0x08, 0x14, 0x22, 0x41, 0x00, // 60 left chevron
0x14, 0x14, 0x14, 0x14, 0x14, // 61 equals
0x00, 0x41, 0x22, 0x14, 0x08, // 62 right chevron
0x0C, 0x06, 0xB2, 0x16, 0x0C, // 63 question mark
0x3E, 0x63, 0x5D, 0x53, 0x4E, // 64 at sign
0x60, 0x1E, 0x11, 0x1E, 0x60, // 65 uppercase A
0x7F, 0x49, 0x49, 0x4E, 0x30, // 66 uppercase B
0x3E, 0x63, 0x41, 0x41, 0x22, // 67 uppercase C
0x7F, 0x41, 0x41, 0x63, 0x3E, // 68 uppercase D
0x7F, 0x49, 0x49, 0x49, 0x41, // 69 uppercase E
0x7F, 0x09, 0x09, 0x09, 0x01, // 70 uppercase F
0x3E, 0x41, 0x49, 0x49, 0x3A, // 71 uppercase G
0x7F, 0x08, 0x08, 0x08, 0x7F, // 72 uppercase H
0x41, 0x41, 0x7F, 0x41, 0x41, // 73 uppercase I
0x30, 0x41, 0x41, 0x3F, 0x01, // 74 uppercase J
0x7F, 0x08, 0x14, 0x22, 0x41, // 75 uppercase K
0x7F, 0x40, 0x40, 0x40, 0x40, // 76 uppercase L
0x7F, 0x02, 0x04, 0x02, 0x7F, // 77 uppercase M
0x7F, 0x04, 0x08, 0x10, 0x7F, // 78 uppercase N
0x3E, 0x41, 0x41, 0x41, 0x3E, // 79 uppercase O
0x7F, 0x09, 0x09, 0x09, 0x06, // 80 uppercase P
0x3E, 0x41, 0x51, 0x21, 0x5E, // 81 uppercase Q
0x7F, 0x09, 0x19, 0x29, 0x46, // 82 uppercase R
0x26, 0x49, 0x49, 0x4A, 0x30, // 83 uppercase S
0x01, 0x01, 0x7F, 0x01, 0x01, // 84 uppercase T
0x1F, 0x20, 0x40, 0x40, 0x7F, // 85 uppercase U
0x0F, 0x30, 0x40, 0x30, 0x0F, // 86 uppercase V
0x7F, 0x20, 0x10, 0x20, 0x7F, // 87 uppercase W
0x63, 0x14, 0x08, 0x14, 0x63, // 88 uppercase X
0x03, 0x04, 0x78, 0x04, 0x03, // 89 uppercase Y
0x61, 0x51, 0x49, 0x45, 0x43, // 90 uppercase Z
0x00, 0x7F, 0x41, 0x41, 0x00, // 91 open square bracket
0x04, 0x08, 0x10, 0x20, 0x40, // 92 back slash
0x00, 0x41, 0x41, 0x7F, 0x00, // 93 close square bracket
0x04, 0x02, 0x01, 0x02, 0x04, // 94 caret
0x80, 0x80, 0x80, 0x80, 0x80, // 95 underscore
0x00, 0x07, 0x0B, 0x00, 0x00, // 96 vertical comma
0x20, 0x54, 0x54, 0x78, 0x40, // 97 lowercase a
0x7F, 0x48, 0x48, 0x48, 0x30, // 98 lowercase b
0x38, 0x44, 0x44, 0x44, 0x28, // 99 lowercase c
0x30, 0x48, 0x48, 0x48, 0x7F, // 100 lowercase d
0x38, 0x54, 0x54, 0x54, 0x58, // 101 lowercase e
0x08, 0x7E, 0x09, 0x09, 0x02, // 102 lowercase f
0x98, 0xA4, 0xA4, 0xA4, 0x7C, // 103 lowercase g
0x7F, 0x08, 0x08, 0x08, 0x70, // 104 lowercase h
0x00, 0x00, 0x7A, 0x00, 0x00, // 105 lowercase i
0x00, 0x60, 0x40, 0x3A, 0x00, // 106 lowercase j
0x7F, 0x10, 0x28, 0x44, 0x44, // 107 lowercase k
0x00, 0x7F, 0x40, 0x20, 0x00, // 108 lowercase l
0x7C, 0x04, 0x78, 0x04, 0x78, // 109 lowercase m
0x7C, 0x08, 0x04, 0x04, 0x78, // 110 lowercase n
0x38, 0x44, 0x44, 0x44, 0x38, // 111 lowercase o
0xFC, 0x24, 0x24, 0x24, 0x18, // 112 lowercase p
0x18, 0x24, 0x24, 0x24, 0xFC, // 113 lowercase q
0x7C, 0x08, 0x04, 0x04, 0x04, // 114 lowercase r
0x48, 0x54, 0x54, 0x54, 0x20, // 115 lowercase s
0x04, 0x04, 0x3E, 0x44, 0x44, // 116 lowercase t
0x3C, 0x40, 0x40, 0x20, 0x7C, // 117 lowercase u
0x1C, 0x20, 0x40, 0x20, 0x1C, // 118 lowercase v
0x3C, 0x40, 0x20, 0x40, 0x3C, // 119 lowercase w
0x44, 0x28, 0x10, 0x28, 0x44, // 120 lowercase x
0x9C, 0xA0, 0xA0, 0xA0, 0x7C, // 121 lowercase y
0x44, 0x64, 0x54, 0x4C, 0x44, // 122 lowercase z
0x08, 0x36, 0x41, 0x41, 0x00, // 123 open curly brace
0x00, 0x00, 0x7F, 0x00, 0x00, // 124 pipe
0x00, 0x41, 0x41, 0x36, 0x08, // 125 close curly brace
0x18, 0x04, 0x08, 0x10, 0x0C, // 126 tilde
0x7F, 0x41, 0x41, 0x41, 0x7F, // 127 blank
0x70, 0xFB, 0xFB, 0x70, 0x00, // 128 inverted exclamation mark
0x0C, 0x12, 0x12, 0x0C, 0x00, // 129 degree
0x30, 0x68, 0x4D, 0x60, 0x30, // 130 inverted question mark
0x60, 0x38, 0x25, 0x3A, 0x60, // 131 uppercase A grave
0x60, 0x3A, 0x25, 0x38, 0x60, // 132 uppercase A acute
0x60, 0x39, 0x24, 0x39, 0x60, // 133 uppercase A diaeresis
0x7C, 0x54, 0x55, 0x56, 0x44, // 134 uppercase E grave
0x7C, 0x56, 0x55, 0x54, 0x44, // 135 uppercase E acute
0x44, 0x44, 0x7D, 0x46, 0x44, // 136 uppercase I grave
0x44, 0x46, 0x7D, 0x44, 0x44, // 137 uppercase I acute
0x7A, 0x09, 0x11, 0x22, 0x79, // 138 uppercase N tilde
0x7C, 0x44, 0x45, 0x46, 0x7C, // 139 uppercase O grave
0x7C, 0x46, 0x45, 0x44, 0x7C, // 140 uppercase O acute
0x7C, 0x45, 0x44, 0x45, 0x7C, // 141 uppercase O diaeresis
0x00, 0x18, 0x18, 0x00, 0x00, // 142 multiply dot
0x08, 0x08, 0x2A, 0x08, 0x08, // 143 division
0x1C, 0x20, 0x41, 0x42, 0x7C, // 144 uppercase U grave
0x1C, 0x22, 0x41, 0x40, 0x7C, // 145 uppercase U acute
0x1C, 0x21, 0x40, 0x41, 0x7C, // 146 uppercase U diaeresis
0x7F, 0x01, 0x29, 0x4E, 0x30, // 147 sharp S
0x20, 0x54, 0x55, 0x7A, 0x40, // 148 lowercase a grave
0x20, 0x56, 0x55, 0x78, 0x40, // 149 lowercase a acute
0x20, 0x56, 0x55, 0x7A, 0x40, // 150 lowercase a circumflex
0x20, 0x55, 0x54, 0x79, 0x40, // 151 lowercase a diaeresis
0x18, 0xA4, 0xE4, 0x24, 0x08, // 152 lowercase c cedilla
0x38, 0x54, 0x55, 0x56, 0x58, // 153 lowercase e grave
0x38, 0x56, 0x55, 0x54, 0x58, // 154 lowercase e acute
0x38, 0x56, 0x55, 0x56, 0x58, // 155 lowercase e circumflex
0x38, 0x55, 0x54, 0x55, 0x58, // 156 lowercase e diaeresis
0x00, 0x01, 0x7A, 0x00, 0x00, // 157 lowercase i grave
0x00, 0x00, 0x7A, 0x01, 0x00, // 158 lowercase i acute
0x00, 0x02, 0x79, 0x02, 0x00, // 159 lowercase i circumflex
0x00, 0x02, 0x78, 0x02, 0x00, // 160 lowercase i diaeresis
0x7A, 0x11, 0x09, 0x0A, 0x71, // 161 lowercase n tilde
0x38, 0x44, 0x45, 0x46, 0x38, // 162 lowercase o grave
0x38, 0x46, 0x45, 0x44, 0x38, // 163 lowercase o acute
0x38, 0x46, 0x45, 0x46, 0x38, // 164 lowercase o circumflex
0x38, 0x45, 0x44, 0x45, 0x38, // 165 lowercase o diaeresis
0x3C, 0x40, 0x41, 0x22, 0x7C, // 166 lowercase u grave
0x3C, 0x42, 0x41, 0x20, 0x7C, // 167 lowercase u acute
0x3C, 0x42, 0x41, 0x22, 0x7C, // 168 lowercase u circumflex
0x3C, 0x41, 0x40, 0x21, 0x7C, // 169 lowercase u diaeresis
0x24, 0x42, 0x42, 0x66, 0x3C, // 170 moon
0x3E, 0x6B, 0x6F, 0x6B, 0x3E, // 171 neutral
0x48, 0x7E, 0x49, 0x41, 0x42, // 172 pound
0x2B, 0x2C, 0x78, 0x2C, 0x2B, // 173 yen
0x30, 0x3F, 0x02, 0x64, 0x78, // 174 beamed quaver
0x02, 0x04, 0x09, 0x02, 0x04, // 175 left slant quotation mark
0x04, 0x02, 0x09, 0x04, 0x02 // 176 right slant quotation mark
};
#endif
Having now checked the Display.cpp file in the Gamebuino library, it appears that the setFont function only expects a width and height to be defined before the actual bitmaps of the font. So, I guess the easiest way to ask is "What do I need to alter in order to get my custom font to play along nicely with the Gamebuino library?".
Do I need to write alternative code to the Gamebuino library in order to read this font in? Or do I need to adjust the font definition to be more like the default Gamebuino fonts? Or am I simply over-thinking all of this? (now that certainly wouldn't be for the first time!)
Sorry for the long post, and thank you in advance!