Embedded StandardGame in Swing UI?

Hi!



I'm a total noob and I'm "fighting" to develop a projected based on robotic simulation. I'm in transit from Java3D and I really have to say that jme and jmephysics really make much more things clear to me! Java3D had a "enormous" user guide and beginner tutorial but in terms of support…oh my god…If I just discovered jme before…



Anyway…I'm writing in this thread because I really want to implement my project using/taking advantage of StandardGame and use a JFrame to contain it (the canvas he should use to render). Its just because I will have some more degrees of freedom where to choose jmeDesktop or a simple component outside jme renderization (can make it easier for me).



So, when I tried to do it, I found the "bug" that this thread talks about…exception in StandardGame in line 249 "camera = display.getRenderer().createCamera(display.getWidth(), display.getHeight());" where display.getRenderer() returns null.

I'm using a simple JFrame and in the constructor simply doing what was supposed too (I think):

public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
          (new jmeTest()).setVisible(true);
      } catch (Exception e) {
         e.printStackTrace();
      }
            }
        });
    }
public jmeTest() throws Exception{
      
        initComponents(); // where components like a JMenuBar are initialized
              
        StandardGame.DISPLAY_MODE = StandardGame.DISPLAY_CANVAS;
        final StandardGame game = new StandardGame("TestJMEDesktopState");
          game.start(); //BOOM
....



So, I would love to know if someone fixed this problem...if it has solution or tweak...

Thanks and..."thanks for jme!"

Jos
moshad said:

I created the GameStateManager instance  inside the implementor simpleSetup method
updated it in simpleUpdate and render it in simpleRender , this way after I create my canvas inside the frame and set it's implementor I have a gameStateInstance up and running , I attached some objects using debugGameState and they rendered to the scene so it seems to be working at list for the display (the mouse keyboard seems to do some troubles but I didn't work in it yet).
so if anyone wants to use the GameStates  and a swing frame , it seems that this way can work.
thanks for all your help guys
Moshe


Hi,

I am currently also trying to use StandardGame, GameStates and a JMECanvas for displaying in a Swing application. I need GameStates for preloading textures, models and so on because normally when I just use JMECanvas with the implementator SimpleCanvasImpl like in the JME example JMESwingTest, things get only being rendered when the canvas is fully visible on the Swing GUI and getting repainted. With the help of GameStates I hope I can get this under control and preload things before the Canvas is visible.

Now, I would be very interested in the solution you mentioned. Could you please provide me a source code example? I would very appreciate that.

Thanks,

Michael

Currently there is a known issue with StandardGame and JMECanvas… you would have to wait for it to be fixed, or fix it yourself and contribute it back… Sorry.

Hi ppl wsup.

well I had some time today to work on this issue so I've come up with this solution and it seems to work (meanwhile)

I didn't test it yet with some other gamsStates but what I have so far works.

I have 2 classed StandardGameState , SimpleJMESwingFrame (with inner class SimpleCanvasImplementor)  and testing class.



I decided to follow the Applet example and create a class name SimpleJMESwingFrame , so like in the Applet example all you need to do to create a swing frame is to subclass this class and implement the SimpleFrameUpdate ,SimpleFrameSetup and SimpleFrameRender functions.



In this SimpleJMESwingFrame there is an inner class SimpleCanvasImplementor that has an instance of a GameStateManager so

any states can be attached to it.



now for the StandardGame solution what I did is that I created a StandardGameState class that has the basic things like a Cam , input system etc' and after I created the instance of this class I attached it to the gameStateManager and it seems to work fine.

now this class is not really necessary coz you can use and other ganeState like DebugGameState but I have a bug here that if I use it the whole environment is turning around and I couldn't find what is causing IT So I created my own GameState.

if someone can figure this out I think this will be helpfull.



o.k then the code will be in the next messages (exceeded 20000 characters)

sorry for the messy code but I didn't have much time to make it neat

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);      
      }
   }
}

and the StandardGameState

Hope this will help



import util.Constants;

import com.jme.image.Texture;
import com.jme.input.AbsoluteMouse;
import com.jme.input.FirstPersonHandler;
import com.jme.input.InputHandler;
import com.jme.input.InputSystem;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.KeyboardLookHandler;
import com.jme.input.MouseInput;
import com.jme.light.PointLight;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.state.LightState;
import com.jme.scene.state.WireframeState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.util.geom.Debugger;
import com.jmex.game.state.BasicGameState;


