Re: Clear status about GLCanvas without animator
Posted by Cyrille on Nov 19, 2010; 3:30pm
URL: https://forum.jogamp.org/Clear-status-about-GLCanvas-without-animator-tp1930475p1931149.html
I tried to call display() explicitly but it doesn't work.
In the sample application below, the canvas appears yellow at startup (its background color) while I expect it to be red (OpenGL clear color). If I call display() everytime the canvas is resized, the canvas flickers between yellow and red during the resize operation and randomly ends yellow or red.
package GLSLTest;
import java.awt.Color;
import java.awt.Component;
import java.awt.Frame;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.BoxLayout;
public class Main
{
static CanvasListener listener = new CanvasListener();
public static void main(String[] args)
{
GLProfile.initSingleton();
GLProfile profile = GLProfile.getMaxFixedFunc();
GLCapabilities caps = new GLCapabilities(profile);
GLCanvas canvas = new GLCanvas(caps);
canvas.setBackground(Color.yellow);
canvas.addGLEventListener(listener);
Frame topLevelFrame = new Frame();
topLevelFrame.setLayout(new BoxLayout(topLevelFrame, BoxLayout.Y_AXIS));
topLevelFrame.add(canvas);
topLevelFrame.setSize(400, 300);
topLevelFrame.setVisible(true);
// Animator animator = new Animator(canvas);
// animator.start();
canvas.display();
}
}
class CanvasListener implements GLEventListener
{
@Override
public void display(GLAutoDrawable arg0)
{
GL2 gl = arg0.getGL().getGL2();
gl.glClearColor(1.0f, 0.0f, 0.0f, 0.5f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
System.out.println("display");
}
@Override
public void dispose(GLAutoDrawable arg0)
{
}
@Override
public void init(GLAutoDrawable arg0)
{
Component canvas = (Component) arg0;
System.out.println(canvas.getSize().toString());
}
@Override
public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4)
{
}
}