Not understanding the resizing behaviour of JOGL

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Not understanding the resizing behaviour of JOGL

r.jaoui
Hello !

I previously posted this question in the Khronos OpenGL Forum, but apparently it is more of a JOGL question than an OpenGL one, so I'll ask it here.

This isn’t specifically a coding question, but more an attempt at understanding how JOGL manages resizing. Firstly:

Does JOGL display the panel continuously while resizing ?

My first experience is that no, since with the following very simple code, the panel is cleared only when resizing stops (when I stop moving my mouse to resize). I also thought of the glViewport function but apparently running it inside of the reshape override doesn’t change anything, so I guess that the viewport is resized automatically…

Here is my simple resizing code :

Main.java

public class Main {
        public static void main(String[] args) {
                @SuppressWarnings("unused")
                Frame frame = new Frame(1280, 720);
        }
}


Frame.java

import javax.swing.JFrame;

import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLJPanel;

public class Frame extends JFrame{
       
        public static GLProfile PROFILE;
        public static GLCapabilities CAPABILITIES;
        public static GLJPanel panel;
        public static PanelListener listener;
       
        public Frame(int width, int height) {
                super();

                PROFILE = GLProfile.get(GLProfile.GL2);
                CAPABILITIES = new GLCapabilities(PROFILE);
               
                CAPABILITIES.setSampleBuffers(true);
                CAPABILITIES.setNumSamples(8);
                CAPABILITIES.setStencilBits(8);
                CAPABILITIES.setDoubleBuffered(true);
                CAPABILITIES.setPBuffer(true);
               
                panel = new GLJPanel(CAPABILITIES);
                listener = new PanelListener(panel);
                panel.addGLEventListener(listener);
               
                this.setContentPane(panel);
               
                this.setVisible(true);
                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                this.setSize(width, height);
               
                run();
        }
       
        public void run() {
                while(true) {
                       
                        panel.display();
                       
                        try {Thread.sleep(1);}
                        catch (InterruptedException e) {e.printStackTrace();}
                }
        }
}


PanelListener.java

import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.awt.GLJPanel;

public class PanelListener implements GLEventListener{
       
        GLJPanel panel;
        GL2 gl;
       
        public PanelListener(GLJPanel panel) {
                super();
                this.panel = panel;
        }

        @Override
        public void display(GLAutoDrawable displayable) {
                gl.glClearColor(1f, 1f, 1f, 1f);
                gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
        }

        @Override
        public void dispose(GLAutoDrawable displayable) {}

        @Override
        public void init(GLAutoDrawable displayable) {
                gl = displayable.getGL().getGL2();
       
                gl.glEnable(GL2.GL_LINE_SMOOTH);
                gl.glEnable(GL2.GL_POINT_SMOOTH);
                gl.glEnable(GL2.GL_SMOOTH);
       
                gl.glDrawBuffer(GL.GL_FRONT_AND_BACK);
                gl.glEnable(GL.GL_MULTISAMPLE);
       
                gl.glHint(GL2.GL_LINE_SMOOTH_HINT, GL2.GL_FASTEST);
                gl.glHint(GL2.GL_POINT_SMOOTH_HINT, GL2.GL_NICEST);
               
                gl.glShadeModel(GL2.GL_SMOOTH);
               
                gl.glEnable(GL2.GL_BLEND);
                gl.glBlendFuncSeparate(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA, GL2.GL_ONE, GL2.GL_ONE);
       
                gl.glEnable(GL2.GL_TEXTURE_2D);
       
                gl.glClearColor(0.3f, 0.3f, 0.3f, 1f);
                gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);
        }

        @Override
        public void reshape(GLAutoDrawable displayable, int x, int y, int w, int h) {}
}



My issue now comes from the following realization : if I then manually resize the panel to be really small (my experimentations seem to yield a size a bit larger than 130x88 pixels), after this point EVERY TIME I resize the panel (not just this time) it seems to be resized continuously, although if the panel is then set to the exact same size as before, exactly the same code is ran, but the behaviour is still different. My second question is therefore :

Is there anything that is done if the panel is reshaped to a sufficiently small size that may cause this shift to happen ?

If so, is there a way to force this behaviour from the start/to block it from happening in the future ?


My main need was to actually have the panel displayed continuously through resizing, but calling panel.display() while redrawing seems to result in a call to GLEventListener.display() that is able to render to the panel only if not currently resizing, and if the panel hasnt been resized to the small size mentionned before… Which doesn’t make sense to me.

Thanks for your help !