public class StandardGameState extends BasicGameState {

   public StandardGameState(String arg0) {
      super(arg0);
      init(true);
   }
    protected InputHandler input;
       protected Camera cam;
       protected WireframeState wireState;
       protected LightState lightState;
       protected boolean pause;
       protected boolean showBounds = false;
       protected boolean showDepth = false;
       protected boolean showNormals = false;
       private Node mainLightNode;
      
       //  Action mnager
      // ActionManager actionManager;
       // Absolut mouse pointer
      
       private AbsoluteMouse absolutMouse;
      
       //private JMEDesktopState desktopState;
      
      
       //Display
       private DisplaySystem display;


       private void init(boolean handleInput) {
          //create the root Node
           rootNode = new Node("RootNode");
     
           // Create a wirestate to toggle on and off. Starts disabled with default
           // width of 1 pixel.
           wireState = DisplaySystem.getDisplaySystem().getRenderer()
                   .createWireframeState();
           wireState.setEnabled(false);
           rootNode.setRenderState(wireState);
          
           // Assign global variables
           display = DisplaySystem.getDisplaySystem();
           cam = DisplaySystem.getDisplaySystem().getRenderer().getCamera();

           // Create ZBuffer for depth
           ZBufferState zbs = DisplaySystem.getDisplaySystem().getRenderer()
                   .createZBufferState();
           zbs.setEnabled(true);
           zbs.setFunction(ZBufferState.CF_LEQUAL);
           rootNode.setRenderState(zbs);
          
           // Lighting
           /** Set up a basic, default light. */
           PointLight light = new PointLight();
           light.setDiffuse( new ColorRGBA( 1f, 1f, 1f, 1f ) );
           light.setAmbient( new ColorRGBA( 1,1, 1, 1.0f ) );
           light.setLocation( new Vector3f( 100, 100, 100 ) );
           light.setEnabled( true );

           /** Attach the light to a lightState and the lightState to rootNode. */
           lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
           lightState.setEnabled( true );
           lightState.attach( light );
           mainLightNode = new Node();
           mainLightNode.setRenderState(lightState);
           rootNode.attachChild(mainLightNode);
           //rootNode.setRenderState( lightState );

           // Initial InputHandler
           if (handleInput) {
              input = new FirstPersonHandler(DisplaySystem.getDisplaySystem().getRenderer().getCamera(), Constants.CAMERA_MOVE_SPEED, Constants.CAMERA_TURN_SPEED);
              input.removeAllFromAttachedHandlers();
              KeyboardLookHandler lookHandler = new KeyboardLookHandler( cam, 50, 1 );
              // and nest it
              input.addToAttachedHandlers( lookHandler );
              initKeyBindings();
             
           }
           // Signal to the renderer that it should keep track of rendering
           // information.
           DisplaySystem.getDisplaySystem().getRenderer().enableStatistics(true);
          
           initMouse();
          

           // Set camera location
         cam.setLocation(Constants.CAMERA_START_POSITION);
         cam.lookAt(Constants.CAMERA_START_VIEW, Vector3f.UNIT_Y);   
         cam.update();
            
         //create the actionManager
          // actionManager = new ActionManager(desktopState,rootNode);
         
           // Finish up
           rootNode.updateRenderState();
           rootNode.updateWorldBound();
           rootNode.updateGeometricState(0.0f, true); 
          
           //add the actionManager to input actions
           //MouseInput.get().addListener(actionManager);
           //KeyInput.get().addListener(actionManager);       
       }
      
       public LightState getLightState() {
          return lightState;
       }

       /*


init mouse
       *  since we want the mouse to pick products we need to init it to do that
       */
      private void initMouse() {
         
          // Create a new mouse. Restrict its movements to the display screen.
           absolutMouse = new AbsoluteMouse("The Mouse", display.getWidth(), display
                   .getHeight());       
           // Get the mouse input device and assign it to the AbsoluteMouse
           // Move the mouse to the middle of the screen to start with
           absolutMouse.setLocalTranslation(new Vector3f(display.getWidth() / 2, display
                   .getHeight() / 2, 0));
           // Assign the mouse to an input handler
           absolutMouse.registerWithInputHandler( input );
          
           //disable aim mouse
             (( FirstPersonHandler ) input ).getMouseLookHandler().setEnabled( false );
      }
      
