Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Java3D - On Screen Text - HUD - Simple 2D Text?  (Read 5842 times)
0 Members and 1 Guest are viewing this topic.
Offline Ben_3D

Junior Newbie





« Posted 2006-05-06 21:09:07 »

Hi all,
  I'm new to java 3d, and am wondering how I go about putting some simple text on screen...I've been reading around and have tried Text3D and Text2D, but they seem to be releative to the 3d world...and my camera is moving around so the text isn't really 2d on screen text.

My simple 3d class extends the JFrame, and wanted to know if there was any examples of using java3d and putting some 2d text on screen...like a counter or something.

Thanks,

Ben

Quote
class MainWindow extends JFrame implements KeyListener
{
..
Offline Jamison

Junior Member




We're all idiots in one way or another.


« Reply #1 - Posted 2006-05-06 22:05:54 »

I have been trying to figure this same thing out for about a day now. And after realizing that javax.media.j3d.Canvas3D extends java.awt.Canvas and java.awt.Canvas exends java.awt.Component, you can simply call the getGraphics() method, like this:
Quote
Canvas3D canvas = new Canvas3D(config);
Graphics g = canvas.getGraphics();
Then use the traditional drawing methods of java.awt.Graphics to draw directly to the Canvas3D.

I don't like you. Check out my site Smiley www.gamedevforums.com
Offline Ben_3D

Junior Newbie





« Reply #2 - Posted 2006-05-06 23:52:46 »

Hi Jamison,
  well thanks for your idea...I tried this:

1  
2  
3  
Graphics g = canvas.getGraphics();
g.setFont(new Font("TimesRoman", Font.ITALIC, 28));
g.drawString("abcdefeghijklmonopdkdkdkd",80, 80);


But what I find is, no matter how I do it, I always seem to get a flicker...never seems like a smooth on screen text....its like every few frames it flickers or something...any ideas on how to fix this?

Thanks,

Ben

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jamison

Junior Member




We're all idiots in one way or another.


« Reply #3 - Posted 2006-05-07 00:14:00 »

I don't have any problems. Perhaps your doing something wrong? Here's some sample code:
Quote
import java.awt.*;
import javax.swing.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.universe.*;

public class Test extends JFrame implements Runnable {
   int fps = 30;
   Graphics screen;

   public Test() {
      setSize(400, 300);
      setResizable(false);
      setDefaultCloseOperation(EXIT_ON_CLOSE);

      GraphicsConfiguration gc = SimpleUniverse.getPreferredConfiguration();
      Canvas3D canvas = new Canvas3D(gc);
      getContentPane().add(canvas);

      BranchGroup scene = new BranchGroup();
      scene.compile();

      SimpleUniverse su = new SimpleUniverse(canvas);
      su.addBranchGraph(scene);

      setVisible(true);

      screen = canvas.getGraphics();

      new Thread(this).start();
   }

   public void run() {
      while(true) {
         try {
            screen.setColor(Color.white);
            screen.setFont(new Font("TimesRoman", Font.ITALIC, 28));
            screen.drawString("abcdefeghijklmonopdkdkdkd",80, 80);

            Thread.currentThread().sleep(1000/fps);
         } catch(InterruptedException e){}
      }
   }

   public static void main(String args[]) {
      new Test();
   }
}

I don't like you. Check out my site Smiley www.gamedevforums.com
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #4 - Posted 2006-05-08 09:56:59 »

I'm sorry, but that source doesn't look like a particularly good solution.

The 2D rendering is not synchronized with the 3D rendering at all.

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Jamison

Junior Member




We're all idiots in one way or another.


« Reply #5 - Posted 2006-05-08 14:20:42 »

You know what? I'm a beginner to J3D too. I was only giving him source code that worked for me from what I found myself by looking through the documentation.

I don't like you. Check out my site Smiley www.gamedevforums.com
Offline Breakfast

Senior Member




for great justice!


« Reply #6 - Posted 2006-05-09 17:55:50 »

Here are a couple of relevant threads:
Dynamic Textures for UI followed by Best Approach to UI Panes also HUD on top of Canvas3D.
Offline Mr. Gol

Senior Member


Medals: 1



« Reply #7 - Posted 2006-05-10 11:30:02 »

Something like this. You have to override Canvas3D.postRender() to make sure the HUD is drawn everytime a frame is rendered. This is supposed to be quite slow, but since drawAndFlushImage was introduced it works good enough.

Quote

public class Viewport extends Canvas3D {

