2 import java.awt.event.*;
4 import javax.media.opengl.*;
5 import javax.media.opengl.glu.*;
7 public class Main implements GLEventListener {
9 private Geom geom = new Geom();
11 public Main(StlFile stlf) {
12 for(int i=0; i<stlf.coordArray.length; i+=3) {
13 Geom.P p0 = geom.newP(stlf.coordArray[i+0].x,
14 stlf.coordArray[i+0].y,
15 stlf.coordArray[i+0].z);
16 Geom.P p1 = geom.newP(stlf.coordArray[i+1].x,
17 stlf.coordArray[i+1].y,
18 stlf.coordArray[i+1].z);
19 Geom.P p2 = geom.newP(stlf.coordArray[i+2].x,
20 stlf.coordArray[i+2].y,
21 stlf.coordArray[i+2].z);
22 Geom.T t = geom.newT(geom.newE(p0, p1),
29 * Take care of initialization here.
31 public void init(GLAutoDrawable gld) {
34 gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
35 gl.glViewport(0, 0, 500, 300);
36 gl.glMatrixMode(GL.GL_PROJECTION);
38 //glu.gluOrtho2D(0.0, 500.0, 0.0, 300.0);
43 * Take care of drawing here.
45 public void display(GLAutoDrawable drawable) {
49 GL gl = drawable.getGL();
50 gl.glClear(GL.GL_COLOR_BUFFER_BIT);
53 for(Geom.T t : geom) {
57 if (red < 0.15) red = 1.0f;
58 if (green < 0.15) green = 1.0f;
59 if (blue < 0.15) blue = 1.0f;
60 gl.glColor3f(red, green, blue);
61 gl.glBegin(GL.GL_TRIANGLES);
66 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
67 public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { }
70 public static void main(String[] s) throws Exception {
71 StlFile stlf = new StlFile();
72 stlf.load("teapot.stl");
73 Main main = new Main(stlf);
74 Frame f = new Frame();
75 GLCapabilities glcaps = new GLCapabilities();
76 GLCanvas glcanvas = new GLCanvas();
77 glcanvas.addGLEventListener(main);
78 f.add(glcanvas, BorderLayout.CENTER);