Author Topic: Drawing with AWT over 3D Render?  (Read 2325 times)

Offline ForOhFor Error

  • byte
  • *
  • Posts: 10
    • View Profile
Drawing with AWT over 3D Render?
« on: May 08, 2013, 12:42:04 am »
Hey, I'm a bit of a noobie around here, but I'm trying to learn. That said, here's my trouble:

This code fails to draw a square into the corner of the JFrame I'm using (a proof of concept - If I can draw a square, I can draw an image as well):
Code: [Select]
while (frame.isShowing()) {
buffer.clear(java.awt.Color.BLUE);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
Graphics g = buffer.getGraphics();

g.fillRect(0, 0, 10, 10);

buffer.displayGLOnly();
canvas.repaint();
Thread.sleep(10);
}

Is there something I'm missing?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Drawing with AWT over 3D Render?
« Reply #1 on: May 08, 2013, 07:49:41 am »
You are using the AWTGLRenderer for this?

Offline ForOhFor Error

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Drawing with AWT over 3D Render?
« Reply #2 on: May 08, 2013, 12:20:41 pm »
Yes, I am.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Drawing with AWT over 3D Render?
« Reply #3 on: May 08, 2013, 01:31:53 pm »
I don't think that you can paint over the gl canvas in a reliable way. However, if you can, the way you are doing it is wrong. Painting in AWT/Swing happens in the awt event dispatch thread and so does rendering of the scene when using the AWTGLRenderer. Try to implement an IPaintListener and do your painting in the finishedPainting()-method. But as mentioned, i'm not sure that this combination will work...

Offline ForOhFor Error

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Drawing with AWT over 3D Render?
« Reply #4 on: May 08, 2013, 09:33:15 pm »
Right, so what would be some reasonable alternatives? I'd rather not use a 2D plane in front of the camera and constantly blit the Texture, if at all possible.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Drawing with AWT over 3D Render?
« Reply #5 on: May 08, 2013, 11:32:35 pm »
What's wrong with blitting a texture instead. It will be faster anyway and more compatible.

Offline ForOhFor Error

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Drawing with AWT over 3D Render?
« Reply #6 on: May 09, 2013, 12:23:23 pm »
Okay, is there a good example for that somewhere? Like I said, I'm still learning.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Drawing with AWT over 3D Render?
« Reply #7 on: May 09, 2013, 10:03:49 pm »
Depends on what you want to draw exactly. The basic idea is to load a texture and simply blit it by using one of the blit-methods in FrameBuffer. It's pretty straight forward.