TextRenderer - outline on fonts?

I’ve only just started playing around with TextRenderer, but the first thing I realised is that whatever text colour I’m going to use, my moving scene can make the text hard to read. So I’m thinking I have a few options:

  1. Render into 3D space onto an approprialy coloured rectangle. - probably the simplest but not very pretty, and prob won’t work for 2D HUD.
  2. Render character by character twice, one slightly larger to give an outline to each character. - probably slow and only approx outline
  3. Create a RenderDelegate and draw and draw an outline or background here. - looks tricky

Has anyone had a go at outlined fonts? or can suggest a better technique for putting text over a multicoured scene? I have a couple of requirements here, one for HUD type 2D output and another for in scene 3D rendering (possibly billboarding). I’ve been trying with glutBitmapString so far, but not really happy with the result.

Is it worth trying to extend the TextRenderer class itself to support this? I guess the Sun guys are busy elsewhere these days, so is anyone else here able to help with that?

Cheers

Peter

update: seems like renderer.setColor has no affect anyway so I need to investigate that first

Regarding RenderDelegate, have you already looked into the sources of the custom text demo?
https://jogl-demos.dev.java.net/

AFAIR there is a Java2d sample somewhere in the jdk sample package which does outlined font rendering.

That’s why I thought it might be tricky (seeing the demo code) I haven’t done and Java2D or font stuff before…

I’ve tried shoe-horning the code below into the CustomText demo and I get some interesting chopped segments of random outlined characters :slight_smile: Before I waste another few hours, is this a good example to have started with?

http://www.java2s.com/Code/Java/2D-Graphics-GUI/OutlineFontpaint.htm

yea, should work, just replace drawGlyphVector with the snippet below.


      public void drawGlyphVector(Graphics2D g2, GlyphVector str, int x, int y) {
          g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                  RenderingHints.VALUE_ANTIALIAS_ON);

          g2.setRenderingHint(RenderingHints.KEY_RENDERING,
                  RenderingHints.VALUE_RENDER_QUALITY);

          g2.setColor(Color.blue);
          g2.drawGlyphVector(str, x, y);

          Shape outline = str.getOutline(x,y);

          g2.setColor(Color.white);
          g2.draw(outline);
      }

Great! thanks for the help, my hacked code was already 3x the size of that and still not working. It looks so simple now I see it :slight_smile:

PS Any ideas why the setColor statements might be being ignored, I get two different colours, but I think they are being picked up from something else in my scene…