LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: mac on April 30, 2005, 05:42:04

Title: AWTGLCanvas 2nd round
Post by: mac on April 30, 2005, 05:42:04
Hi,

today i put the AWT Component inside a Swing JPanel.


public class AWTCanvasTest
extends JPanel


AWTCanvas is impl. like this:


 add(canvas0 = new AWTGLCanvas()
 {
long startTime = 0;
long fps = 0;

final public void paintGL()
{
 if (startTime == 0)
 {
setup();
 }

 try
 {
angle += 2.0f;
xRot += xAdd;
yRot += yAdd;
zRot += zAdd;

panexRot += panexAdd;
paneyRot += paneyAdd;
panezRot += panezAdd;

GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);


I setup LWJGL like this:


/**
  * Setup GL
  */
 public synchronized void setup()
 {
// setup ogl
FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[]
{5.0f, 5.0f, 10.0f, 0.0f});
FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[]
{0.8f, 0.1f, 0.0f, 1.0f});
FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[]
{0.0f, 0.8f, 0.2f, 1.0f});
FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[]
{0.2f, 0.2f, 1.0f, 1.0f});
pos.flip();
red.flip();
green.flip();
blue.flip();


GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, pos);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_LIGHT0);
GL11.glEnable(GL11.GL_DEPTH_TEST);

...
...



While lauching it,it first displays correct on AWTGLCanvas,when i remove the JPanel(AWTCanvasTest ) from another component,later i add it again to the same Panel back to bring it visible again i see the only a black screen.

While the AWTGLCanvas is removed from the container,no GL Operation is made until is is added again.

The LWJGL Java Doc say for AWTGLCanvas (http://www.lwjgl.org/javadoc/org/lwjgl/opengl/AWTGLCanvas.html#makeCurrent()l):

QuoteMake the canvas' context current. It is highly recommended that the context is only made current inside the AWT thread (for example in an overridden paint()).

But unfortunately paint is final declared (http://www.lwjgl.org/javadoc/org/lwjgl/opengl/AWTGLCanvas.html#paint(java.awt.Graphics)) on AWTGLCanvas,whats wrong there :?:


Too be inside AWT i overwrote paint on AWTCanvasTest:

 public void paint(Graphics g)
 {
try
{
canvas0.makeCurrent();
}
catch (LWJGLException ex)
{
 ex.printStackTrace();
}
 }


again it looks like a black hole :( anyone can help ?

Stay Tuned,
Jens
Title: AWTGLCanvas 2nd round
Post by: elias on April 30, 2005, 15:37:19
You'll need to overridde paintGL() instead of paint(), and I've corrected the documentation to reflect that. I'm not sure why you get a black screen however by removing/adding the canvas, I'm afraid.

- elias
Title: AWTGLCanvas 2nd round
Post by: mac on April 30, 2005, 16:00:28
Of course i overwrote paintGL() in AWTGLCanvas,but without a malecurrent() call.

- jens
Title: AWTGLCanvas 2nd round
Post by: mac on May 03, 2005, 01:34:49
Insert a makeCurrent() do not solve my problem.
I also  tried a special setup method to reinit the View in the EDT Thread using SwingUtillities.invokeLater(..) with no luck.

Any suggestion ?

Thx,
Jens
Title: AWTGLCanvas 2nd round
Post by: Matzon on May 03, 2005, 05:49:49
so basically, there are issues with removing it or with readding the component?
Could you make a simple test case that shows this error ?