Login  Register

Re: Blank Window - Porting Joe Groff's OpenGL Tutorial to JOGL

Posted by gouessej on Oct 05, 2010; 11:50am
URL: https://forum.jogamp.org/Blank-Window-Porting-Joe-Groff-s-OpenGL-Tutorial-to-JOGL-tp1623993p1635433.html

Add the GLEventListener to the canvas before adding the canvas to the frame; once the canvas is in the frame, call setVisible(true). Please test this (it works on my machine):

package org.maoni.jogl.test;

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;

import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.Animator;


public class JOGLTest {
       
        public static void main(String args[]) {
                GLProfile.initSingleton();
                GLCapabilities caps = new GLCapabilities(null);
                System.out.println("Created JOGL context successfully.");
                GLCanvas canvas = new GLCanvas(caps);
               
                Frame frame = new Frame("AWT Window Test");
                frame.setSize(800, 600);
                //FIXME: not sure that your window listener will be called...
                frame.addWindowListener(new Closer());

                SwingUtilities.invokeLater(new Runnable() {
                       @Override
                       public void run() {
                              canvas.addGLEventListener(new SimpleScene());
                              frame.add(canvas);
                              Animator animator = new FPSAnimator(canvas);
                              animator.start();
                      }
                });
                frame.setVisible(true);
        }
       
        static class Closer extends WindowAdapter {
                public void windowClosing (WindowEvent event) {
                        System.exit(0);
                }
        }
}
Julien Gouesse | Personal blog | Website