How to use shaders to draw Texts using buffers?

Hi all,

I am beginner in OpenGl and JOGL and I need your help :slight_smile:

I have to draw elements on a 2D map, each element has a specific shape (depending on properties) and a text above ( it can be its Id or a valuable information ). I succeeded to draw the shapes using 3 shaders ( vertex, geometry and fragment ) but didn’t find how to draw the Text above the Shape.

I found a way to draw it using a TextRendering but it doesn’t meet with the specification that requires that the process must be done by GPU and not CPU.

Can you help me on that ? is there a path to follow to learn how to do with JOGL ?

Best regards,
Akrem

It’s quite involved… you’ll need a bitmap font, rasterised into a texture. Then you essentially draw text as a series of quads, like sprites. It’s easier to start with a non-proportional font as then you won’t have to worry about kerning pairs, advancement, line spacing, etc, etc.

There’s a font tool called Hiero which Libgdx makes use of which will do the rasterising for you:

Cas :slight_smile:

1 Like

Thanks for your response.
Do you have a code as example ?

I am looking for something like the following in JOGL

This is old code now, and I haven’t been working on this for 4 years now, but I think you can take a look at it no matter the age.

1 Like

paging @gouessej

@philfrei Thank you. There’s a build-in shader-based text renderer in JOGL, please look at the package com.jogamp.graph.curve and com.jogamp.graph.geom.

If you don’t mind using something less efficient but easier to use, try com.jogamp.opengl.util.awt.TextRenderer.

Please note that many engines have their own means to render text.

1 Like