Drawing with AWT over 3D Render?

Started by ForOhFor Error, May 08, 2013, 12:42:04 AM

Previous topic - Next topic

ForOhFor Error

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):
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?

EgonOlsen

You are using the AWTGLRenderer for this?


EgonOlsen

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...

ForOhFor Error

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.

EgonOlsen

What's wrong with blitting a texture instead. It will be faster anyway and more compatible.

ForOhFor Error

Okay, is there a good example for that somewhere? Like I said, I'm still learning.

EgonOlsen

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.