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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
/**
* @(#) Test.java
* @(#) author: Sven Goethel
*/
package gl4java.utils;
/* This program is free software under the license of LGPL */
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.*;
import java.io.*;
import java.util.*;
import gl4java.GLContext;
import gl4java.awt.GLCanvas;
import gl4java.awt.GLAnimCanvas;
import gl4java.applet.SimpleGLAnimApplet1;
public class Test
{
public Test(String name, Object tstObj, int width, int height)
{
if(tstObj instanceof SimpleGLAnimApplet1)
{
SimpleGLAnimApplet1 glSAnimApplet = (SimpleGLAnimApplet1)tstObj;
Frame f = new Frame(name);
f.addWindowListener( new WindowAdapter()
{
public void windowClosed(WindowEvent e)
{
System.exit(0);
}
public void windowClosing(WindowEvent e)
{
windowClosed(e);
}
}
);
f.setLayout(new BorderLayout());
glSAnimApplet.setSize(width, height);
glSAnimApplet.init();
glSAnimApplet.start();
f.add(glSAnimApplet);
Dimension ps = glSAnimApplet.getPreferredSize();
f.setBounds(-100,-100,99,99);
f.setVisible(true);
//f.setVisible(false);
Insets i = f.getInsets();
f.setBounds(0,0,
ps.width+i.left+i.right,
ps.height+i.top+i.bottom);
f.setVisible(true);
} else if(tstObj instanceof GLAnimCanvas)
{
GLAnimCanvas glAnimCvsTest = (GLAnimCanvas)tstObj;
GLAnimCanvasTest applet = new GLAnimCanvasTest();
Frame f = new Frame(name);
f.addWindowListener( new WindowAdapter()
{
public void windowClosed(WindowEvent e)
{
System.exit(0);
}
public void windowClosing(WindowEvent e)
{
windowClosed(e);
}
}
);
f.setLayout(new BorderLayout());
f.add("Center", applet);
applet.setSize(width,height);
applet.init(glAnimCvsTest);
applet.start();
Dimension ps = applet.getPreferredSize();
f.setBounds(-100,-100,99,99);
f.setVisible(true);
f.setVisible(false);
Insets i = f.getInsets();
f.setBounds(0,0,
ps.width+i.left+i.right,
ps.height+i.top+i.bottom);
f.setVisible(true);
} else {
GLCanvas glCvsTest = (GLCanvas)tstObj;
GLCanvasTest applet = new GLCanvasTest();
Frame f = new Frame(name);
f.addWindowListener( new WindowAdapter()
{
public void windowClosed(WindowEvent e)
{
System.exit(0);
}
public void windowClosing(WindowEvent e)
{
windowClosed(e);
}
}
);
f.setLayout(new BorderLayout());
f.add("Center", applet);
applet.setSize(width,height);
applet.init();
applet.start();
Dimension ps = applet.getPreferredSize();
f.setBounds(-100,-100,99,99);
f.setVisible(true);
f.setVisible(false);
Insets i = f.getInsets();
f.setBounds(0,0,
ps.width+i.left+i.right,
ps.height+i.top+i.bottom);
f.setVisible(true);
}
}
/**
* Test to load the native library, GLFunc and GLUFunc implementation !
* If succesfull, a Frame will created and the GL-Infos (vendor, ...)
* are shown in it !
*
* @param args, a list of args,
*
* -gljlib <glj-libname> gl4java-glj-lib native library
* -gllib <gl-libname> gl4java-gl-lib native library
* -glulib <glu-libname> gl4java-glu-lib native library
* -glclass <gl-class> gl4java-gl-class java GLFunc implementation
* -gluclass <glu-class> gl4java-glu-class java GLUFunc implementation
* -testclass <GLCanvas or SimpleGLAnimApplet1 Implementation Class> A derivation of GLCanvas (GLAnimCanvas also) or SimpleGLAnimApplet1 can be started here for testing purposes !
* -w <int> the testclass window width (default 400)
* -h <int> the testclass window height (default 250)
* -perftest if a derivation of GLAnimCanvas is used as the testclass (see above), the fps-sleep and the use-repaint flags are set to false!
*
* without any arguments, a help screen is shown
*/
public static void main( String args[] )
{
String gljLibName = null;
String glLibName = null;
String gluLibName = null;
String glName = GLContext.defGLFuncClass;
String gluName = GLContext.defGLUFuncClass;
String testClazzName = GLContext.defGLUFuncClass;
boolean perftest=false;
int width=400, height=250;
int i = 0;
boolean ok=true;
if(args.length==0)
{
System.out.println("usage: java gl4java.GLContext <options>, where options can be: ");
System.out.println(" -gljlib <glj-libname> \t\t\t choose a custom the gl4java-glj-lib native library (default: GL4JavaJauGljJNI)");
System.out.println(" -gllib <gl-libname> \t\t\t choose a custom the gl4java-gl-lib native library (default: GL4JavaJauGLJNI)");
System.out.println(" -glulib <glu-libname> \t\t\t choose a custom the gl4java-glu-lib native library (default: GL4JavaJauGLUJNI");
System.out.println(" -glclass <gl-class> \t\t\t choose a custom the gl4java-gl-class java GLFunc implementation (default: GLFuncJauJNI)");
System.out.println(" -gluclass <glu-class> \t\t\t choose a custom the gl4java-glu-class java GLUFunc implementation (default: GLUFuncJauJNI)");
System.out.println(" -testclass <GLCanvas Implementation Class> \t\t\t a derivation of GLCanvas (GLCanvas or GLAnimCanvas) can be started here for testing purposes !");
System.out.println(" -w <int> \t\t\t the testclass window width (default 800) !");
System.out.println(" -h <int> \t\t\t the testclass window height (default 600) !");
System.out.println(" -perftest \t\t\t if a derivation of GLAnimCanvas is used as the testclass (see above), the fps-sleep and the use-repaint flags are set to false!");
System.exit(0);
}
while(args.length>i)
{
if(args[i].equals("-gljlib")) {
if(args.length>++i) gljLibName=args[i];
} else if(args[i].equals("-gllib")) {
if(args.length>++i) glLibName=args[i];
} else if(args[i].equals("-glulib")) {
if(args.length>++i) gluLibName=args[i];
} else if(args[i].equals("-glclass")) {
if(args.length>++i) glName=args[i];
} else if(args[i].equals("-gluclass")) {
if(args.length>++i) gluName=args[i];
} else if(args[i].equals("-testclass")) {
if(args.length>++i) testClazzName=args[i];
} else if(args[i].equals("-w")) {
if(args.length>++i) {
try {
width = Integer.valueOf(args[i]).intValue();
} catch (Exception ex) {
System.out.println("invalid width, please insert an integer value !");
ok=false;
}
}
} else if(args[i].equals("-h")) {
if(args.length>++i) {
try {
height = Integer.valueOf(args[i]).intValue();
} catch (Exception ex) {
System.out.println("invalid height, please insert an integer value !");
ok=false;
}
}
} else if(args[i].equals("-perftest")) {
perftest=true;
} else {
System.out.println("illegal arg "+i+": "+args[i]);
ok=false;
}
i++;
}
if(!perftest)
{
GLContext.gljNativeDebug = true;
GLContext.gljClassDebug = true;
} else {
GLContext.gljNativeDebug = false;
GLContext.gljClassDebug = false;
}
if(GLContext.loadNativeLibraries(gljLibName, glLibName, gluLibName))
System.out.println("native Libraries loaded succesfull");
else {
System.out.println("native library NOT loaded complete");
ok=false;
}
Object tstObj = null;
if(ok==true)
{
try {
Class canvasClazz =
Class.forName("gl4java.awt.GLCanvas");
Class animCanvasClazz =
Class.forName("gl4java.awt.GLAnimCanvas");
Class animAppletCanvasClazz =
Class.forName("gl4java.applet.SimpleGLAnimApplet1");
Class tstClazz =
Class.forName(testClazzName);
if( ! canvasClazz.isAssignableFrom(tstClazz) &&
! animAppletCanvasClazz.isAssignableFrom(tstClazz) )
{
System.out.println("Your test-clazz is neither derived from gl4java.awt.GLCanvas nor from gl4java.applet.SimpleGLAnimApplet1!");
ok=false;
throw new Exception();
}
/**
* Std. conversion from Integer -> int
*/
Class[] parameterTypes = new Class[4];
parameterTypes[0] = Class.forName("java.lang.Integer");
parameterTypes[1] = Class.forName("java.lang.Integer");
parameterTypes[2] = Class.forName("java.lang.String");
parameterTypes[3] = Class.forName("java.lang.String");
Object[] parameters = null;
java.lang.reflect.Constructor tstObjConstr = null;
try {
tstObjConstr = tstClazz.getConstructor(parameterTypes);
parameters = new Object[4];
parameters[0] = new java.lang.Integer(width);
parameters[1] = new java.lang.Integer(height);
parameters[2] = glName;
parameters[3] = gluName;
} catch (java.lang.NoSuchMethodException nsme) {
try {
parameterTypes = new Class[4];
parameterTypes[0] = Class.forName("java.lang.Integer");
parameterTypes[1] = Class.forName("java.lang.Integer");
tstObjConstr = tstClazz.getConstructor(parameterTypes);
parameters = new Object[4];
parameters[0] = new java.lang.Integer(width);
parameters[1] = new java.lang.Integer(height);
} catch (java.lang.NoSuchMethodException nsme2) {
tstObj = tstClazz.newInstance();
}
}
if(tstObj==null && parameters!=null)
tstObj = tstObjConstr.newInstance(parameters);
} catch (Exception ex) {
System.out.println("Instantiation of: "+testClazzName+" failed !");
System.out.println(ex);
ok =false;
}
ok = tstObj!=null ;
}
if(ok) {
// let's do it ...
Test test = new Test(testClazzName, tstObj, width, height);
}
}
private class GLAnimCanvasTest extends SimpleGLAnimApplet1
{
public void init(GLAnimCanvas glAnimCanvas)
{
super.init();
Dimension d = getSize();
canvas = glAnimCanvas;
add("Center", canvas);
}
}
private class GLCanvasTest extends Applet
{
GLCanvas canvas = null;
/* Initialize the applet */
public void init(GLCanvas glCanvas)
{
Dimension d = getSize();
setLayout(new BorderLayout());
canvas = glCanvas;
add("Center", canvas);
}
/* Start the applet */
public void start()
{
}
/* Stop the applet */
public void stop()
{
}
}
}
|