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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
/**
* @(#) anti.java
* @(#) author: Silicon Graphics, Inc. (converted to Java by Ron Cemer)
*/
/*
* This program demonstrates lots of material properties.
* A single light source illuminates the objects.
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.*;
import java.io.*;
import java.util.*;
import gl4java.GLContext;
import gl4java.awt.GLCanvas;
import gl4java.utils.glut.*;
public class anti extends Applet
{
antiCanvas canvas = null;
/* Initialize the applet */
public void init()
{
Dimension d = getSize();
setLayout(new BorderLayout());
canvas = new antiCanvas(d.width, d.height);
add("Center", canvas);
}
/* Start the applet */
public void start()
{
}
/* Stop the applet */
public void stop()
{
}
public static void main( String args[] ) {
anti applet =
new anti();
Frame f = new Frame("anti");
f.addWindowListener( new WindowAdapter()
{
public void windowClosed(WindowEvent e)
{
System.exit(0);
}
public void windowClosing(WindowEvent e)
{
windowClosed(e);
}
}
);
f.setLayout(new BorderLayout());
f.add("Center", applet);
applet.setSize(500,300);
applet.init();
applet.start();
Dimension ps = applet.getPreferredSize();
f.setBounds(-100,-100,99,99);
f.setVisible(true);
//f.setVisible(false);
Insets i = f.getInsets();
f.setBounds(0,0,
ps.width+i.left+i.right,
ps.height+i.top+i.bottom);
f.setVisible(true);
}
/* Local GLCanvas extension class */
private class antiCanvas extends GLCanvas
{
GLUTFunc glut = null;
public antiCanvas(int w, int h)
{
super(w, h);
GLContext.gljNativeDebug = false;
GLContext.gljClassDebug = false;
}
public void preInit()
{
doubleBuffer = true;
stereoView = false;
}
/* Initialize antialia(float)Math.sing for RGBA mode, including alpha
* blending, hint, and line width. Print out implementation
* specific info on line width granularity and width.
*/
public void init()
{
glut = new GLUTFuncLightImpl(gl, glu);
reshape(getSize().width, getSize().height);
float values[]=new float[2];
gl.glGetFloatv (GL_LINE_WIDTH_GRANULARITY, values);
System.out.println("GL_LINE_WIDTH_GRANULARITY value is "+values[0]);
gl.glGetFloatv (GL_LINE_WIDTH_RANGE, values);
System.out.println("GL_LINE_WIDTH_RANGE values are "+
values[0] + ", " +values[1]);
gl.glEnable (GL_LINE_SMOOTH);
gl.glEnable (GL_BLEND);
gl.glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl.glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
gl.glLineWidth (1.5f);
gl.glShadeModel(GL_FLAT);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glDepthFunc(GL_LESS);
gl.glEnable(GL_DEPTH_TEST);
}
public void display()
{
if (glj.gljMakeCurrent() == false) return;
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gl.glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
glut.glutWireIcosahedron();
glj.gljSwap();
glj.gljFree();
}
public void reshape(int w, int h)
{
gl.glViewport(0, 0, w, h);
gl.glMatrixMode(GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective (45.0f, (float) w/(float) h, 3.0f, 5.0f);
gl.glMatrixMode(GL_MODELVIEW);
gl.glLoadIdentity ();
gl.glTranslatef (0.0f, 0.0f, -4.0f); /* move object into view */
}
}
}
|