Advertisement

At a loss as to how to do font rendering in OpenGL

Started by April 11, 2020 06:46 PM
11 comments, last by taby 4 years, 9 months ago

I'm using GLUI for OpenGL GUI stuff. Unfortunately, on Intel and nVidia, I cannot call the GLUT character rendering function, because it causes the GPU to lock up, and my app dies. Works great on AMD though! LOL

Anyway, what would you recommend for a font rendering solution using OpenGL? I've tried about a half-dozen sample apps and libraries, but none seem to work, or even compile.

Is there a small solution that you know of? It's for an open source program, so your source must be open and pretty much in the public domain.

P.S. The app is coming along nicely. The source and precompiled exe can be found at: https://github.com/sjhalayka/julia4d3

Advertisement

To me, the annoying problem of text display magically disappeared since using ImGui. It's also much more flexible to create GUI and really useful for debugging purposes.

I've also used this before: https://www.angelcode.com/products/bmfont/ It's bitmap fonts, (less complexity to write the rendering than integrating something like freetype i guess)

taby said:
Anyway, what would you recommend for a font rendering solution using OpenGL? I've tried about a half-dozen sample apps and libraries, but none seem to work, or even compile.

I was able to build x64 freetype static libs in VS2019 using the vc2010 solution without a problem. Seems that you're using VS2019 as well.

Why are you using GLUT with 4.1 OpenGL?

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

I'm surprised that GLUT and OpenGL 4 co-existed on AMD. Thanks for the tips!

Yeah, Dear Imgui. Comes with examples and documentation. But it only compiles with a bunch of implicit conversion warnings.

Should Imgui be too sophisticated, then there are text rendering tutorials using freetype. It's not too hard to diy text rendering. Load glyphs, bild texture, store offsets, a static buffer for fixed text labels, a dynamic buffer for the flickering variables, a little logic and let there be text …

Advertisement

taby said:
what would you recommend for a font rendering solution using OpenGL?

You can simply rewrite this examples from Java to C++:

I will find the source code in the video description.

Thanks for the pointer.

Nothing worked, and I tried like a half-dozen libraries. What I ended up doing is implementing my own font rendering system on the CPU – I use glReadPixels to capture the screen, then I alter it by rendering text onto it, then I use glDrawPixels to put the text back onto the screen.

I tried the FreeType library but I decided to make font rendering from scratch like on videos above. I made it in the Pong game in C# (OpenGL 2.0 with shaders) and TypeScript (WebGL): https://8observer8.github.io/webgl10-ts/pong2d-from-noobtuts/

I you want to use a library than the most popular is FreeType. This is a tutorial: https://learnopengl.com/In-Practice/Text-Rendering

The learnopengl example just shows the principle. It loads every glyph into a single texture, which becomes unwieldy if not impossible for use with several fonts or different sizes because you'd end up with several hundred textures. Much better and practicable is the example on the freetype2 site.

I have done a finger exercise on text rendering (plain C and opengl 4.5). It loads glyphs of a given font and size into a single texture atlas and stores the offsets for each glyphs. It has a static buffer for labels and a dynamic one for the display of data that changes every frame. You create a font with size, a "window", add static and dynamic elements to it, and call a draw routine every frame. It is here: https://github.com/BaronVerde/VeryVerySimpleGUI. It is fast and primitive, does not have elements like scroll bars, sliders or text input, yet, and it's plain C. One day i'll heave it to C++ and integrate it in my stuff. Of course, my intention is to hear what you say about it ;-)

A much more sophisticated gui render (besides Dear Imgui), and written in plain C, comes with this engine: https://github.com/mrDIMAS/DmitrysEngine.

This topic is closed to new replies.

Advertisement