Simple font renderer library written in Opengl 3.3 using stb_truetype.h to load a packed bitmap into texture of a .ttf font.

mv_easy_font

Simple font renderer library written in Opengl 3.3 using stb_truetype.h to load a packed bitmap into texture of a .ttf font.

Uses instanced rendering, so that only position, index and color of each glyph have to be updated instead of updating two triangles of vertex attributes per glyph.

Inspired by stb_easy_font.h.

Usage

Compile the example program with

gcc main.c -Iinclude -lglfw -lm

or similar linking options for your OS (like -ldl in linux). Run with:

./a.out path/to/font.ttf

or omit the file to use extra/Inconsolata-Regular.ttf.

To use mv_easy_font.h in any opengl project, #define MV_EASY_FONT_IMPLEMENTATION before including mv_easy_font.h in one .c/.cpp file, and include mv_easy_font.h wherever else needed. Simply call mv_ef_draw() with the appropriate parameters to draw text:

mv_ef_draw(str, col, offset, font_size, res);

somewhere in the render loop.

If

mv_ef_init(path_to_ttf, font_size, path_to_custom_vertex_shader, path_to_custom_fragment_shader);

is not called manually, it will try to look up a default font file using font size 48, and the built in shaders are used. All the three string arguments can be NULL to use default values.

Dependencies

mv_easy_font.h depends on stb_truetype.h and calls the OpenGL API, so make sure all the relevant OpenGL symbols and functions are loaded using something like GLEW, GLAD or whatever floats your boat.

You can optionally choose to use include stb_image_write.h (for generating font.png) and stb_rect_pack.h (for more efficient packing)

At the moment there are two shader files that need to be visible to the executable. These will probably be inlined in the near future.

console.ttf is hardcoded at the moment, so that will also have to be available in the current working directory when running.

The example code uses GLFW and GLAD, but those should not be required, as long as opengl symbols are loaded properly.

TODO

  • ADd functionality to adjust the bitmap texture size based on the font size. currently it's using a hard-coded texture that we hope will fit (and is proably too big). Might not even care, since it doesn't really impact performance...

  • Look into padding in the bitmap

Screenshot:

screenshot

Font bitmap

font

Similar Resources

Stock exchange simulator made in Swing using Java with logic backend in C++ giving it faster load time and better data control

StockSimulator Stock exchange simulator made in Swing using Java with logic backend in C++ giving it faster load time and better data control Features

Mar 1, 2022

Load bitstream to AG1K series FPGA using CH552

Load bitstream to AG1K series FPGA using CH552

ch552-ag1k-msd Load bitstream to AG1K series FPGA using CH552 AG1K does not have a built-in data flash; This design only simulate a USB mass storage d

Dec 14, 2022

Several GX2 test programs to compare it with OpenGL. (With additional GLFW+OpenGL implementation provided)

GX2-Tests Provided are GX2 test programs and samples for comparison with OpenGL and with additional GLFW+OpenGL implementation for test on PC. These s

Nov 15, 2021

An efficient texture-free GLSL procedural noise library

Wombat An efficient texture-free GLSL procedural noise library Source: https://github.com/BrianSharpe/Wombat Derived from: https://github.com/BrianSha

Dec 18, 2022

Super Simple Scene Renderer

Super Simple Scene Renderer

SSSR Super Simple Scene Renderer Feature Rendering path Forward rendering Deferred rendering Physically based rendering GGX Image based lighting Equir

Dec 9, 2021

A font cooking library

Font Chef Font Chef is a cross-platform C99 and C++ library to create character atlas of pre-rasterized glyphs from a font at a specified size and col

Apr 25, 2022

Fast single source file BC7/BPTC texture encoder with perceptual metric support

Note: Since this repo was created, we've released two new codecs with better BC7 encoders: https://github.com/richgel999/bc7enc_rdo https://github.com

Nov 23, 2022

Builds atlas texture from a bunch of input images.

Builds atlas texture from a bunch of input images.

Atlasc @septag atlasc is a command-line program that builds atlas texture from a bunch of input images. Main Features Cross-platform. Runs on linux/ma

Aug 30, 2022
A terminal-based, mouse-driven BDF (bitmap) font editor.
A terminal-based, mouse-driven BDF (bitmap) font editor.

bdfedit A terminal-based, mouse-driven BDF font editor. Capable of reading, writing, and editing bitmap font files fully within the terminal, and enti

Dec 24, 2022
cross-platform bitmap font implementation

Component for rendering text with bitmap font on all openfl targets. This set of classes is heavily based on classes from pixelizer (https://github.co

Oct 26, 2021
OpenGL Template Engine - a C++ OpenGL graphics engine which aimed to be a simple startup template for 3D OpenGL projects.
OpenGL Template Engine - a C++ OpenGL graphics engine which aimed to be a simple startup template for 3D OpenGL projects.

OpenGL Template Engine is a C++ OpenGL graphics engine which aimed to be a simple startup template for 3D OpenGL projects. This is the template I personally use for my own projects and provides me with the general OpenGL 3D render setup with model import and UI.

May 16, 2022
A family of small, fast, and simple bitmap fonts in single-file C headers
A family of small, fast, and simple bitmap fonts in single-file C headers

Blit A family of small, fast, and simple bitmap fonts in single-file C headers [go to repository] These are not intended as a replacement for fancy us

Dec 22, 2022
An implementation of a weak handle interface to a packed vector in C++

Experimental handle container in C++ Overview Following on from c-handle-container, this library builds on the same ideas but supports a dynamic numbe

Nov 26, 2022
Risc-V RV32IMAFC + 80s ERA SoC (bitmap + GPU, sprites, tilemaps)
Risc-V RV32IMAFC + 80s ERA SoC (bitmap + GPU, sprites, tilemaps)

A simple (no interrupts or exceptions/traps), Risc-V RV32IMAFC CPU, with a pseudo SMT (dual thread) capability. The display is similar to the 8-bit era machines, along with audio, SDCARD read support, UART and PS/2 keyboard input.

Jun 3, 2022
Automatically load dlls into any executables without replacing any files!

Automatically loaded dll using xinput9_1_0 proxy. Please put the modified xinput9_1_0.dll in the executable's directory.

Dec 24, 2022
Stack-based texture generation tool written in C99!
Stack-based texture generation tool written in C99!

Stack-based texture generation tool written in C99! Brought to you by @zaklaus and contributors Introduction zpl.texed is a cross-platform stack-based

Dec 20, 2022
Texture Packer for Game Development Using MaxRects Algorithm
Texture Packer for Game Development Using MaxRects Algorithm

Overview Texture Packer for Game Development Using MaxRects Algorithm. Note: The game assets used in this example were download from Grassland Tileset

Dec 8, 2022
Control Heidelberg Wallbox Energy Control over WiFi using ESP8266 and configure your own local load management
Control Heidelberg Wallbox Energy Control over WiFi using ESP8266 and configure your own local load management

< scroll down for English version and additional information > wbec WLAN-Anbindung der Heidelberg WallBox Energy Control ├╝ber ESP8266 Die Heidelberg W

Jan 3, 2023