Login  Register

Re: Resize of a JCanvas3D

Posted by Andreas on Jan 22, 2013; 12:43pm
URL: https://forum.jogamp.org/Resize-of-a-JCanvas3D-tp4027842p4027976.html

After I found the Beans/desginTime problem, I was able to look if other had this problem. And there were some.

http://netbeans.org/bugzilla/show_bug.cgi?id=139304
http://kenai.com/nonav/projects/netbeans-opengl-pack/forums/forum/topics/2025-Problem-closing-the-OpenGL-Capabilities-Viewer-

So I'm not sure if this is a bug or just two points of view.

Additionally the Beans/desginTime problem is not connected to my original resizing problem of the JCanvas3D inside the a Netbeans Platform Application with different TopComponents.

A simple example is what happens when the GLCanvas is used inside Netbeans is the following where Beans/desginTime is set true:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jrealitytest;

import com.jogamp.opengl.util.Animator;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.Beans;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL2ES1;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.fixedfunc.GLLightingFunc;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
import javax.swing.JFrame;

public class JOGLQuad implements GLEventListener {

    private float rotateT = 0.0f;

    @Override
    public void display(GLAutoDrawable gLDrawable) {
        final GL2 gl = gLDrawable.getGL().getGL2();
        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
        gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
        gl.glLoadIdentity();
        gl.glTranslatef(0.0f, 0.0f, -5.0f);

        // rotate on the three axis
        gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
        gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
        gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);

        // Draw A Quad
        gl.glBegin(GL2.GL_QUADS);
        gl.glColor3f(0.0f, 1.0f, 1.0f);   // set the color of the quad
        gl.glVertex3f(-1.0f, 1.0f, 0.0f);   // Top Left
        gl.glVertex3f(1.0f, 1.0f, 0.0f);   // Top Right
        gl.glVertex3f(1.0f, -1.0f, 0.0f);   // Bottom Right
        gl.glVertex3f(-1.0f, -1.0f, 0.0f);   // Bottom Left
        // Done Drawing The Quad
        gl.glEnd();

        // increasing rotation for the next iteration                  
        rotateT += 0.2f;
    }

    @Override
    public void init(GLAutoDrawable glDrawable) {
        GL2 gl = glDrawable.getGL().getGL2();
        gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.glClearDepth(1.0f);
        gl.glEnable(GL.GL_DEPTH_TEST);
        gl.glDepthFunc(GL.GL_LEQUAL);
        gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
    }

    @Override
    public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {
        GL2 gl = gLDrawable.getGL().getGL2();
        final float aspect = (float) width / (float) height;
        gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
        gl.glLoadIdentity();
        final float fh = 0.5f;
        final float fw = fh * aspect;
        gl.glFrustumf(-fw, fw, -fh, fh, 1.0f, 1000.0f);
        gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
        gl.glLoadIdentity();
    }

    @Override
    public void dispose(GLAutoDrawable gLDrawable) {
    }

    public static void main(String[] args) {
        Beans.setDesignTime(true);
        final GLCanvas canvas = new GLCanvas();
        final JFrame frame = new JFrame("Jogl Quad drawing");
        final Animator animator = new Animator(canvas);
        canvas.addGLEventListener(new JOGLQuad());
        frame.add(canvas);
        frame.setSize(640, 480);
        frame.setResizable(false);
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                animator.stop();
                frame.dispose();
                System.exit(0);
            }
        });
        frame.setVisible(true);
        animator.start();
        canvas.requestFocus();
    }
}