o.k then sorry for the messy code but I didn't have much time to make it neat
So first here is the testting main class
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jmex.game.state.DebugGameState;
import com.jmex.game.state.GameStateManager;
public class Testing extends SimpleJMESwingFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* @param args
*/
/**
* a standardGameState , have all the basics
*/
private static StandardGameState test;
private static DebugGameState test2;
public static void main(final String[] args) {
final Testing testing = new Testing();
testing.setLocationRelativeTo(null);
// Wait for the gameStateManager to be created
while(!testing.isImplemented());
// Create the GameStates , the DebugGame state is not working well bu the StandardGameState works fine
test2 = new DebugGameState();
test = new StandardGameState("main");
// Init some stuff to render
simpleInitGame();
// Show the Frame
testing.setVisible(true);
}
private static void simpleInitGame() {
final DisplaySystem display = DisplaySystem.getDisplaySystem();
final Node father = new Node();
// Create a box and texture to see
final Box b=new Box("my box",new Vector3f(0,0,0),new Vector3f(1,1,1));
b.setModelBound(new BoundingBox());
b.updateModelBound();
b.setLocalScale(new Vector3f(50,70,50));
final TextureState ts=display.getRenderer().createTextureState();
// Use the TextureManager to load a texture
final Texture t =
TextureManager.loadTexture(Testing.class.getClassLoader().getResource("./nike.png"),Texture.MM_LINEAR,Texture.FM_LINEAR);
// Assign the texture to the TextureState
ts.setTexture(t);
t.setWrap(Texture.WM_WRAP_S_WRAP_T);
t.setScale(new Vector3f(5,5,0));
father.setRenderState(ts);
father.attachChild(b);
test.getRootNode().attachChild(father);
// Attach the gameState to the GameState Manager
GameStateManager.getInstance().attachChild(test);
test.setActive(true);
// This is where I tried to use DebugGameState with no success, I don't understand what us turning it around
/*test2.getRootNode().attachChild(father);
GameStateManager.getInstance().attachChild(test2);
test2.setActive(true);*/
father.updateRenderState();
}
}
Now here is the Code for the SimpleJMESwingFrame
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyListener;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.jme.input.InputSystem;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.system.DisplaySystem;
import com.jmex.awt.JMECanvas;
import com.jmex.awt.SimpleCanvasImpl;
import com.jmex.awt.input.AWTKeyInput;
import com.jmex.awt.input.AWTMouseInput;
import com.jmex.game.state.GameStateManager;
public class SimpleJMESwingFrame extends JFrame {
/**
* SimpleJMESwingFrame Works the same as SimpleJME Applet
* It lets you subclass it in order to create a swing Frame that you can work with
*/
private static final long serialVersionUID = 1L;
private static final int WIDTH = 640;
private static final int HIEGHT = 480;
/**
* The Canvas that will hold the gl
*/
private Canvas glCanvas;
/**
* The implementor
*/
SimpleCanvasImpl impl;
/**
* a Title for our frame
*/
private String title;
/**
* width and height variables
*/
int width, height;
/**
* A Constractor that gets the width and height
* @param width
* @param height
*/
public SimpleJMESwingFrame( int width, int height) {
this("JME Canvas test",width,height);
}
/**
* A default Constractor
*/
public SimpleJMESwingFrame() {
this("JME Canvas test",WIDTH,HIEGHT);
}
/**
* A Constractor that gets a Title
* @param title
*/
public SimpleJMESwingFrame(String title) {
this(title,WIDTH,HIEGHT);
}
/**
* A Constractor that gets title ,width and height
* @param title
* @param width
* @param height
*/
public SimpleJMESwingFrame(String title, int width, int height) {
this.title = title;
this.width = width;
this.height = height;
// Add a listener for closing the window
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
// init the frame
init();
// pack the frame
pack();
// Repain canvas in a thread
new Thread() {
{
setDaemon(true);
}
public void run() {
while (true) {
glCanvas.repaint();
yield();
}
}
}.start();
}
/**
* Init function initilize the components
*/
private void init() {
// Create the canvas from the Display System
glCanvas = DisplaySystem.getDisplaySystem("lwjgl").createCanvas(
WIDTH, HEIGHT);
// Set the title
setTitle(title);
// add a listener... if window is resized, we can do something about it.
glCanvas.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent ce) {
doResize();
}
});
KeyInput.setProvider(InputSystem.INPUT_SYSTEM_AWT);
AWTMouseInput.setup(glCanvas, true);
// Create the implementor
impl = new SimpleCanvasImplementor(640, 480);
//Set the jme canvas implementor
JMECanvas jmeCanvas = ((JMECanvas) glCanvas);
jmeCanvas.setImplementor(impl);
jmeCanvas.setUpdateInput(true);
JPanel contentPane = (JPanel) this.getContentPane();
glCanvas.setBounds(0, 0, 640, 480);
// Add jme canvas to the frame content pane
contentPane.add(glCanvas, BorderLayout.CENTER);
/*
* When the frame has focus activate the inputs
* when it loses the focus disable inputs
*/
glCanvas.setFocusable(true);
glCanvas.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent arg0) {
((AWTKeyInput) KeyInput.get()).setEnabled(true);
((AWTMouseInput) MouseInput.get()).setEnabled(true);
}
public void focusLost(FocusEvent arg0) {
((AWTKeyInput) KeyInput.get()).setEnabled(false);
((AWTMouseInput) MouseInput.get()).setEnabled(false);
}
});
// Add the inpus listeners
((JMECanvas) glCanvas).setUpdateInput(true);
if (!KeyInput.isInited())
KeyInput.setProvider(InputSystem.INPUT_SYSTEM_AWT);
((AWTKeyInput) KeyInput.get()).setEnabled(false);
KeyListener kl = (KeyListener) KeyInput.get();
glCanvas.addKeyListener(kl);
if (!MouseInput.isInited())
MouseInput.setProvider(InputSystem.INPUT_SYSTEM_AWT);
((AWTMouseInput) MouseInput.get()).setEnabled(false);
((AWTMouseInput) MouseInput.get()).setDragOnly(true);
//glCanvas.addMouseListener((MouseListener) MouseInput.get());
glCanvas.addMouseWheelListener((MouseWheelListener) MouseInput
.get());
glCanvas.addMouseMotionListener((MouseMotionListener) MouseInput
.get());
glCanvas.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(java.awt.event.MouseEvent e) {
if (!glCanvas.hasFocus())
glCanvas.requestFocus();
};
});
}
/**
* doResize resize the canvas
*
*/
protected void doResize() {
impl.resizeCanvas(glCanvas.getWidth(), glCanvas.getHeight());
}
// Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
/**
* return true if the implementor is init
* @return
*/
public boolean isImplemented(){
return ((SimpleCanvasImplementor)impl).isImplemented();
}
public void simpleFrameSetup() {
}
public void simpleFrameUpdate() {
}
public void simpleFrameRender() {
}
public float getTimePerFrame() {
return impl.getTimePerFrame();
}
public Renderer getRenderer() {
return impl.getRenderer();
}
public Node getRootNode() {
return impl.getRootNode();
}
/**
* the implementor class
* @author moshe
*
*/
class SimpleCanvasImplementor extends SimpleCanvasImpl {
public SimpleCanvasImplementor(int width, int height) {
super(width, height);
}
/**
* Setup function create the gameState instance and activate simpleFrame setup function
*/
public void simpleSetup() {
// Create a gameState manager instance
GameStateManager.create();
simpleFrameSetup();
}
/**
* Update function
* Upate the gameState instance and the updateFrame function
*/
public void simpleUpdate() {
simpleFrameUpdate();
GameStateManager.getInstance().update(tpf);
}
/**
* Render function renders the GameState render function and SimpleFrameRender function
*/
public void simpleRender() {
GameStateManager.getInstance().render(tpf);
simpleFrameRender();
}
/**
* @return true if the GameStateManager is created
*/
public boolean isImplemented() {
return (GameStateManager.getInstance() != null);
}
}
}