JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
DemoCreateAndDisposeOnCloseNEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2013 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.opengl.test.junit.newt;
29
30import com.jogamp.nativewindow.WindowClosingProtocol;
31import com.jogamp.opengl.GLAutoDrawable;
32import com.jogamp.opengl.GLCapabilities;
33import com.jogamp.opengl.GLEventListener;
34import com.jogamp.opengl.GLProfile;
35
36import com.jogamp.newt.event.WindowEvent;
37import com.jogamp.newt.event.WindowAdapter;
38import com.jogamp.newt.opengl.GLWindow;
39import com.jogamp.opengl.test.junit.util.MiscUtils;
40import com.jogamp.opengl.util.Animator;
41
42/**
43 * Manual test case validating closing behavior.
44 * <p>
45 * Validates bugs:
46 * <ul>
47 * <li>Bug 882: Crash on OSX when closing NEWT window</li>
48 * </ul>
49 * </p>
50 *
51 */
53 public static void main(final String[] args) {
54 int closeMode = 0; // 0 - none, 1 - window, animator, 2 - animator, window, 3 - System.exit
55
56 for(int i=0; i<args.length; i++) {
57 if(args[i].equals("-close")) {
58 closeMode = MiscUtils.atoi(args[++i], closeMode);
59 }
60 }
61 System.err.println("Close Mode: "+closeMode);
62
64 caps.setBackgroundOpaque(true);
65 caps.setDoubleBuffered(true);
66 caps.setDepthBits(16);
67 final Animator animator = new Animator(0 /* w/o AWT */);
68 final GLWindow glWindow = GLWindow.create(caps);
69 animator.add(glWindow);
70 glWindow.addGLEventListener(new GLEventListener() {
71 @Override
72 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
73 System.out.println("GLEventListener.reshape");
74 }
75
76 @Override
77 public void init(final GLAutoDrawable drawable) {
78 System.out.println("GLEventListener.init");
79 }
80
81 @Override
82 public void dispose(final GLAutoDrawable drawable) {
83 System.out.println("GLEventListener.dispose");
84 }
85
86 @Override
87 public void display(final GLAutoDrawable drawable) {
88 }
89 });
90 glWindow.setTitle("Test");
91 glWindow.setSize(1024, 768);
92 glWindow.setUndecorated(false);
93 glWindow.setPointerVisible(true);
94 glWindow.setVisible(true);
95 glWindow.setFullscreen(false);
97 glWindow.addWindowListener(new WindowAdapter() {
98 @Override
99 public void windowDestroyNotify(final WindowEvent e) {
100 System.out.println("GLWindow.destroyNotify");
101 }
102
103 @Override
104 public void windowDestroyed(final WindowEvent e) {
105 System.out.println("GLWindow.destroyed");
106 animator.stop();
107 }
108 });
109
110 animator.start();
111
112 switch( closeMode ) {
113 case 1:
114 sleep1s();
115 glWindow.destroy();
116 sleep1s();
117 animator.stop();
118 break;
119 case 2:
120 sleep1s();
121 animator.stop();
122 sleep1s();
123 glWindow.destroy();
124 break;
125 case 3:
126 sleep1s();
127 System.exit(0);
128 break;
129 default: break; // 0 - nop
130 }
131 }
132 static void sleep1s() {
133 try {
134 Thread.sleep(1000);
135 } catch (final InterruptedException e) {
136 e.printStackTrace();
137 }
138 }
139
140}
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
WindowClosingMode setDefaultCloseOperation(final WindowClosingMode op)
Definition: GLWindow.java:222
final void setPointerVisible(final boolean mouseVisible)
Makes the pointer visible or invisible.
Definition: GLWindow.java:312
final void setTitle(final String title)
Definition: GLWindow.java:297
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final boolean setFullscreen(final boolean fullscreen)
Enable or disable fullscreen mode for this window.
Definition: GLWindow.java:534
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
Definition: GLWindow.java:882
final void setUndecorated(final boolean value)
Definition: GLWindow.java:337
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
void setDoubleBuffered(final boolean enable)
Enables or disables double buffering.
void setDepthBits(final int depthBits)
Sets the number of bits requested for the depth buffer.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getMaxProgrammable(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the programmable shader pipeline.
Definition: GLProfile.java:831
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368
Window closing mode if triggered by toolkit close operation.
DISPOSE_ON_CLOSE
Dispose resources on native window close operation.
Protocol for handling window closing events.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.