2 import java.awt.event.*;
4 import javax.media.opengl.*;
5 import javax.media.opengl.glu.*;
7 public class Main implements GLEventListener {
9 public static StlFile stlf = null;
12 * Take care of initialization here.
14 public void init(GLAutoDrawable gld) {
17 gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
18 gl.glViewport(0, 0, 500, 300);
19 gl.glMatrixMode(GL.GL_PROJECTION);
21 //glu.gluOrtho2D(0.0, 500.0, 0.0, 300.0);
26 * Take care of drawing here.
28 public void display(GLAutoDrawable drawable) {
32 GL gl = drawable.getGL();
33 gl.glClear(GL.GL_COLOR_BUFFER_BIT);
36 for(int i=0; i<stlf.coordArray.length; i+=3) {
40 if (red < 0.15) red = 1.0f;
41 if (green < 0.15) green = 1.0f;
42 if (blue < 0.15) blue = 1.0f;
43 gl.glColor3f(red, green, blue);
45 gl.glBegin(GL.GL_TRIANGLES);
46 for(int j=0; j<3; j++)
47 gl.glVertex3f(stlf.coordArray[i+j].x,
48 stlf.coordArray[i+j].y,
49 stlf.coordArray[i+j].z);
53 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
54 public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { }
57 public static void main(String[] s) throws Exception {
59 stlf.load("teapot.stl");
60 Main main = new Main();
61 Frame f = new Frame();
62 GLCapabilities glcaps = new GLCapabilities();
63 GLCanvas glcanvas = new GLCanvas();
64 glcanvas.addGLEventListener(main);
65 f.add(glcanvas, BorderLayout.CENTER);