Login  Register

Re: GlEventListener initialization

Posted by John No on Jun 16, 2014; 2:04pm
URL: https://forum.jogamp.org/GlEventListener-initialization-tp4032434p4032439.html

Sorry, i thought it might be a basic concept issue on my side (therefore no code in the first post).

I built a quick testcase showing my issue:

package misc.canvastest;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.jogamp.opengl.util.FPSAnimator;

public class App extends JFrame implements GLEventListener, ActionListener {
	private static final long serialVersionUID = 1895794130238960411L;
	boolean formShow;
	JPanel form;
	FPSAnimator animator;
	
	int clickCount;

	public static void main(String[] args) {
		new App();
	}

	public App() {
		this.setSize(400, 300);

		JButton toggleButton = new JButton();
		toggleButton.setSize(100, 30);
		toggleButton.addActionListener(this);

		form = new JPanel();
		form.setSize(160, 90);

		GLCanvas canvas = new GLCanvas();
		canvas.setSize(160, 90);
		canvas.addGLEventListener(this);

		animator = new FPSAnimator(canvas, 20, true);
		animator.start();

		this.add(toggleButton);
		this.add(form);
		form.add(canvas);

		formShow = true;
		clickCount = 1;
		this.setVisible(true);
	}

	public void init(GLAutoDrawable drawable) {
		System.out.println("init");
	}

	public void dispose(GLAutoDrawable drawable) {
		System.out.println("dispose");
	}

	public void display(GLAutoDrawable drawable) {
		System.out.println("display");
	}

	public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
		System.out.println("reshape");
	}

	public void actionPerformed(ActionEvent e) {
		if (formShow) {
			System.out.println("remove Form - click " + clickCount);
			formShow = false;
			clickCount++;
			this.remove(form);

		} else {
			System.out.println("add Form - click " + clickCount);
			formShow = true;
			clickCount++;
			this.add(form);
		}
	}
}

The debug output for 4 button clicks in this program is:
init
reshape
display
display
...
display
display
remove Form - click 1
dispose
add Form - click 2
remove Form - click 3
add Form - click 4
init
reshape
display
display
...

I would expect to get init, reshape and the display loop again after click 2.

I uploaded the maven project for quick testing:
http://www.filedropper.com/canvastest 

EDIT: My Jogl version is 2.1.5-01 and i'm running Java 1.7.0_51

Cheers,
John