//jleblanc: 2.27.06 //rudimentry exploration of branching import org.lwjgl.opengl.*; import org.lwjgl.opengl.glu.GLU; import org.lwjgl.input.Keyboard; public class tree { private boolean done = false; private final String windowTitle = "Basic OpenGL App"; private DisplayMode displayMode; float rotation = 0f; //Main function just creates and runs the application. public static void main(String args[]) { tree app = new tree(); app.run(); } //Initialize the app, then sit in a render loop until done==true. public void run() { try { init(); while (!done) { mainloop(); render(); Display.update(); } cleanup(); } catch (Exception e) { e.printStackTrace(); System.exit(0); } } //Initialize the environment private void init() throws Exception { initDisplay(); initGL(); } //Create an OpenGL display, in this case a fullscreen window. private void initDisplay() throws Exception { // set to full screen, no chrome Display.setFullscreen(false); // get all possible display resolutions DisplayMode d[] = Display.getAvailableDisplayModes(); // find a resolution we like for (int i = 0; i < d.length; i++) { if (d[i].getWidth() == 800 && d[i].getHeight() == 600 && d[i].getBitsPerPixel() == 32) { displayMode = d[i]; break; } } // set the display to the resolution we picked Display.setDisplayMode(displayMode); Display.setTitle(windowTitle); // create the window Display.create(); } //Initialize OpenGL private void initGL() { // Select the Projection Matrix (controls perspective) GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); // Reset The Projection Matrix // Define perspective GLU.gluPerspective( 45.0f, // Field Of View (float)displayMode.getWidth() / (float)displayMode.getHeight(), // aspect ratio 0.1f, // near Z clipping plane 100.0f); // far Z clipping plane // Where is the 'eye' GLU.gluLookAt( -.5f, 2f, 7f, // eye position //-.5,1,7 //0f,0f,15f, 0f, 0f, 0f, // target to look at 0f, 1f, 0f); // which way is up // Select The Modelview Matrix (controls model orientation) GL11.glMatrixMode(GL11.GL_MODELVIEW); // depth GL11.glEnable(GL11.GL_DEPTH_TEST); } //Handle keyboard input. Just check for escape key or user private void mainloop() { if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { // Escape is pressed done = true; } if(Display.isCloseRequested()) { // Window is closed done = true; } } //Render the scene. private void render() { rotation += .08f; // Clear screen and depth buffer GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Reset the Modelview matrix // this resets the coordinate system to center of screen GL11.glLoadIdentity(); // rotate coord system around Y GL11.glRotatef(rotation, 0,1,0); GL11.glTranslatef(0, -.5f, 0); // draw crosshairs //drawOrigin(); //draw tree rendertree(rotation/3, .05f, 1, 1, 10); GL11.glRotatef(120, 1,0,0); rendertree(rotation/3, .05f, 1, 1, 10); GL11.glRotatef(120, 1,0,0); rendertree(rotation/3, .05f, 1, 1, 10); } public void rendertree(float turn, float width, float scale, float level, float maxlevel) { if(level