1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
package demos.applets;
import java.applet.*;
import java.awt.Container;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.KeyListener;
import javax.media.opengl.*;
import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.opengl.GLWindow;
import java.awt.BorderLayout;
/**
* Simple GLEventListener deployment as an applet using JOGL. This demo must be
* referenced from a web page via an <applet> tag.
*
* <p>
* Example of an applet tag using GearsES2 within the applet area (normal case):
* <pre>
<applet width=100 height=100>
<param name="java_arguments" value="-Dsun.java2d.noddraw=true">
<param name="gl_event_listener_class" value="com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2">
<param name="gl_profile" value="GL2">
<param name="gl_swap_interval" value="1">
<param name="gl_debug" value="false">
<param name="gl_trace" value="false">
<param name="jnlp_href" value="jogl-newt-applet-runner.jnlp">
</applet>Hello Gears !
* </pre>
* </p>
*
* <p>
* Example of an applet tag using GearsES2 in an undecorated, translucent and always-on-top window:
* <pre>
<applet width=1 height=1>
<param name="java_arguments" value="-Dsun.java2d.noddraw=true">
<param name="gl_event_listener_class" value="com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2">
<param name="gl_profile" value="GL2">
<param name="gl_swap_interval" value="1">
<param name="gl_undecorated" value="true">
<param name="gl_alwaysontop" value="true">
<param name="gl_opaque" value="false">
<param name="gl_dx" value="10">
<param name="gl_dy" value="0">
<param name="gl_width" value="100">
<param name="gl_height" value="100">
<param name="gl_debug" value="false">
<param name="gl_trace" value="false">
<param name="jnlp_href" value="jogl-newt-applet-runner.jnlp">
</applet>Hello Gears !
* </pre>
* </p>
*/
@SuppressWarnings("serial")
public class JOGLNewtApplet1Run extends Applet {
GLWindow glWindow;
NewtCanvasAWT newtCanvasAWT;
JOGLNewtAppletBase base;
/** if valid glStandalone:=true (own window) ! */
int glXd=Integer.MAX_VALUE, glYd=Integer.MAX_VALUE, glWidth=Integer.MAX_VALUE, glHeight=Integer.MAX_VALUE;
boolean glStandalone = false;
public void init() {
if(!(this instanceof Container)) {
throw new RuntimeException("This Applet is not a AWT Container");
}
Container container = (Container) this; // have to think about that, we may use a Container
String glEventListenerClazzName=null;
String glProfileName=null;
int glSwapInterval=0;
boolean glDebug=false;
boolean glTrace=false;
boolean glUndecorated=false;
boolean glAlwaysOnTop=false;
boolean glOpaque=true;
try {
glEventListenerClazzName = getParameter("gl_event_listener_class");
glProfileName = getParameter("gl_profile");
glSwapInterval = JOGLNewtAppletBase.str2Int(getParameter("gl_swap_interval"), glSwapInterval);
glDebug = JOGLNewtAppletBase.str2Bool(getParameter("gl_debug"), glDebug);
glTrace = JOGLNewtAppletBase.str2Bool(getParameter("gl_trace"), glTrace);
glUndecorated = JOGLNewtAppletBase.str2Bool(getParameter("gl_undecorated"), glUndecorated);
glAlwaysOnTop = JOGLNewtAppletBase.str2Bool(getParameter("gl_alwaysontop"), glAlwaysOnTop);
glOpaque = JOGLNewtAppletBase.str2Bool(getParameter("gl_opaque"), glOpaque);
glXd = JOGLNewtAppletBase.str2Int(getParameter("gl_dx"), glXd);
glYd = JOGLNewtAppletBase.str2Int(getParameter("gl_dy"), glYd);
glWidth = JOGLNewtAppletBase.str2Int(getParameter("gl_width"), glWidth);
glHeight = JOGLNewtAppletBase.str2Int(getParameter("gl_height"), glHeight);
} catch (Exception e) {
e.printStackTrace();
}
if(null==glEventListenerClazzName) {
throw new RuntimeException("No applet parameter 'gl_event_listener_class'");
}
glStandalone = Integer.MAX_VALUE>glXd && Integer.MAX_VALUE>glYd && Integer.MAX_VALUE>glWidth && Integer.MAX_VALUE>glHeight;
base = new JOGLNewtAppletBase(glEventListenerClazzName,
glSwapInterval,
glDebug,
glTrace);
try {
GLProfile.initSingleton(false);
GLCapabilities caps = new GLCapabilities(GLProfile.get(glProfileName));
caps.setBackgroundOpaque(glOpaque);
glWindow = GLWindow.create(caps);
glWindow.setUndecorated(glUndecorated);
glWindow.setAlwaysOnTop(glAlwaysOnTop);
if(glStandalone) {
newtCanvasAWT = null;
} else {
newtCanvasAWT = new NewtCanvasAWT(glWindow);
container.setLayout(new BorderLayout());
container.add(newtCanvasAWT, BorderLayout.CENTER);
}
base.init(glWindow);
if(base.isValid()) {
GLEventListener glEventListener = base.getGLEventListener();
if(glEventListener instanceof MouseListener) {
addMouseListener((MouseListener)glEventListener);
}
if(glEventListener instanceof MouseMotionListener) {
addMouseMotionListener((MouseMotionListener)glEventListener);
}
if(glEventListener instanceof KeyListener) {
addKeyListener((KeyListener)glEventListener);
}
}
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
public void start() {
if(glStandalone) {
glWindow.setSize(glWidth, glHeight);
final java.awt.Point p0 = this.getLocationOnScreen();
glWindow.setPosition(p0.x+glXd, p0.y+glYd);
}
base.start();
}
public void stop() {
base.stop();
}
public void destroy() {
glWindow.setVisible(false); // hide 1st
if(!glStandalone) {
glWindow.reparentWindow(null); // get out of newtCanvasAWT
this.remove(newtCanvasAWT); // remove newtCanvasAWT
}
base.destroy(); // destroy glWindow unrecoverable
base=null;
}
}
|