Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
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  
  How to draw directly to Canvas3D  (Read 1143 times)
0 Members and 1 Guest are viewing this topic.
Offline chumDS

Senior Newbie





« Posted 2007-04-28 22:34:35 »

I want to draw text to my screen, AFTER the rendering is done.

I see that Canvas3D inherits from awt.Canvas, so I thought maybe I'd override paint(), postRender() or postSwap(), but none of those seemed to do what I want.

"Back in the day", when I was using JOGL, I'd complete my render, then go into glOrtho2D mode, then draw text onto the screen there, then do my GL-swap.  I'm ok with doing that in J3D, except I don't know how to interrupt the pipeline to do that.

Or I can just draw on the cavas, if there's a way to do that.

What I was trying that didn't work:

1  
2  
3  
4  
5  
6  
7  
   public   void   paint (Graphics gr)
   {
      super.paint (gr);

      gr.setColor (Color.white);
      gr.drawString ("Foo", 50, 50);
   }


(Tried similar things with postRender() & postSwap(), too -- except I had to call getGraphics().)

No text shows up on my screen.

Help?  Hints?  Snippets?

Thanks!

Now, with even MORE Java!
Offline chumDS

Senior Newbie





« Reply #1 - Posted 2007-04-28 23:29:57 »

To follow up, I found A way (Google!), but it's sub-optimal.  Basically, I've got:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
(My canvas class...)
   private      J3DGraphics2D   j3dgr   = null;

   public   void   postRender ()
   {
//*      super.postRender ();
     drawText();
   }


    private void drawText()
   {
      if (j3dgr == null)
         j3dgr = getGraphics2D();

      j3dgr.setColor(Color.WHITE);
      j3dgr.drawString ("foo", 10, 10);
      j3dgr.flush (true);
    }


Which works display-wise, but completely destroys my frame-rate.  (The slow part seems to be the flush().)

So my new & improved question is: how do I do this in a reasonable amount of time?

Now, with even MORE Java!
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #2 - Posted 2007-05-08 09:56:40 »

I don't have a good answer. Just that creating 2D overlays with Java3D is difficult. The postRender approach is know to destroy performance. So the only way seems to be to do the 2D stuff in 3D as well.

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (143 views)
2013-05-17 21:29:12

alaslipknot (151 views)
2013-05-16 21:24:48

gouessej (182 views)
2013-05-16 00:53:38

gouessej (175 views)
2013-05-16 00:17:58

theagentd (186 views)
2013-05-15 15:01:13

theagentd (171 views)
2013-05-15 15:00:54

StreetDoggy (214 views)
2013-05-14 15:56:26

kutucuk (239 views)
2013-05-12 17:10:36

kutucuk (237 views)
2013-05-12 15:36:09

UnluckyDevil (243 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.099 seconds with 21 queries.