   private Dimension resolution;      
   private BufferedImage buffer;
   private Graphics2D g2;
   private J3DGraphics2D g3;
   
   public Viewport(GraphicsDevice gd,Dimension resolution) {
      
      super(gd.getBestConfiguration(new GraphicsConfigTemplate3D()));
      
      this.resolution=resolution;
      
      buffer=new BufferedImage(resolution.width,resolution.height,BufferedImage.TYPE_4BYTE_ABGR);
      g2=buffer.createGraphics();
      g3=this.getGraphics2D();
      
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
      g2.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
   }   

   public void postRender() {
      
      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR,0f));
      g2.setColor(new Color(0,0,0));
      g2.fillRect(0,0,resolution.width,resolution.height);
      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1f));
         
      hud.renderFrame(g2,resolution.width,resolution.height);
         
      g3.drawAndFlushImage(buffer,0,0,this);   
   }
}

public class HUD {

   (...)

   public void renderFrame(Graphics2D g2,int width,int height) {

      // Drawing code goes here
   }
}


Online kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #8 - Posted 2006-05-10 16:22:50 »

Been a while since I worked with Java 3D, but using postRender() used to have an awful performance impact - anyone know if this is still the case.

We used to end up aligning quads with the screen and using dynamic textures for optimum performance.

Kev

Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #9 - Posted 2006-05-11 13:06:39 »

Hi

It's probably suffered a bit of bit rot by now, but there is a HUD system for Java 3D and a demo application on the newdawn software site here.

HTH

Endolf

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #10 - Posted 2006-10-03 04:41:18 »

Quote
Been a while since I worked with Java 3D, but using postRender() used to have an awful performance impact - anyone know if this is still the case.

Well as of J3D1.4.0_01 the performance is still bad (I am going through the pains of having to convert over to a new hud b/c of it).  By using JProfiler I discovered that postRender was taking up 68% of all computation time.  Thats horrible for just displaying hud stuff. 

Well, I think I'm gonna try and use the HUD stuff from j3d.org.

Ubuntu
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #11 - Posted 2006-10-04 05:21:18 »

Hey.
   So I am trying to use the j3d overlay package and I can't seem to get it to work.
This is what I am doing:
* Extended Canvas3D (I was previously using drawAndFlushImage but commented out that code)
* Added ImageOverlay with a BufferedImage.
* Getting Graphics2D from image and drawing to it the HUD Components


So here is what I do when creating Image Overlay in the constructor of Canvas3D
1  
2  
3  
4  
5  
6  
BufferedImage imageBuffer = OverlayUtilities.createBufferedImage(dimension,true);
Graphics2D g2d = imageBuffer.createGraphics();

ImageOverlay imageOverlay = new ImageOverlay(this,dimension,true,true,imageBuffer);
imageOverlay.initialize();
imageOverlay.setVisible(true);


Then in the postRender function
1  
2  
3  
// do update HUD graphics with g2g
updateHUDGraphics(g2g);
imageOverlay.repaint()


Am I doing something wrong?

Ubuntu
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #12 - Posted 2006-10-07 21:17:18 »

Well, I've asked the question over at the java.net forums about methods for rendering HUDS.

A poster replied and mentioned that performance is affected by the size of the image that you call drawAndImageFlush on.

Check it out here

http://forums.java.net/jive/thread.jspa?threadID=18922

Ubuntu
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #13 - Posted 2006-10-12 04:35:45 »

ok, I've just converted over to drawing to seperate images (panes) like described in the above post and I'm getting worse performance.
I'm down to 15FPS instead of 30FPS with the all in one image. 

Any suggsetions?

How about using the PlatformGeometry class to do all 2d drawing.  Is there anything to be aware of when using PlatformGeometry?

Ubuntu
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (13 views)
2014-07-24 01:59:36

Riven (11 views)
2014-07-23 21:16:32

Riven (12 views)
2014-07-23 21:07:15

Riven (13 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!