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
| import javax.media.opengl.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame {
public Test() {
this.setSize(400, 300);
this.setTitle("Test1");
GLCapabilities glCaps = new GLCapabilities();
glCaps.setRedBits(8);
glCaps.setBlueBits(8);
glCaps.setGreenBits(8);
glCaps.setAlphaBits(8);
GLCanvas canvas = new GLCanvas(glCaps);
canvas.addGLEventListener(new TestRenderer());
this.add(canvas);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
}
public static void main(String args[]) {
Test test = new Test();
test.setVisible(true);
}
};
class TestRenderer implements GLEventListener {
private GL gl;
private GLDrawable glDrawable;
public void display(GLAutoDrawable drawable) {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glBegin(GL.GL_TRIANGLES);
gl.glVertex3f(0.0f, 0.0f, 0.0f);
gl.glVertex3f(1.0f, 0.0f, 0.0f);
gl.glVertex3f(1.0f, 1.0f, 0.0f);
gl.glEnd();
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
}
public void init(GLAutoDrawable drawable) {
gl = drawable.getGL();
glDrawable = drawable;
drawable.setGL(new DebugGL(gl));
}
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
}
};
|