-
Notifications
You must be signed in to change notification settings - Fork 34
/
IApplicationGL1.java
146 lines (109 loc) · 4.14 KB
/
IApplicationGL1.java
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
/*---
iGeo - http://igeo.jp
Copyright (c) 2002-2013 Satoru Sugihara
This file is part of iGeo.
iGeo is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, version 3.
iGeo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with iGeo. If not, see <http://www.gnu.org/licenses/>.
---*/
package igeo;
import java.awt.*;
import java.awt.event.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;
//import com.jogamp.opengl.util.*; // processing 2.0
//import javax.media.opengl.awt.*; // processing 2.0
import igeo.gui.*;
public class IApplicationGL1 implements GLEventListener /*, IPanelAdapter*/{
public static void main(String[] args){
Frame frame = new Frame();
frame.setSize(1024,768);
GLCanvas canvas = new GLCanvas();
IApplicationGL1 application = new IApplicationGL1();
application.setFrame(frame);
canvas.addGLEventListener(application);
frame.add(canvas);
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
new Thread(new Runnable() {
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
frame.setVisible(true);
animator.start();
}
public IPanelI panel;
public IG ig;
public IGraphicsGL igg;
public Frame frame;
public void init(GLAutoDrawable drawable){
GL gl = drawable.getGL();
setGLProperties(gl);
panel = new IGridPanel(0,0,drawable.getWidth(),drawable.getHeight(),2,2);
panel.setVisible(true);
panel.setParent(frame);
//panel.setAdapter(this);
ig = IG.init(panel);
ig.server().graphicServer().enableGL();
igg = new IGraphicsGL1();
((Component)drawable).addMouseListener((MouseListener)panel);
((Component)drawable).addMouseMotionListener((MouseMotionListener)panel);
((Component)drawable).addMouseWheelListener((MouseWheelListener)panel);
((Component)drawable).addKeyListener((KeyListener)panel);
((Component)drawable).addFocusListener((FocusListener)panel);
((Component)drawable).addComponentListener((ComponentListener)panel);
frame.addWindowListener(panel);
initObjects(); // init geometry objects
}
public void setFrame(Frame f){ frame = f; }
// copied from PIGraphicsGL.java
public void setGLProperties(GL gl){
gl.glEnable(GL.GL_MULTISAMPLE);
//gl.glEnable(GL.GL_POINT_SMOOTH);
gl.glEnable(GL.GL_LINE_SMOOTH);
//gl.glEnable(GL.GL_POLYGON_SMOOTH);
//gl.glEnable(GL.GL_ALPHA_TEST);
gl.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST);
//gl.glHint(GL.GL_POINT_SMOOTH_HINT, GL.GL_NICEST);
//gl.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST);
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
if ((drawable instanceof GLJPanel) &&
!((GLJPanel) drawable).isOpaque() &&
((GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) {
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
} else {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
}
igg.setGL(gl);
panel.draw(igg);
}
public void dispose(GLAutoDrawable drawable){} // added 20130731
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
public void initObjects(){
// test
for(int i=0; i<10; i++){
for(int j=0; j<10; j++){
new ISurface(i*10,j*10,0, (i+1)*10,j*10,0, (i+1)*10,(j+1)*10, i+j, i*10, (j+1)*10, 0).clr(i*0.1,j*0.1,0);
}
}
for(int i=0; i<100; i++){
new IBoidTrajectory(IRand.pt(100)){ public void update(){ push(IRand.pt(-500,500)); }}.clr(IRand.gray());
}
IG.focus();
}
public void close(){} // doing nothing
}