fixed a few things:
- created a new com.jmex.awt.applet.AppletResizeListener to eliminate the duplicate code in the 3 Applet implementations
- BaseApplet and StandardApplet were calling display.update() instead display.getRenderer().displayBackBuffer();
this resulted in the renderqueue not being rendered, which is why F4 was not working for example.
- LWJGLDisplaySystem.initForApplet() was not updating DisplaySystems width and height, which resulted in a endlessloop when creating StatisticsGamestate. (because width and height were 0)
- also initForApplet() was creating a headless display, but headless needs to be false or Display.update(); is not called in Renderer.displayBackBuffer()
edit: those changes are commited
Index: src/com/jme/system/lwjgl/LWJGLDisplaySystem.java
===================================================================
--- src/com/jme/system/lwjgl/LWJGLDisplaySystem.java (revision 4389)
+++ src/com/jme/system/lwjgl/LWJGLDisplaySystem.java (working copy)
@@ -677,9 +677,11 @@
* @param h height of the applet
*/
public void initForApplet(int w, int h) {
+ width = w;
+ height = h;
renderer = new LWJGLRenderer(w, h);
switchContext(this);
- renderer.setHeadless(true);
+ renderer.setHeadless(false);
currentContext.setupRecords(renderer);
DisplaySystem.updateStates(renderer);
created = true;
Index: src/com/jmex/awt/applet/AppletResizeListener.java
===================================================================
--- src/com/jmex/awt/applet/AppletResizeListener.java (revision 0)
+++ src/com/jmex/awt/applet/AppletResizeListener.java (revision 0)
@@ -0,0 +1,58 @@
+package com.jmex.awt.applet;
+
+import java.applet.Applet;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+import java.util.concurrent.Callable;
+
+import com.jme.system.DisplaySystem;
+import com.jme.util.GameTaskQueue;
+import com.jme.util.GameTaskQueueManager;
+
+/**
+ * ComponentListener for use with the newer lwjgl2 Applets.<br>
+ * Listens for resize events from an Applet and reinitializes the Renderer.
+ */
+public class AppletResizeListener implements ComponentListener {
+ private Applet applet;
+
+ public AppletResizeListener(Applet applet) {
+ this.applet = applet;
+ }
+
+ public void componentHidden(ComponentEvent ce) {
+
+ }
+
+ public void componentMoved(ComponentEvent ce) {
+
+ }
+
+ /**
+ * Reinitializes the renderer based on the applets new size.<br>
+ * Sets the new width and height in the displaysystem.
+ */
+ public void componentResized(final ComponentEvent ce) {
+ Callable<?> exe = new Callable<Object>() {
+ int w = applet.getWidth();
+ int h = applet.getHeight();
+
+ public Object call() {
+ DisplaySystem display = DisplaySystem.getDisplaySystem();
+ display.getRenderer().reinit(w, h);
+ display.getRenderer().getCamera().setFrustumPerspective(45.0f,
+ (float) applet.getWidth() / (float)applet.getHeight(), 1, 1000);
+ display.setWidth(w);
+ display.setHeight(h);
+ return null;
+ }
+ };
+ GameTaskQueueManager.getManager()
+ .getQueue(GameTaskQueue.RENDER).enqueue(exe);
+ }
+
+ public void componentShown(ComponentEvent ce) {
+
+ }
+
+}
Index: src/com/jmex/awt/applet/BaseApplet.java
===================================================================
--- src/com/jmex/awt/applet/BaseApplet.java (revision 4389)
+++ src/com/jmex/awt/applet/BaseApplet.java (working copy)
@@ -165,7 +165,7 @@
// render, do not use interpolation parameter
render(-1.0f);
// Swap buffers, process messages, handle input
- Display.update();
+ display.getRenderer().displayBackBuffer();
Thread.yield();
}
}
Index: src/com/jmex/awt/applet/SimpleApplet.java
===================================================================
--- src/com/jmex/awt/applet/SimpleApplet.java (revision 4389)
+++ src/com/jmex/awt/applet/SimpleApplet.java (working copy)
@@ -1,17 +1,11 @@
package com.jmex.awt.applet;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-import java.util.concurrent.Callable;
-
import com.jme.app.AbstractGame;
import com.jme.app.BaseSimpleGame;
import com.jme.app.SimpleGame;
import com.jme.input.FirstPersonHandler;
import com.jme.input.MouseInput;
import com.jme.renderer.Renderer;
-import com.jme.util.GameTaskQueue;
-import com.jme.util.GameTaskQueueManager;
/**
* LWJGL2 Applet imlpementation similar to {@link SimpleGame}
@@ -79,23 +73,7 @@
*/
protected void initSystem() {
super.initSystem();
- this.addComponentListener(new ComponentAdapter() {
- public void componentResized(ComponentEvent ce) {
- Callable<?> exe = new Callable<Object>() {
- public Object call() {
- display.getRenderer().reinit(
- SimpleApplet.this.getWidth(),
- SimpleApplet.this.getHeight());
- cam.setFrustumPerspective(45.0f, (float) displayParent
- .getWidth()
- / (float) displayParent.getHeight(), 1, 1000);
- return null;
- }
- };
- GameTaskQueueManager.getManager()
- .getQueue(GameTaskQueue.RENDER).enqueue(exe);
- }
- });
+ this.addComponentListener(new AppletResizeListener(this));
}
}
No newline at end of file
Index: src/com/jmex/awt/applet/SimplePassApplet.java
===================================================================
--- src/com/jmex/awt/applet/SimplePassApplet.java (revision 4389)
+++ src/com/jmex/awt/applet/SimplePassApplet.java (working copy)
@@ -1,17 +1,11 @@
package com.jmex.awt.applet;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-import java.util.concurrent.Callable;
-
import com.jme.app.AbstractGame;
import com.jme.app.BaseSimpleGame;
import com.jme.app.SimplePassGame;
import com.jme.input.MouseInput;
import com.jme.renderer.Renderer;
import com.jme.renderer.pass.BasicPassManager;
-import com.jme.util.GameTaskQueue;
-import com.jme.util.GameTaskQueueManager;
/**
* LWJGL2 Applet imlpementation similar to {@link SimplePassGame}<br>
@@ -78,22 +72,6 @@
protected void initSystem() {
super.initSystem();
- this.addComponentListener(new ComponentAdapter() {
- public void componentResized(ComponentEvent ce) {
- Callable<?> exe = new Callable<Object>() {
- public Object call() {
- display.getRenderer().reinit(
- SimplePassApplet.this.getWidth(),
- SimplePassApplet.this.getHeight());
- cam.setFrustumPerspective(45.0f, (float) displayParent
- .getWidth()
- / (float) displayParent.getHeight(), 1, 1000);
- return null;
- }
- };
- GameTaskQueueManager.getManager()
- .getQueue(GameTaskQueue.RENDER).enqueue(exe);
- }
- });
+ this.addComponentListener(new AppletResizeListener(this));
}
}
No newline at end of file
Index: src/com/jmex/awt/applet/StandardApplet.java
===================================================================
--- src/com/jmex/awt/applet/StandardApplet.java (revision 4389)
+++ src/com/jmex/awt/applet/StandardApplet.java (working copy)
@@ -5,8 +5,6 @@
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Toolkit;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -41,8 +39,6 @@
/**
* LWJGL2 Applet imlpementation similar to {@link StandardGame}
- *
- * TODO: not yet finished, crashes when pressing F4
*/
public abstract class StandardApplet extends Applet {
private static final long serialVersionUID = 6894421316159346138L;
@@ -199,7 +195,8 @@
height);
camera.setFrustumPerspective(45.0f, (float) width
/ (float) height, 1, 1000);
-
+ DisplaySystem.getDisplaySystem().setWidth(width);
+ DisplaySystem.getDisplaySystem().setHeight(height);
} catch (LWJGLException e) {
e.printStackTrace();
}
@@ -358,7 +355,7 @@
// render game state
render(tpf);
// Swap buffers, process messages, handle input
- Display.update();
+ display.getRenderer().displayBackBuffer();
// Fixed framerate End
if (preferredTicksPerFrame >= 0) {
@@ -463,23 +460,7 @@
display = DisplaySystem.getDisplaySystem();
}
- this.addComponentListener(new ComponentAdapter() {
- public void componentResized(ComponentEvent ce) {
- Callable<?> exe = new Callable<Object>() {
- public Object call() {
- display.getRenderer().reinit(
- StandardApplet.this.getWidth(),
- StandardApplet.this.getHeight());
- camera.setFrustumPerspective(45.0f,
- (float) StandardApplet.this.getWidth()
- / (float)StandardApplet.this.getHeight(), 1, 1000);
- return null;
- }
- };
- GameTaskQueueManager.getManager()
- .getQueue(GameTaskQueue.RENDER).enqueue(exe);
- }
- });
+ this.addComponentListener(new AppletResizeListener(this));
}
protected void initSound() {
Index: src/jmetest/awt/applet/TestSimpleApplet.java
===================================================================
--- src/jmetest/awt/applet/TestSimpleApplet.java (revision 4389)
+++ src/jmetest/awt/applet/TestSimpleApplet.java (working copy)
@@ -18,6 +18,7 @@
*/
@Override
public void init() {
+ System.setProperty("jme.stats", "set");
setSize(640, 480);
super.init();
}
@@ -31,4 +32,8 @@
b.updateModelBound();
rootNode.attachChild(b);
}
+ @Override
+ protected void simpleUpdate() {
+ super.simpleUpdate();
+ }
}
No newline at end of file
Index: src/jmetest/awt/applet/TestStandardApplet.java
===================================================================
--- src/jmetest/awt/applet/TestStandardApplet.java (revision 4389)
+++ src/jmetest/awt/applet/TestStandardApplet.java (working copy)
@@ -6,9 +6,12 @@
import com.jme.bounding.BoundingSphere;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
+import com.jme.light.DirectionalLight;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.shape.Box;
+import com.jme.scene.state.LightState;
+import com.jme.system.DisplaySystem;
import com.jme.util.GameTaskQueueManager;
import com.jmex.awt.applet.StandardApplet;
import com.jmex.game.state.BasicGameState;
@@ -24,11 +27,11 @@
public class TestStandardApplet extends StandardApplet {
private static final long serialVersionUID = 1L;
-
+
public void init() {
+ setSize(800, 600);
System.setProperty("jme.stats", "set");
setBackgroundColor(ColorRGBA.blue.clone());
- setSize(640, 480);
super.init();
try {
@@ -69,19 +72,34 @@
KeyBindingManager.getKeyBindingManager().add("switch", KeyInput.KEY_SPACE);
this.applet = applet;
+ addLight();
+
Box box = new Box("my box", new Vector3f(0, 0, 0), 2, 2, 2);
box.setModelBound(new BoundingSphere());
box.updateModelBound();
+ rootNode.attachChild(box);
+ rootNode.updateGeometricState(0, true);
// We had to add the following line because the render thread is already running
// Anytime we add content we need to updateRenderState or we get funky effects
- rootNode.attachChild(box);
-
rootNode.updateRenderState();
}
-
+
+ /**
+ * create a LightState and attach a DirectionalLight to it.
+ */
+ private void addLight() {
+ LightState ls = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
+ DirectionalLight dr = new DirectionalLight();
+ dr.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
+ dr.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
+ dr.setEnabled(true);
+ dr.setDirection(new Vector3f(0.5f, -1, -0.5f));
+ ls.attach(dr);
+ rootNode.setRenderState(ls);
+ }
+
@Override
public void update(float tpf) {
-
if (KeyBindingManager.getKeyBindingManager().isValidCommand("switch", false)) {
applet.toggleFullscreen();
KeyInput.get().clear();