Generating a border around characters

I’m trying to generate a border around typed characters. Something that looks like this:

I can’t seem to come up with a solution that performs quickly enough.

How would you do this in OpenGL? The border needs to be regenerated every frame and it would be nice if the border size could be set by the user.

I keep thinking there should be a way to pull it off with a fragment shader, but I haven’t managed it yet.

Any ideas?

Thanks guys.

You could dilate with a fragment shader, it would be similar to a convolution kernel with the character in a texture and the shader performing multiple taps in all directions to test for a hit against the glyph, the displacement of the texture tap could be variable under user control and be clamped to the glyph bounds so you don’t hit other glyphs in the image. You could also draw the character displaced up down left right etc in the border color then finally draw it in the fill color in the middle, primitive but effective.

There are other ways using geometry but it depends on how your glyphs are represented in memory in the first place.