what is a common way to render UI elements (rects with background color) and text?

Started by
2 comments, last by NightCreature83 1 year, 4 months ago

I mean, should I use the same shader for both and set isText bool to true when I want to render text or should I simply use different shaders. Please help!

Advertisement

I use a different shader. In my GUI I have a few different shaders:

  • Border/background - draws an antialiased circle, or rounded rectangle with a border, depending on the UVs you pass in. This shader also applies dithering for gradients.
  • Text - draws fonts using alpha texture atlas for all glyphs. This shader does super sampling of the alpha channel to reduce aliasing with small font sizes.
  • Circle/line - similar to border/background, but just draws a solid antialiased circle or rounded line without a border.

As you can see, the needs for the different shaders are pretty different.

There are a couple of ways of doing text you could use:
- Alpha mapped rects for bitmapped fonts, this can be the normal shader you use to render a background as long as it deals with alpha
-SDF fonts, which use dedicated shaders to figure out the outline of the glyph in the pixel shader from vector quantized texture maps for each glyph (https://medium.com/@calebfaith/implementing-msdf-font-in-opengl-ea09a9ab7e00

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

This topic is closed to new replies.

Advertisement