Java Code Examples for com.jogamp.opengl.awt.GLCanvas#addKeyListener()

The following examples show how to use com.jogamp.opengl.awt.GLCanvas#addKeyListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Fireworks.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
    // Create the OpenGL rendering canvas
    final GLProfile gp = GLProfile.get(GLProfile.GL2);
    GLCapabilities cap = new GLCapabilities(gp);

    final GLCanvas canvas = new GLCanvas(cap);
    Fireworks renderer = new Fireworks();
    canvas.addGLEventListener(renderer);

    canvas.addKeyListener(renderer);
    canvas.setFocusable(true);  // To receive key event
    canvas.requestFocus();

    // Create a animator that drives canvas' display() at the specified FPS.
    final FPSAnimator animator = new FPSAnimator(canvas, FPS, true);

    // Create the top-level container frame
    final JFrame frame = new JFrame(); // Swing's JFrame or AWT's Frame
    frame.getContentPane().add(canvas);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            // Use a dedicate thread to run the stop() to ensure that the
            // animator stops before program exits.
            new Thread() {
                @Override
                public void run() {
                    animator.stop(); // stop the animator loop
                    System.exit(0);
                }
            }.start();
        }
    });
    frame.setTitle(TITLE);
    frame.pack();
    frame.setSize(640, 480);
    frame.setVisible(true);
    animator.start(); // start the animation loop
}
 
Example 2
Source File: NBodyVisualizer.java    From gpu-nbody with MIT License 4 votes vote down vote up
/**
 * Creates a new JOCLSimpleGL3 sample.
 * 
 * @param capabilities
 *            The GL capabilities
 */
public NBodyVisualizer(final GLCapabilities capabilities) {
	glComponent = new GLCanvas(capabilities);
	glComponent.setFocusable(true);
	glComponent.addGLEventListener(this);

	// Initialize the mouse and keyboard controls
	final MouseControl mouseControl = new MouseControl();
	glComponent.addMouseMotionListener(mouseControl);
	glComponent.addMouseWheelListener(mouseControl);
	final KeyboardControl keyboardControl = new KeyboardControl();
	glComponent.addKeyListener(keyboardControl);

	setFullscreen();

	updateModelviewMatrix();

	// Create and start an animator
	animator = new Animator(glComponent);
	animator.start();

	// Create the simulation
	// simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new SerializedUniverseGenerator("universes/sphericaluniverse1.universe"));
	// simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new SerializedUniverseGenerator("universes/montecarlouniverse1.universe"));

	// simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new RotatingDiskGalaxyGenerator(3.5f, 25, 0));
	simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new RotatingDiskGalaxyGenerator(3.5f, 1, 1));
	// simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new SphericalUniverseGenerator());
	// simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new LonLatSphericalUniverseGenerator());

	// simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new RandomCubicUniverseGenerator(5));
	// simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new MonteCarloSphericalUniverseGenerator());

	// simulation = new GpuNBodySimulation(Mode.GL_INTEROP, 2048 * 8, new LonLatSphericalUniverseGenerator());
	// simulation = new GpuNBodySimulation(Mode.GL_INTEROP, 2048, new PlummerUniverseGenerator());
	// simulation = new GpuNBodySimulation(Mode.GL_INTEROP, 128, new SphericalUniverseGenerator());

	// Create the main frame
	frame = new JFrame("NBody Simulation");
	frame.addWindowListener(new WindowAdapter() {
		@Override
		public void windowClosing(final WindowEvent e) {
			runExit();
		}
	});
	frame.setLayout(new BorderLayout());
	frame.add(glComponent, BorderLayout.CENTER);

	frame.setUndecorated(true);
	frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
	frame.setVisible(true);
	frame.setLocationRelativeTo(null);
	glComponent.requestFocus();

}
 
Example 3
Source File: JCudaDriverSimpleJOGL.java    From jcuda-samples with MIT License 4 votes vote down vote up
/**
 * Creates a new JCudaDriverSimpleJOGL.
 * 
 * @param The JOGL OpenGL capabilities
 */
public JCudaDriverSimpleJOGL(GLCapabilities capabilities)
{
    simpleInteraction = new SimpleInteraction();
    
    // Initialize the GL component and the animator
    GLCanvas glComponent = new GLCanvas(capabilities);
    glComponent.setFocusable(true);
    glComponent.addGLEventListener(this);

    // Initialize the mouse and keyboard controls
    MouseControl mouseControl = simpleInteraction.getMouseControl();
    glComponent.addMouseMotionListener(mouseControl);
    glComponent.addMouseWheelListener(mouseControl);
    KeyboardControl keyboardControl = new KeyboardControl();
    glComponent.addKeyListener(keyboardControl);

    // Create the main frame 
    frame = new JFrame("JCuda / JOGL interaction sample");
    frame.addWindowListener(new WindowAdapter()
    {
        @Override
        public void windowClosing(WindowEvent e)
        {
            runExit();
        }
    });
    frame.setLayout(new BorderLayout());
    glComponent.setPreferredSize(new Dimension(800, 800));
    frame.add(glComponent, BorderLayout.CENTER);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    glComponent.requestFocus();

    // Create and start the animator
    animator = new Animator(glComponent);
    animator.setRunAsFastAsPossible(false);
    animator.start();
    
}