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
|
import java.awt.*;
import gl4java.*;
import gl4java.awt.*;
public class SharedGLTest extends Frame {
public static void main(String[] args) {
SharedGLTest t1 = new SharedGLTest();
t1.setVisible(true);
do { // Wait until t1 is fully created and displayed.
if(t1.getGLContext() != null) break;
}
while(true);
SharedGLTest t2 = new SharedGLTest(t1.getGLContext());
t2.setVisible(true);
}
public SharedGLTest() { this(null); }
public SharedGLTest(GLContext shareWith) {
super();
setBounds(50, 0, 200, 200);
c = new MyCanvas(100, 100, shareWith);
add(c);
}
private MyCanvas c;
public GLContext getGLContext() { return c.getGLContext(); }
private class MyCanvas extends GLCanvas {
public MyCanvas(int w, int h) {
super(w, h);
}
public MyCanvas(int w, int h, GLContext shareWith) {
super(w, h);
sharedGLContext = shareWith;
}
public void display() {
if( glj.gljMakeCurrent() == false ) {
System.out.println("problem in use() method");
return;
}
GLFunc gl = glj.getGLFunc();
buildCallList(gl); // Really build something only once.
gl.glCallList(callList);
glj.gljSwap();
glj.gljCheckGL();
glj.gljFree();
}
}
private static int callList;
private static boolean alreadyDone;
private static void buildCallList(GLFunc gl) { // Build only one call list for both GLCanvas.
if(alreadyDone) return;
alreadyDone = true;
callList = gl.glGenLists(1);
gl.glNewList(callList, gl.GL_COMPILE);
gl.glClearColor(1f, 0f, 0f, 1f);
gl.glClear(gl.GL_COLOR_BUFFER_BIT); // Clear the GLCanvas with red.
gl.glEndList();
}
}
|