Skip to main content
gamedev.net
🔒 Locked

[java] 2D drawing with Java3D

Started by mtfr 2 replies 1.2k views
Original Post
mtfr
mtfr
Hello. Is there any possibility to use 2D drawing (text and primitives like line, rectangle) in a Java3D window? Just like the HUD in games. But without using bitmaps in the 3D space oriented towards the user...
Vyper_uk
Vyper_uk
Indeed there is. What you have to do is create a class that extends Canvas3D and use that instead of the default Canvas3D class. Once you have done that you can override various methods, with the one you want in this case being postRender(). This gets called every frame after everything else in the scene has been rendered.

For example:

      public MyCanvas3D(GraphicsConfiguration gcfg) {        super(gcfg,false);    }    public void postRender() {      if (g2 == null) {        g2 = this.getGraphics2D();        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,                RenderingHints.VALUE_ANTIALIAS_ON);      }      drawStuff(g2);      g2.flush(true);    }
mtfr
mtfr
Thanks for the answer. I didn't get to try it yet but I'll post again when I do, about the outcome.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.