Login  Register

flickering with NewtCanvasAWT when resizing

Posted by CharlesHuet on Dec 20, 2018; 1:20pm
URL: https://forum.jogamp.org/flickering-with-NewtCanvasAWT-when-resizing-tp4039323.html

Hi,

I cannot seem to find any bug tracker where I can post this, so I'll put this here.

I am having an issue with NewtCanvasAWT when resizing, the whole rendering flickers at each resize (happens on Linux and Windows).

Here is a simple reproducer that demonstrates the issue:

import static com.jogamp.opengl.GL2ES3.GL_COLOR;

import java.awt.BorderLayout;
import java.nio.FloatBuffer;

import javax.swing.JFrame;
import javax.swing.JPanel;

import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.GL4;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.util.GLBuffers;

public class NewtTest extends NewtCanvasAWT implements GLEventListener
{
  private static final long serialVersionUID = 1667724932451812449L;

  protected GLWindow m_glWindow;

  public static void main(String[] args)
  {
    JFrame mainFrame = new JFrame("Newt test");

    JPanel panel = new JPanel(new BorderLayout());
    mainFrame.add(panel);

    GLProfile profile = GLProfile.getDefault();

    final GLCapabilities glCapabilities = new GLCapabilities(profile);
    glCapabilities.setBackgroundOpaque(false);
    glCapabilities.setDoubleBuffered(true);
    glCapabilities.setHardwareAccelerated(true);
    glCapabilities.setStereo(false);
    glCapabilities.setDepthBits(24);
    glCapabilities.setStencilBits(8);
    glCapabilities.setSampleBuffers(false);
    glCapabilities.setNumSamples(0);
    glCapabilities.setAlphaBits(8);

    GLWindow m_glWindow = GLWindow.create(glCapabilities);

    panel.add(new NewtTest(m_glWindow));

    mainFrame.pack();
    mainFrame.setVisible(true);
  }

  private NewtTest(GLWindow window)
  {
    super(window);
    window.addGLEventListener(this);
  }

  @Override
  public void init(GLAutoDrawable drawable)
  {}

  @Override
  public void dispose(GLAutoDrawable drawable)
  {}

  @Override
  public void display(GLAutoDrawable drawable)
  {
    GL4 gl = drawable.getGL().getGL4();
    FloatBuffer clearColor = GLBuffers.newDirectFloatBuffer(4);
    gl.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1f).put(1, .5f).put(2, 0f).put(3, 1f));
  }

  @Override
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
  {}
}