[jddaniels commit] r168 - in trunk/graphics-experiments: . src src/net src/net/ddaniels src/net/ddaniels/experiments...

1 view
Skip to first unread message

codesite...@google.com

unread,
Jan 31, 2008, 10:50:39 PM1/31/08
to jddaniels-commit...@googlegroups.com
Author: daniels.douglas
Date: Thu Jan 31 19:40:37 2008
New Revision: 168

Added:
trunk/graphics-experiments/.classpath
trunk/graphics-experiments/.project
trunk/graphics-experiments/src/
trunk/graphics-experiments/src/net/
trunk/graphics-experiments/src/net/ddaniels/
trunk/graphics-experiments/src/net/ddaniels/experiments/
trunk/graphics-experiments/src/net/ddaniels/experiments/jogl/
trunk/graphics-experiments/src/net/ddaniels/experiments/lwjgl/
trunk/graphics-experiments/src/net/ddaniels/experiments/lwjgl/LWJGLTest.java

Log:
Initial import.

Added: trunk/graphics-experiments/.classpath
==============================================================================
--- (empty file)
+++ trunk/graphics-experiments/.classpath Thu Jan 31 19:40:37 2008
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/Graphics Libraries"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>

Added: trunk/graphics-experiments/.project
==============================================================================
--- (empty file)
+++ trunk/graphics-experiments/.project Thu Jan 31 19:40:37 2008
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>graphics-experiments</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>

Added: trunk/graphics-experiments/src/net/ddaniels/experiments/lwjgl/LWJGLTest.java
==============================================================================
--- (empty file)
+++
trunk/graphics-experiments/src/net/ddaniels/experiments/lwjgl/LWJGLTest.java
Thu Jan 31 19:40:37 2008
@@ -0,0 +1,151 @@
+package net.ddaniels.experiments.lwjgl;
+
+import org.lwjgl.Sys;
+import org.lwjgl.input.Keyboard;
+import org.lwjgl.opengl.Display;
+import org.lwjgl.opengl.GL11;
+
+public class LWJGLTest {
+
+ /** Game title */
+ public static final String GAME_TITLE = "My Game";
+
+ /** Desired frame time */
+ private static final int FRAMERATE = 60;
+
+ /** Exit the game */
+ private static boolean finished;
+
+ /** Angle of rotating square */
+ private static float angle;
+
+ /**
+ * Application init
+ *
+ * @param args
+ * Commandline args
+ */
+ public static void main(String[] args) {
+ boolean fullscreen = (args.length == 1 && args[0].equals("-fullscreen"));
+
+ try {
+ init(fullscreen);
+ run();
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ Sys.alert(GAME_TITLE, "An error occured and the game will exit.");
+ } finally {
+ cleanup();
+ }
+ System.exit(0);
+ }
+
+ /**
+ * Initialise the game
+ *
+ * @throws Exception
+ * if init fails
+ */
+ private static void init(boolean fullscreen) throws Exception {
+ // Create a fullscreen window with 1:1 orthographic 2D projection
+ // (default)
+ Display.setTitle(GAME_TITLE);
+ Display.setFullscreen(fullscreen);
+
+ // Enable vsync if we can (due to how OpenGL works, it cannot be
+ // guarenteed to always work)
+ Display.setVSyncEnabled(true);
+
+ // Create default display of 640x480
+ Display.create();
+ }
+
+ /**
+ * Runs the game (the "main loop")
+ */
+ private static void run() {
+
+ while (!finished) {
+ // Always call Window.update(), all the time - it does some behind
+ // the
+ // scenes work, and also displays the rendered output
+ Display.update();
+
+ // Check for close requests
+ if (Display.isCloseRequested()) {
+ finished = true;
+ }
+
+ // The window is in the foreground, so we should play the game
+ else if (Display.isActive()) {
+ logic();
+ render();
+ Display.sync(FRAMERATE);
+ }
+
+ // The window is not in the foreground, so we can allow other stuff
+ // to run and
+ // infrequently update
+ else {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ }
+ logic();
+
+ // Only bother rendering if the window is visible or dirty
+ if (Display.isVisible() || Display.isDirty()) {
+ render();
+ }
+ }
+ }
+ }
+
+ /**
+ * Do any game-specific cleanup
+ */
+ private static void cleanup() {
+ // Close the window
+ Display.destroy();
+ }
+
+ /**
+ * Do all calculations, handle input, etc.
+ */
+ private static void logic() {
+ // Example input handler: we'll check for the ESC key and finish the
+ // game instantly when it's pressed
+ if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
+ finished = true;
+ }
+
+ // Rotate the square
+ angle += 2.0f % 360;
+ }
+
+ /**
+ * Render the current frame
+ */
+ private static void render() {
+ // clear the screen
+ GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
+ GL11.glColor3f(1.0f, 0.0f, 0.0f);
+ // center square according to screen size
+ GL11.glPushMatrix();
+ GL11.glTranslatef(Display.getDisplayMode().getWidth() / 2, Display
+ .getDisplayMode().getHeight() / 2, 0.0f);
+
+ // rotate square according to angle
+ GL11.glRotatef(angle, 0, 0, 1.0f);
+
+ // render the square
+ GL11.glBegin(GL11.GL_QUADS);
+ GL11.glVertex2i(-50, -50);
+ GL11.glVertex2i(50, -50);
+ GL11.glVertex2i(50, 50);
+ GL11.glVertex2i(-50, 50);
+ GL11.glEnd();
+
+ GL11.glPopMatrix();
+ }
+}

Reply all
Reply to author
Forward
0 new messages