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
|
import gl4java.awt.*;
import java.awt.*;
import java.awt.Dimension;
import gl4java.GLContext;
import gl4java.GLFunc;
public class glStencilTest {
protected class MyCanvas extends GLCanvas {
public MyCanvas(int w, int h) {
super(w,h);
GLContext.gljNativeDebug = false;
GLContext.gljClassDebug = false;
}
public void preInit() {
stencilBits = 8;
}
public void init() {
gl.glMatrixMode(GL_PROJECTION);
gl.glOrtho(-1,1,-1,1,-50.0,50.0);
gl.glMatrixMode(GL_MODELVIEW);
glj.gljCheckGL();
}
public void reshape(int w, int h) {
Dimension d=new Dimension(w,h);
if (!cvsIsInit()) return;
if( glj.gljMakeCurrent() == false ) {
return;
}
setSize(d);
gl.glViewport(0,0,w,h);
glj.gljCheckGL();
glj.gljFree();
}
public void display() {
int i;
if( glj.gljMakeCurrent() == false ) {
return;
}
gl.glPushMatrix();
gl.glClear(GL_COLOR_BUFFER_BIT);
glu.gluLookAt(0, 0, 20, 0, 0, 0, 0, 1, 0);
gl.glBegin(GL_POLYGON);
gl.glVertex2d(0,-0.5);
gl.glVertex2d(0.5,0.5);
gl.glVertex2d(-0.5,0.5);
gl.glEnd();
// Examine some OpenGL properties
int [] res=new int[6];
gl.glGetIntegerv(GL_STENCIL_BITS,res);
System.out.println("Stencil bits are "+res[0]);
gl.glGetIntegerv(GL_RED_BITS,res);
System.out.println("Color bits are "+res[0]);
gl.glPopMatrix();
glj.gljSwap();
glj.gljCheckGL();
glj.gljFree();
}
}
protected MyCanvas cvs;
protected Frame frame;
public glStencilTest() {
frame = new Frame( "OpenGL" );
cvs= new MyCanvas(640,480);
frame.setSize(640,480);
frame.add("Center", cvs);
frame.setVisible(true);
}
public static void main(java.lang.String[] args) {
try {
glStencilTest g=new glStencilTest();
} catch (Throwable exception) {
System.err.println("Exception occurred in main()");
exception.printStackTrace(System.out);
}
}
}
|