Font Size

Holzchopf

Moderator
Staff member
Joined
Jul 31, 2017
Location
Bern, Switzerland
You either load a bitmap font the size you like or you use SetScale to scale the output text (but this will make the font blurry).

Both Mojo and Mojo2 don't use "native" font render machines, meaning they don't load system fonts like Arial.ttf which can be drawn in any size or style. What they do is bitmap font drawing: They load an image containing glyphs (ASCII 32-127 I think) and draw them when drawing text. The default fonts are
modules\mojo\data\mojo_font.png
modules\mojo2\data\mojo2_font.png
 

dawlane

Active Member
CX Code Contributor
Joined
Jun 21, 2017
If I remember there is no function to change the size of a font.
You have three approaches
  1. Have another scaled version of the Font loaded and use SetFont.
  2. Use PushMatrix, Scale, DrawText, PopMatrix command in the order given.
  3. Create an array of source image positions, widths and height and use the DrawImageRect command.
 

dawlane

Active Member
CX Code Contributor
Joined
Jun 21, 2017
If you want better control of a font, then search the forum for the FontMachine. It may have been updated to work with the latest version of Cerberus.
 

AutmnLeaf

New Member
Joined
Feb 19, 2018
Though this is an old thread, here's my two cents: If like, you might want to try my free Font 2 PNG program, link. At the page there are example programs using the output of Font 2 PNG. The programs are written in Monkey X and work as such with Cerberus X. Also two links for implementing a font class for Font 2 PNG's output. Font Classes include changing font size.
 

dawlane

Active Member
CX Code Contributor
Joined
Jun 21, 2017
You should be able to use the Freetype library to render ttf's in a GL/EGL context. There should be plenty of tutorials, etc on the subject.

Here's a quickie.
 
Last edited:

dawlane

Active Member
CX Code Contributor
Joined
Jun 21, 2017
I should point out that you will of course be taking a performance penalty hit using ttf with GL.
 

Holzchopf

Moderator
Staff member
Joined
Jul 31, 2017
Location
Bern, Switzerland
And why? Isn't rendering glyphs stored in a texture loaded from a png file not very similar to rendering glyphs stored in a texture filled via a routine that renders vector based fonts? I can see why this would affect loading speeds. But the actual rendering?
 

dawlane

Active Member
CX Code Contributor
Joined
Jun 21, 2017
Isn't rendering glyphs stored in a texture loaded from a png file not very similar to rendering glyphs stored in a texture filled via a routine that renders vector based fonts?
Yes they do work in a similar fashion. The main issues would be getting the best use of texture space, dealing with unicode and how much text you can get into a single Vertex Buffer Object to improve performance.

It my be worth looking into Font-Stash and FTGL.
 

wick

Member
3rd Party Module Dev
Patreon Bronze
Joined
Jul 17, 2017
@Raph Ah! This looks useuful. Is the google code repo broken though? I'm getting a "There was an error getting resource 'downloads':"

So the only copy is that big copy+pasted block?
 

MikeHart

Administrator
Staff member
Joined
Jun 19, 2017
Location
Germany
Search in github for tfont. It will bring up a repro with chris's code. I was playing with at it is usable. The advantage is that runs on all mojo targets. Now i will think of a way to integrate it and port this to mojo2 ss well.
 
Top Bottom