       private void initKeyBindings() {
          
          //
registed the basic movments
          
          KeyBindingManager keyboard = KeyBindingManager.getKeyBindingManager();
          
          keyboard.set( "forward", KeyInput.KEY_UP );
           keyboard.set( "backward", KeyInput.KEY_DOWN);
           keyboard.set( "strafeLeft", KeyInput.KEY_A );
           keyboard.set( "strafeRight", KeyInput.KEY_D );
           keyboard.set( "lookUp", KeyInput.KEY_W );
           keyboard.set( "lookDown", KeyInput.KEY_S );
           keyboard.set( "turnRight", KeyInput.KEY_RIGHT );
           keyboard.set( "turnLeft", KeyInput.KEY_LEFT );
           keyboard.set( "elevateUp", KeyInput.KEY_Q);
           keyboard.set( "elevateDown", KeyInput.KEY_Z);
          
          //
           /** Assign key P to action "toggle_pause". */
           KeyBindingManager.getKeyBindingManager().set("toggle_pause",
                   KeyInput.KEY_P);
           /** Assign key T to action "toggle_wire". */
           KeyBindingManager.getKeyBindingManager().set("toggle_wire",
                   KeyInput.KEY_T);
           /** Assign key L to action "toggle_lights". */
           KeyBindingManager.getKeyBindingManager().set("toggle_lights",
                   KeyInput.KEY_L);
           /** Assign key B to action "toggle_bounds". */
           KeyBindingManager.getKeyBindingManager().set("toggle_bounds",
                   KeyInput.KEY_B);
           /** Assign key N to action "toggle_normals". */
           KeyBindingManager.getKeyBindingManager().set("toggle_normals",
                   KeyInput.KEY_N);
           /** Assign key C to action "camera_out". */
           KeyBindingManager.getKeyBindingManager().set("camera_out",
                   KeyInput.KEY_C);
           KeyBindingManager.getKeyBindingManager().set("screen_shot",
                   KeyInput.KEY_F1);
           //KeyBindingManager.getKeyBindingManager().set("exit",
             //      KeyInput.KEY_ESCAPE);
           KeyBindingManager.getKeyBindingManager().set("parallel_projection",
                   KeyInput.KEY_F2);
           KeyBindingManager.getKeyBindingManager().set("toggle_depth",
                   KeyInput.KEY_F3);
           KeyBindingManager.getKeyBindingManager().set("mem_report",
                   KeyInput.KEY_R);
           KeyBindingManager.getKeyBindingManager().set("toggle_mouse",
                           KeyInput.KEY_M);
       }

