|
From: <ka...@us...> - 2009-05-23 09:09:37
|
Revision: 3213
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3213&view=rev
Author: kappa1
Date: 2009-05-23 09:09:28 +0000 (Sat, 23 May 2009)
Log Message:
-----------
updated GearsApplet to use addNotify() to start a LWJGL Display, also prevents a new Display being created each time the start() method is called.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java
Modified: trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java 2009-05-22 09:30:50 UTC (rev 3212)
+++ trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java 2009-05-23 09:09:28 UTC (rev 3213)
@@ -45,10 +45,15 @@
}
}
- /**
- * @see java.applet.Applet#start()
- */
public void start() {
+
+ }
+
+ public void stop() {
+
+ }
+
+ public void startApplet() {
gameThread = new Thread() {
public void run() {
running = true;
@@ -67,9 +72,6 @@
gameThread.start();
}
- public void stop() {
- }
-
public void stopApplet() {
running = false;
}
@@ -78,6 +80,10 @@
setLayout(new BorderLayout());
try {
display_parent = new Canvas() {
+ public final void addNotify() {
+ super.addNotify();
+ startLWJGL();
+ }
public final void removeNotify() {
destroyLWJGL();
super.removeNotify();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-05-23 09:37:12
|
Revision: 3214
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3214&view=rev
Author: kappa1
Date: 2009-05-23 09:37:10 +0000 (Sat, 23 May 2009)
Log Message:
-----------
A bit of clean up, code refactoring and commenting to GearsApplet test.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java
Modified: trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java 2009-05-23 09:09:28 UTC (rev 3213)
+++ trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java 2009-05-23 09:37:10 UTC (rev 3214)
@@ -14,9 +14,13 @@
public class GearsApplet extends Applet {
+ /** The Canvas where the LWJGL Display is added */
Canvas display_parent;
+
+ /** Thread which runs the main game loop */
Thread gameThread;
+ /** is the game loop running */
boolean running = false;
private float view_rotx = 20.0f;
@@ -30,30 +34,12 @@
boolean keyDown = false;
- public void destroy() {
- remove(display_parent);
- super.destroy();
- System.out.println("Clear up");
- }
- private void destroyLWJGL() {
- stopApplet();
- try {
- gameThread.join();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- public void start() {
-
- }
-
- public void stop() {
-
- }
-
- public void startApplet() {
+ /**
+ * Once the Canvas is created its add notify method will call this method to
+ * start the LWJGL Display and game loop in another thread.
+ */
+ public void startLWJGL() {
gameThread = new Thread() {
public void run() {
running = true;
@@ -71,11 +57,44 @@
};
gameThread.start();
}
-
- public void stopApplet() {
+
+
+ /**
+ * Tell game loop to stop running, after which the LWJGL Display will be destoryed.
+ * The main thread will wait for the Display.destroy() to complete
+ */
+ private void stopLWJGL() {
running = false;
+ try {
+ gameThread.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
+ public void start() {
+
+ }
+
+ public void stop() {
+
+ }
+
+ /**
+ * Applet Destroy method will remove the canvas, before canvas is destroyed it will notify
+ * stopLWJGL() to stop main game loop and to destroy the Display
+ */
+ public void destroy() {
+ remove(display_parent);
+ super.destroy();
+ System.out.println("Clear up");
+ }
+
+ /**
+ * initialise applet by adding a canvas to it, this canvas will start the LWJGL Display and game loop
+ * in another thread. It will also stop the game loop and destroy the display on canvas removal when
+ * applet is destroyed.
+ */
public void init() {
setLayout(new BorderLayout());
try {
@@ -85,7 +104,7 @@
startLWJGL();
}
public final void removeNotify() {
- destroyLWJGL();
+ stopLWJGL();
super.removeNotify();
}
};
@@ -231,7 +250,7 @@
GL11.glTranslatef(0.0f, 0.0f, -40.0f);
} catch (Exception e) {
System.err.println(e);
- stopApplet();
+ running = false;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-06-03 18:29:15
|
Revision: 3221
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3221&view=rev
Author: kappa1
Date: 2009-06-03 18:29:05 +0000 (Wed, 03 Jun 2009)
Log Message:
-----------
Added Mouse Support to Gears Applet, This will allow rotating the view using the mouse.
Fixed view ratio to support all sizes.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java
Modified: trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java 2009-06-03 11:08:58 UTC (rev 3220)
+++ trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java 2009-06-03 18:29:05 UTC (rev 3221)
@@ -9,6 +9,7 @@
import org.lwjgl.opengl.ARBTransposeMatrix;
import org.lwjgl.opengl.Display;
import org.lwjgl.input.Keyboard;
+import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
@@ -23,18 +24,22 @@
/** is the game loop running */
boolean running = false;
- private float view_rotx = 20.0f;
- private float view_roty = 30.0f;
- private float view_rotz = 0.0f;
- private int gear1;
- private int gear2;
- private int gear3;
- private float angle = 0.0f;
+ /** variables used to rotate the view */
+ private float view_rotx = 20.0f;
+ private float view_roty = 30.0f;
+ private float view_rotz = 0.0f;
+ private int gear1;
+ private int gear2;
+ private int gear3;
+ private float angle;
boolean keyDown = false;
+ private int prevMouseX, prevMouseY;
+ private boolean mouseButtonDown = false;
+
/**
* Once the Canvas is created its add notify method will call this method to
* start the LWJGL Display and game loop in another thread.
@@ -44,7 +49,6 @@
public void run() {
running = true;
try {
- System.out.println("display_parent.isDisplayable() = " + display_parent.isDisplayable());
Display.setParent(display_parent);
//Display.setVSyncEnabled(true);
Display.create();
@@ -138,18 +142,34 @@
} else {
long timeUsed = 5000 + (startTime - System.currentTimeMillis());
startTime = System.currentTimeMillis() + 5000;
-/* System.out.println(fps + " frames 2 in " + (float) (timeUsed / 1000f) + " seconds = "
- + (fps / (timeUsed / 1000f)));*/
+ System.out.println(fps + " frames 2 in " + (float) (timeUsed / 1000f) + " seconds = "
+ + (fps / (timeUsed / 1000f)));
fps = 0;
}
- if (Keyboard.isKeyDown(Keyboard.KEY_LEFT))
- view_roty += .1f;
- else if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
- view_roty -= .1f;
+ if (Mouse.isButtonDown(0)) {
+ if (!mouseButtonDown) {
+ prevMouseX = Mouse.getX();
+ prevMouseY= Mouse.getY();
+ }
+ mouseButtonDown = true;
+ }
+ else {
+ mouseButtonDown = false;
+ }
- if (Keyboard.isKeyDown(Keyboard.KEY_F)) {
- keyDown = true;
+ if (mouseButtonDown) {
+ int x = Mouse.getX();
+ int y = Mouse.getY();
+
+ float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)display_parent.getWidth());
+ float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)display_parent.getHeight());
+
+ prevMouseX = x;
+ prevMouseY = y;
+
+ view_rotx += thetaX;
+ view_roty += thetaY;
}
// F Key Pressed (i.e. released)
@@ -174,25 +194,31 @@
public void drawLoop() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
+
GL11.glPushMatrix();
+
GL11.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
GL11.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
GL11.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
+
GL11.glPushMatrix();
GL11.glTranslatef(-3.0f, -2.0f, 0.0f);
GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f);
GL11.glCallList(gear1);
GL11.glPopMatrix();
+
GL11.glPushMatrix();
GL11.glTranslatef(3.1f, -2.0f, 0.0f);
GL11.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
GL11.glCallList(gear2);
GL11.glPopMatrix();
+
GL11.glPushMatrix();
GL11.glTranslatef(-3.1f, 4.2f, 0.0f);
GL11.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
GL11.glCallList(gear3);
GL11.glPopMatrix();
+
GL11.glPopMatrix();
}
@@ -203,6 +229,7 @@
FloatBuffer red = FloatBuffer.wrap(new float[] { 0.8f, 0.1f, 0.0f, 1.0f});
FloatBuffer green = FloatBuffer.wrap(new float[] { 0.0f, 0.8f, 0.2f, 1.0f});
FloatBuffer blue = FloatBuffer.wrap(new float[] { 0.2f, 0.2f, 1.0f, 1.0f});
+
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, pos);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_LIGHTING);
@@ -215,11 +242,13 @@
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, red);
gear(1.0f, 4.0f, 1.0f, 20, 0.7f);
GL11.glEndList();
+
gear2 = GL11.glGenLists(1);
GL11.glNewList(gear2, GL11.GL_COMPILE);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, green);
gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
GL11.glEndList();
+
gear3 = GL11.glGenLists(1);
GL11.glNewList(gear3, GL11.GL_COMPILE);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, blue);
@@ -227,11 +256,13 @@
GL11.glEndList();
GL11.glEnable(GL11.GL_NORMALIZE);
GL11.glMatrixMode(GL11.GL_PROJECTION);
-/* System.err.println("GL_VENDOR: " + GL11.glGetString(GL11.GL_VENDOR));
+
+ System.err.println("GL_VENDOR: " + GL11.glGetString(GL11.GL_VENDOR));
System.err.println("GL_RENDERER: " + GL11.glGetString(GL11.GL_RENDERER));
System.err.println("GL_VERSION: " + GL11.glGetString(GL11.GL_VERSION));
System.err.println();
- System.err.println("glLoadTransposeMatrixfARB() supported: " + GLContext.getCapabilities().GL_ARB_transpose_matrix);*/
+ System.err.println("glLoadTransposeMatrixfARB() supported: " + GLContext.getCapabilities().GL_ARB_transpose_matrix);
+
if (!GLContext.getCapabilities().GL_ARB_transpose_matrix) {
// --- not using extensions
GL11.glLoadIdentity();
@@ -243,7 +274,7 @@
identityTranspose.flip();
ARBTransposeMatrix.glLoadTransposeMatrixARB(identityTranspose);
}
- float h = (float) 300 / (float) 300;
+ float h = (float) display_parent.getHeight() / (float) display_parent.getWidth();
GL11.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
@@ -362,4 +393,4 @@
}
GL11.glEnd();
}
-}
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2010-02-21 21:27:41
|
Revision: 3277
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3277&view=rev
Author: matzon
Date: 2010-02-21 21:27:35 +0000 (Sun, 21 Feb 2010)
Log Message:
-----------
fixed non-direct buffer issue
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java
Modified: trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java 2010-02-21 21:18:17 UTC (rev 3276)
+++ trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java 2010-02-21 21:27:35 UTC (rev 3277)
@@ -225,11 +225,16 @@
protected void initGL() {
try {
// setup ogl
- FloatBuffer pos = FloatBuffer.wrap(new float[] { 5.0f, 5.0f, 10.0f, 0.0f});
- FloatBuffer red = FloatBuffer.wrap(new float[] { 0.8f, 0.1f, 0.0f, 1.0f});
- FloatBuffer green = FloatBuffer.wrap(new float[] { 0.0f, 0.8f, 0.2f, 1.0f});
- FloatBuffer blue = FloatBuffer.wrap(new float[] { 0.2f, 0.2f, 1.0f, 1.0f});
+ FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[] { 5.0f, 5.0f, 10.0f, 0.0f});
+ FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[] { 0.8f, 0.1f, 0.0f, 1.0f});
+ FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[] { 0.0f, 0.8f, 0.2f, 1.0f});
+ FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[] { 0.2f, 0.2f, 1.0f, 1.0f});
+ pos.flip();
+ red.flip();
+ green.flip();
+ blue.flip();
+
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, pos);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_LIGHTING);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|