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
|
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import gl4java.*;
import gl4java.awt.*;
public class SharedGLTest2 extends Applet
implements MouseListener
{
MyCanvas canvas = null;
Button addButton = null;
int canvasNumber = 0;
Panel pAllCvs = null;
Dimension d = null;
public void init()
{
d = getSize();
setLayout(new BorderLayout());
addButton = new Button ("add gl");
addButton.addMouseListener(this);
add("South", addButton);
pAllCvs = new Panel();
pAllCvs.setLayout(new GridLayout(4,1));
add("Center", pAllCvs);
canvas = new MyCanvas (d.width/2, d.height/2, null);
pAllCvs.add(canvas);
canvasNumber=1;
}
public static void main( String args[] )
{
Frame mainFrame = new Frame("SharedGLTest2");
SharedGLTest2 applet = new SharedGLTest2();
applet.setSize(400, 400);
applet.init();
applet.start();
mainFrame.add(applet);
mainFrame.pack();
mainFrame.setVisible(true);
}
public void start()
{
}
public void stop()
{
}
// Methods required for the implementation of MouseListener
public void mouseEntered( MouseEvent evt )
{
}
public void mouseExited( MouseEvent evt )
{
}
public void mousePressed( MouseEvent evt )
{
}
public void mouseReleased( MouseEvent evt )
{
}
public void mouseClicked( MouseEvent evt )
{
Component comp = evt.getComponent();
if( canvas!=null && comp.equals(addButton) )
{
if(canvasNumber<4)
{
MyCanvas _canvas =
new MyCanvas (d.width/2,d.height/2,canvas.getGLContext());
pAllCvs.add(_canvas);
canvasNumber++;
pAllCvs.invalidate();
pAllCvs.validate();
if(canvasNumber==4)
addButton.setEnabled(false);
}
}
}
private static int callList=0;
protected class MyCanvas extends GLCanvas
{
public MyCanvas(int w, int h, GLContext shareWith)
{
super(w, h);
sharedGLContext = shareWith;
}
public void init()
{
if(sharedGLContext==null && callList==0)
{
buildCallList(); // Really build something only once.
}
}
public void display()
{
if( glj.gljMakeCurrent() == false ) {
System.out.println("problem in use() method");
return;
}
if(callList!=0)
gl.glCallList(callList);
glj.gljSwap();
glj.gljCheckGL();
glj.gljFree();
}
/**
* Build only one call list for both GLCanvas.
*/
protected void buildCallList()
{
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();
}
}
}
|