       public void update(float tpf) {
          InputSystem.update();
          super.update(tpf);
          
          //update action Manager
          //actionManager.update();
          
          Vector3f cameraPositionBeforeChange= new Vector3f(cam.getLocation());
          
          //if(actionManager.isFocusOff())
             //return;
          
          
           // Update the InputHandler
          if (input != null) {
             input.update(tpf);
          
              /** If toggle_pause is a valid command (via key p), change pause. */
              if (KeyBindingManager.getKeyBindingManager().isValidCommand(
                      "toggle_pause", false)) {
                  pause = !pause;
              }
             
              if (pause)
                  return;
          }
          
          //force camera hight
          forceCemraHight();
          
          Vector3f cameraPositionAfterChange = new Vector3f(cam.getLocation());
          //actionManager.setLatsCameraPosition(cameraPositionBeforeChange);
          if(cameraPositionBeforeChange.distance(cameraPositionAfterChange) != 0 ){
             //actionManager.setLatsCameraPosition(cameraPositionBeforeChange);          
          }
           // Update the geometric state of the rootNode
           rootNode.updateGeometricState(tpf, true);

           if (input != null) {
              /** If toggle_wire is a valid command (via key T), change wirestates. */
              if (KeyBindingManager.getKeyBindingManager().isValidCommand(
                      "toggle_wire", false)) {
                  wireState.setEnabled(!wireState.isEnabled());
                  rootNode.updateRenderState();
              }
              /** If toggle_lights is a valid command (via key L), change lightstate. */
              if (KeyBindingManager.getKeyBindingManager().isValidCommand(
                      "toggle_lights", false)) {
                  lightState.setEnabled(!lightState.isEnabled());
                  rootNode.updateRenderState();
              }
              /** If toggle_bounds is a valid command (via key B), change bounds. */
              if (KeyBindingManager.getKeyBindingManager().isValidCommand(
                      "toggle_bounds", false)) {
                  showBounds = !showBounds;
              }
              /** If toggle_depth is a valid command (via key F3), change depth. */
              if (KeyBindingManager.getKeyBindingManager().isValidCommand(
                      "toggle_depth", false)) {
                  showDepth = !showDepth;
              }
      
              if (KeyBindingManager.getKeyBindingManager().isValidCommand(
                      "toggle_normals", false)) {
                  showNormals = !showNormals;
              }
              /** If camera_out is a valid command (via key C), show camera location. */
              if (KeyBindingManager.getKeyBindingManager().isValidCommand(
                      "camera_out", false)) {
                
              }
              if (KeyBindingManager.getKeyBindingManager().isValidCommand(
                      "screen_shot", false)) {
                  DisplaySystem.getDisplaySystem().getRenderer().takeScreenShot(
                          "SimpleGameScreenShot");
              }
              if (KeyBindingManager.getKeyBindingManager().isValidCommand(
                      "parallel_projection", false)) {
                  if (DisplaySystem.getDisplaySystem().getRenderer().getCamera()
                          .isParallelProjection()) {
                      cameraPerspective();
                  } else {
                      cameraParallel();
                  }
              }             
              if (KeyBindingManager.getKeyBindingManager().isValidCommand(
                              "toggle_mouse", false)) {
                          MouseInput.get().setCursorVisible(!MouseInput.get().isCursorVisible());                        
                      }
      
              if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit",
                      false)) {
                  System.exit(0);
              }
           }
       }

       protected void cameraPerspective() {
           DisplaySystem display = DisplaySystem.getDisplaySystem();
           cam = display.getRenderer().getCamera();
           cam.setFrustumPerspective(45.0f, (float) display.getWidth()
                   / (float) display.getHeight(), 1, 10000);
           cam.setParallelProjection(false);
           cam.update();
       }

       protected void cameraParallel() {
           DisplaySystem display = DisplaySystem.getDisplaySystem();
           cam = display.getRenderer().getCamera();
           cam.setParallelProjection(true);
           float aspect = (float) display.getWidth() / display.getHeight();
           cam.setFrustum(-100.0f, 1000.0f, -50.0f * aspect, 50.0f * aspect,
                   -50.0f, 50.0f);
           cam.update();
       }

       public void render(float tpf) {      
          super.render(tpf);       
           // Render the rootNode
           DisplaySystem.getDisplaySystem().getRenderer().draw(rootNode);

           if (showBounds) {
               Debugger.drawBounds(rootNode, DisplaySystem.getDisplaySystem()
                       .getRenderer(), true);
           }

           if (showNormals) {
               Debugger.drawNormals(rootNode, DisplaySystem.getDisplaySystem()
                       .getRenderer());
           }

           if (showDepth) {
               DisplaySystem.getDisplaySystem().getRenderer().renderQueue();
               Debugger.drawBuffer(Texture.RTT_SOURCE_DEPTH, Debugger.NORTHEAST,
                       DisplaySystem.getDisplaySystem().getRenderer());
           }
       }

       public void cleanup() {
          
       }
      
       /**
       * forceCemraHight force the camera to be on the same hight
       *
       */
      private void forceCemraHight() {
         //
force camera hight to be 5
         Camera cam=DisplaySystem.getDisplaySystem().getRenderer().getCamera();
         Vector3f cameraLoc  = cam.getLocation();
         cameraLoc.setY(Constants.CAMERA_HEIGHT);
         cam.setLocation(cameraLoc);
         //
   
      }
      
      public Node getRootNode(){
         return mainLightNode;
      }

      public InputHandler getInputHandler(){
         return input;
      }
}


<-- first post



Moshad, in Testing.java you might want to add a Thread.sleep(some short amount of time) like so:



   // Wait for the gameStateManager to be created
   while(!testing.isImplemented()) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException ex) {}
        }



That way your computer won't freak out while you are waiting for the GameStateManager to init and it will init a lot faster since the while loop isn't eating all of the processor time anymore.

Has this been rolled into the jME 2.0 code yet?  It also seems like there should be a better way to do this.  But, what do I know, I am new.  :)

Sorry to wake up an old thread, but I'm also struggling with this problem at the moment.



I am implementing an molecule viewer with jME using StandardGame and need to integrate it into Swing.



Any help would be greatly appreciated.

menkey said:

<-- first post

Moshad, in Testing.java you might want to add a Thread.sleep(some short amount of time) like so:


   // Wait for the gameStateManager to be created
   while(!testing.isImplemented()) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException ex) {}
        }



