From 6a52c16dd5ba108eebe62b6209677bbbf065f10e Mon Sep 17 00:00:00 2001 From: Caspian Rychlik-Prince Date: Sun, 25 Aug 2002 10:04:09 +0000 Subject: [PATCH] Tweaks --- doc/tutorial/skeleton_code.html | 229 ++++++++++++++++---------------- 1 file changed, 112 insertions(+), 117 deletions(-) diff --git a/doc/tutorial/skeleton_code.html b/doc/tutorial/skeleton_code.html index 8fe91caf..2f21c08d 100644 --- a/doc/tutorial/skeleton_code.html +++ b/doc/tutorial/skeleton_code.html @@ -144,134 +144,129 @@ thing finished on time and under budget!

write a fullscreen Java game using LWJGL. Because we're games programmers, we don't want to do a Hello World as we'd probably rather shoot it. But before we can make bullets we must pay homage to the rotating square!

-

public +

import +org.lwjgl.*;
+import org.lwjgl.opengl.*;
+import org.lwjgl.input.*;
+
+
+public final class Game {
-static {
-try {
-DisplayMode[] modes = Display.getAvailableDisplayModes();
-System.out.println("Available display modes:");
-for (int i = 0; i < modes.length; i ++)
+    static {
+        try {
+            DisplayMode[] modes = Display.getAvailableDisplayModes();
+            System.out.println("Available display modes:");
+            for (int i = 0; i < modes.length; i ++)
+                System.out.println(modes[i]);
-// For now let's just pick a mode we're certain to have
-Display.create(new DisplayMode(640, 480, 16, 60), true);
-System.out.println("Created display.");
-} catch (Exception e) {
-System.err.println("Failed to create display due to "+e);
-System.exit(1);
-}
-}
-public static final GL gl = new GL(16, 0, 16, 8);
-static {
-try {
-gl.create();
-System.out.println("Created OpenGL.");
-} catch (Exception e) {
-System.err.println("Failed to create OpenGL due to "+e);
-System.exit(1);
-}
-}
-/** A handy number formatter for use displaying FPS and the like */
-public static NumberFormat fmt = new DecimalFormat();
-static {
-fmt.setMaximumFractionDigits(1);
-fmt.setMinimumFractionDigits(1);
-fmt.setGroupingUsed(false);
-}
-/** Is the game finished? */
-private static boolean finished;
-/** A rotating square! */
-private static float angle;
-/**
-* No construction allowed
-*/
-private Game() {
-}
-public static void main(String[] arguments) {
-try {
-init();
-int frames = 0;
-float fps = 0.0f;
-Timer timer = new Timer();
-timer.reset();
-timer.resume();
-while (!finished) {
-AbsMouse.poll();
+            // For now let's just pick a mode we're certain to have
+            Display.create(new DisplayMode(640, 480, 16, 60), true);
+            System.out.println("Created display.");
+        } catch (Exception e) {
+            System.err.println("Failed to create display due to "+e);
+            System.exit(1);
+        }
+    }
+
+    public static final GL gl = new GL(16, 0, 16, 8);
+    static {
+        try {
+            gl.create();
+            System.out.println("Created OpenGL.");
+        } catch (Exception e) {
+            System.err.println("Failed to create OpenGL due to "+e);
+            System.exit(1);
+        }
+    }
+
+    /** Is the game finished? */
+    private static boolean finished;
+
+    /** A rotating square! */
+    private static float angle;
+
+    /**
+     * No construction allowed
+     */
+    private Game() {
+    }
+
+    public static void main(String[] arguments) {
+        try {
+            init();
+            while (!finished) {
+                Keyboard.poll();
-Keyboard.read();
-gl.clear(GL.COLOR_BUFFER_BIT);
+                mainLoop();
+                render();
+                gl.swapBuffers();
-// Count the frames per second. Do with this what you will..
-frames++;
-float time = timer.getTime();
-if (time >= 1.0f) {
-fps = (int) (frames / time);
-timer.reset();
-frames = 0;
-}
-}
-} catch (Throwable t) {
+            }
   
+        } catch (Throwable t) {
+            t.printStackTrace();
-} finally {
-cleanup();
-}
-}
+        } finally {
+            cleanup();
+        }
+    }

-/**
-* All calculations are done in here
-*/
-private static void mainLoop() {
-angle += 1f;
-if (angle > 360.0f)
-angle = 0.0f;
+    /**
+     * All calculations are done in here
+     */
+    private static void mainLoop() {
+        angle += 1f;
+        if (angle > 360.0f)
+            angle = 0.0f;

-if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
-finished = true;
-}
+        Keyboard.poll();
-/**
-* All rendering is done in here
-*/
-private static void render() {
+        if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
+            finished = true;
+    }

-gl.pushMatrix();
-gl.translatef(Display.getWidth() / 2, Display.getHeight() / 2, 0.0f);
-gl.rotatef(angle, 0, 0, 1.0f);
-gl.begin(GL.QUADS);
-gl.vertex2i(-50, -50);
-gl.vertex2i(50, -50);
-gl.vertex2i(50, 50);
-gl.vertex2i(-50, 50);
-gl.end();
-gl.popMatrix();
-}
-/**
-* Initialize
-*/
-private static void init() throws Exception {
-Keyboard.create();
-Keyboard.enableBuffer();
-Mouse.create();
-// Go into orthographic projection mode.
-gl.matrixMode(GL.PROJECTION);
-gl.loadIdentity();
-gl.glu.ortho2D(0, Display.getWidth(), 0, Display.getHeight());
-gl.matrixMode(GL.MODELVIEW);
-gl.loadIdentity();
-gl.viewport(0, 0, Display.getWidth(), Display.getHeight());
-// Fix the refresh rate to the display frequency.
-gl.wglSwapIntervalEXT(1);
-}
-/**
-* Cleanup
-*/
-private static void cleanup() {
-Keyboard.destroy();
-Mouse.destroy();
-gl.destroy();
-Display.destroy();
-}
+    /**
+     * All rendering is done in here
+     */
+    private static void render() {
+        gl.clear(GL.COLOR_BUFFER_BIT);
+        gl.pushMatrix();
+        gl.translatef(Display.getWidth() / 2, Display.getHeight() / 2, 0.0f);
+        gl.rotatef(angle, 0, 0, 1.0f);
+        gl.begin(GL.QUADS);
+        gl.vertex2i(-50, -50);
+        gl.vertex2i(50, -50);
+        gl.vertex2i(50, 50);
+        gl.vertex2i(-50, 50);
+        gl.end();
+        gl.popMatrix();
+    }
+
+    /**
+     * Initialize
+     */
+    private static void init() throws Exception {
+        Keyboard.create();
+        // Go into orthographic projection mode.
+        gl.matrixMode(GL.PROJECTION);
+        gl.loadIdentity();
+        glu.ortho2D(0, Display.getWidth(), 0, Display.getHeight());
+        gl.matrixMode(GL.MODELVIEW);
+        gl.loadIdentity();
+        gl.viewport(0, 0, Display.getWidth(), Display.getHeight());
+        // Fix the refresh rate to the display frequency.
+        gl.wglSwapIntervalEXT(1);
+    }
+
+    /**
+     * Cleanup
+     */
+    private static void cleanup() {
+        Keyboard.destroy();
+   
          gl.destroy();
+        Display.destroy();
+    }
}