That way your computer won't freak out while you are waiting for the GameStateManager to init and it will init a lot faster since the while loop isn't eating all of the processor time anymore.

Has this been rolled into the jME 2.0 code yet?  It also seems like there should be a better way to do this.  But, what do I know, I am new.  :)


thanks for the tip :)
Methius said:

Sorry to wake up an old thread, but I'm also struggling with this problem at the moment.

I am implementing an molecule viewer with jME using StandardGame and need to integrate it into Swing.

Any help would be greatly appreciated.


Try to use my code as a base , eventually it worked great for me but I did had to change many things  to make it work better but it is a good base .
Anyhowhere is a molecule editor that have been made with jme http://www.molinspiration.com/jme/ .
if it's already exist why do you need to make a new one ?

Hi moshad,



What kind of improvements did you do?

Care to post the new versions of the code here maybe?



Thanks!

Regards,

Alex

pokemoen said:

Hi moshad,

What kind of improvements did you do?
Care to post the new versions of the code here maybe?

Thanks!
Regards,
Alex

belive me I would have if I had the time for it , but I really don't :( .
most of the changes I made where for my projects so I can't post it here and I can't remeber all the changes , one that I do remember was to do with mouse picking , since awt axis is differant then JME's a convertion must be made
(I'fe found about it here in the forum :) ).
. I would have to make another generic code that would fit to every project.
why won't you start from what I've posted see how it goes and if you have any problems send me questions I will try to help as much as I can.

Okay, I'll see how it works out and post back my findings/questions/code here.



Regards,

Alex

moshad said:

Methius said:

Sorry to wake up an old thread, but I'm also struggling with this problem at the moment.

I am implementing an molecule viewer with jME using StandardGame and need to integrate it into Swing.

Any help would be greatly appreciated.


Try to use my code as a base , eventually it worked great for me but I did had to change many things  to make it work better but it is a good base .
Anyhowhere is a molecule editor that have been made with jme http://www.molinspiration.com/jme/ .
if it's already exist why do you need to make a new one ?



Different JME. :)
renanse said:

moshad said:

Methius said:

Sorry to wake up an old thread, but I'm also struggling with this problem at the moment.

I am implementing an molecule viewer with jME using StandardGame and need to integrate it into Swing.

Any help would be greatly appreciated.


Try to use my code as a base , eventually it worked great for me but I did had to change many things  to make it work better but it is a good base .
Anyhowhere is a molecule editor that have been made with jme http://www.molinspiration.com/jme/ .
if it's already exist why do you need to make a new one ?



Different JME. :)


LOL right I didn't figure it out at the first place :) JME stants for Java Molecule Editor , I thought  that the preFix of JME before the  Molecule Editor would suggest it was made with this engian  :) , I need to pay more attention

Hi folks, waking up an old thread here.



I'm working on a swing application that will have an embedded canvas in which we would like to render a jME scene. This thread was very useful in getting a prototype up and running.



However, I'm still interested in using a Game implementation to drive the render loop, mainly because we'd like to be able to control frame rates and animation timing, something a StandardGame implementation does well. I was reading on the wiki ( http://www.jmonkeyengine.com/wiki/doku.php?id=game_types  & http://www.jmonkeyengine.com/wiki/doku.php?id=displaysystem ) that a headless window should allow us to create a canvas for embedding in a Swing/AWT ui, but I cannot find any further details on how to use this.



So, cutting to the chase, my question is how do I go about using a headless window and a game instance to drive the rendering of a canvas in a Swing application?

I’ve posted my last “beta” implementation to a so called “StandardCanvasGame” class at this topic: http://www.jmonkeyengine.com/jmeforum/index.php?topic=9851.0.



I decided to separate the canvas standard game implementation from the StandardGame class to avoid confusion and problems…such implementations are to much distinct and I think they deserve separated classes.



With this class, a very similar behaviour to StandardGame and, for the newbies (like me) that always wanted to implement StandardGames that renderes in Canvas, I think this could be a start…



Any correction and feedback is always very much appreciated! :slight_smile:

you get a NullPointerException at the line:


isSupported = GLContext.getCapabilities().GL_EXT_framebuffer_object;



Which means GLContext.getCapabilities() returns null.
Either StandardGame.update() is not called in the OpenGL thread in your version, or the GLContext is not initialized/available.

Just want to say thanks for the implementation!