JME FengGUI Applet

  These day, I am trying to integrate FengGUI on web, but I find it some problem. At frist , i find someone ask the same question: http://www.fenggui.org/forum/index.php?action=printpage;topic=247.0, but i cant not resolve in my test, Following is my test code:

   

   public class AppletTestRotateAboutPoint  extends SimpleJmeApplet:

   {

    …

    private void creatFengGUI()

   {

       XMLTheme.TYPE_REGISTRY.register("Texture", LWJGLTexture.class);

       fengdisp = new org.fenggui.Display(new AWTGLCanvasBinding((AWTGLCanvas)glCanvas));

       if(fengdisp != null)

       {

           FengJMEHandler fenguiInput  = new FengJMEHandler(fengdisp);

           AWTKeyInput.get().addListener(fenguiInput);

           AWTMouseInput.get().addListener(fenguiInput);



           buildUI();

           MouseInput.get().setCursorVisible(true);

       }

       else

       {

           System.out.println("creat fengdisp err , fengdisp == null");

       }

   }



   private void buildUI()

   {

       int width = DisplaySystem.getDisplaySystem().getWidth();

       int height = DisplaySystem.getDisplaySystem().getHeight();



       try {

           theme =  new DefaultTheme();

           FengGUI.initPrototypes();

           FengGUIOptional.initOptional();

       }

       catch(Exception e) {

           System.out.println("load XMLTheme Error : " + e.getMessage());

       }



       FengGUI.setTheme(theme);

//        Everything everything = new Everything();

//        everything.buildGUI(fengdisp);

       System.err.println("DisplaySystem : " + width + ", " + height);



       final Window frame = FengGUI.createWindow(fengdisp, false, false, false, false);

       frame.setSize(300, 200);

       frame.setXY(width / 2 - frame.getWidth() / 2, height / 2

               - frame.getHeight() / 2);



       frame.getAppearance().add(new PlainBackground(Color.GRAY));



       frame.setTitle("_Menu");

       frame.setLayoutManager(new GridLayout(6, 1));



       Button intro = FengGUI.createButton(frame, "Credits");

       intro.addButtonPressedListener(new IButtonPressedListener() {

           public void buttonPressed(final ButtonPressedEvent e) {

               System.err.println("Credits action");

           }

       });



       Button start = FengGUI.createButton(frame, "Play");

       start.addButtonPressedListener(new IButtonPressedListener() {

           public void buttonPressed(final ButtonPressedEvent e) {

               System.err.println("play action");

           }

       });



       Button settings = FengGUI.createButton(frame, "Settings");

       settings.addButtonPressedListener(new IButtonPressedListener() {

           public void buttonPressed(final ButtonPressedEvent e) {

               System.err.println("setting action");

           }

       });



       fengdisp.layout();

   }



  …



 }

  These is all the gui codes , the member  

the user shatterblast has recently been working on a fengGUI integration with JME2. Maybe if you ask him personally he will know a way to help.

  Thank you,  my prj is use JME2.0 , FengGUI_Alpha1.2 and LWJGL21, and now I start to rewriter LWJGLCanvas for a test.

 

I have two suggestions that may aid you.  First, FengGUI code sharing space inside a class method along with JME 2 code should politely go below and behind any existing JME 2 code in that same method's organization.  Second, texture states need setting to "default."



Please examine the following code in how it may benefit you.  Changing a few names may become a requirement.  It should remain compatible with your own code.



*
 * Copyright (c) 2003-2009 jMonkeyEngine
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
 *   may be used to endorse or promote products derived from this software
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package jME2_and_FengGUI_Integration;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

import org.fenggui.Display;
import org.fenggui.binding.render.lwjgl.LWJGLBinding;

import com.jme.app.SimpleGame;
import com.jme.image.Texture;
import com.jme.input.MouseInput;
import com.jme.math.Vector3f;
import com.jme.scene.state.TextureState;

/**
 * AppStart_Edit
 *
 * @author Original author: Unknown
 * @author Modification by Wesley Lange, " shatterblast "
 */

public class AppStart_Edit extends SimpleGame {
   public static void main(String[] args) {
      AppStart_Edit app = new AppStart_Edit();
      app.setConfigShowMode(ConfigShowMode.AlwaysShow);
      app.findNatives();
      app.start();
   }

   Display disp;

   TextureState defaultTextureState;

   public void findNatives() {

      /*
       * Set lwjgl library path so that LWJGL finds the natives depending on
       * the OS.
       */
      String osName = System.getProperty("os.name");
      // Get .jar dir. new File(".") and property "user.dir" will not work if
      // .jar is called from
      // a different directory, e.g. java -jar /someOtherDirectory/myApp.jar
      String nativeDir = "";
      try {
         nativeDir = new File(this.getClass().getProtectionDomain()
               .getCodeSource().getLocation().toURI()).getParent();
      } catch (URISyntaxException uriEx) {
         try {
            // Try to resort to current dir. May still fail later due to bad
            // start dir.
            uriEx.printStackTrace();
            nativeDir = new File(".").getCanonicalPath();
         } catch (IOException ioEx) {
            // Completely failed
            System.out
                  .println("Failed to locate native library directory. Error:n"
                        + ioEx.toString());
            ioEx.printStackTrace();
            System.exit(-1);
         }
      }

      // Append library subdir
      nativeDir += File.separator + "native" + File.separator;
      if (osName.startsWith("Windows")) {
         nativeDir += "windows";
      } else if (osName.startsWith("Linux") || osName.startsWith("FreeBSD")) {
         nativeDir += "linux";
      } else if (osName.startsWith("Mac OS X")) {
         nativeDir += "macosx";
      } else if (osName.startsWith("Solaris") || osName.startsWith("SunOS")) {
         nativeDir += "solaris";
      } else {
         System.out.println("Unsupported OS: " + osName + ". Exiting.");
         System.exit(-1);
      }
      System.setProperty("org.lwjgl.librarypath", nativeDir);
   }

   // Pieces together the beginnings of FengGUI.
   protected void initGUI() {
      disp = new org.fenggui.Display(
            new org.fenggui.binding.render.lwjgl.LWJGLBinding());

      input = new FengJMEInputHandler(disp);

      Everything everything = new Everything();
      everything.buildGUI(disp);

      disp.layout();

   }

   @Override
   protected void simpleInitGame() {
      Texture defTex = TextureState.getDefaultTexture().createSimpleClone();
      defaultTextureState = display.getRenderer().createTextureState();
      defTex.setScale(new Vector3f(1, 1, 1));
      defaultTextureState.setTexture(defTex);

      disp = new Display(new LWJGLBinding());
      input = new FengJMEInputHandler(disp);

      initGUI();

      MouseInput.get().setCursorVisible(true);
   }

   // Seems necessary for sending the texture verification to the OpenGL
   // rendering thread.
   // Otherwise, the GUI will not show.
   @Override
   protected void simpleRender() {
      defaultTextureState.apply();

      disp.display();
   }
}

It's best to use SimpleApplet instead of SimpleJmeApplet. The latter used to implement the only way to embed applets into a web page, and there are some severe differences between the way SimpleJmeApplet works and the way SimpleGame works.



SimpleApplet is an enhancement that uses some new features of LWJGL, and the way it works is almost identical to the way SimpleGame works. I don't think anyone's benchmarked this yet, but it's also supposed to be faster. I tried integrating JmeDesktop, FengGUI and GBUI with SimpleJmeApplet, and things were a lot more messy than with the new applets (most of the issues were due to input differences).



As an added incentive to use the new applets: switching SimpleGame to SimpleJmeApplet and back requires a lot of changes to your code, while switching SimpleGame to SimpleApplet shouldn't require any changes at all.

Wizem said:

It's best to use SimpleApplet instead of SimpleJmeApplet. The latter used to implement the only way to embed applets into a web page, and there are some severe differences between the way SimpleJmeApplet works and the way SimpleGame works.


I might consider that for the future on my project.

Wizem said:

SimpleApplet is an enhancement that uses some new features of LWJGL, and the way it works is almost identical to the way SimpleGame works. I don't think anyone's benchmarked this yet, but it's also supposed to be faster. I tried integrating JmeDesktop, FengGUI and GBUI with SimpleJmeApplet, and things were a lot more messy than with the new applets (most of the issues were due to input differences).


I would think that trying different game states would help resolve the issue.  In that way, enabling and disabling various GUIs as necessary could help.  You could even go so far as to have one fade away while another comes up.

Since I only use FengGUI now, I just put the code at the most bottom of the " initGame " method.  After that, I put a couple of items into the bottom of the various render and update methods.  While I don't use a game state for FengGUI, it works still since the RenderPass queue gets to FengGUI at the very last in the cycle.

Wizem said:

As an added incentive to use the new applets: switching SimpleGame to SimpleJmeApplet and back requires a lot of changes to your code, while switching SimpleGame to SimpleApplet shouldn't require any changes at all.


That could have an added benefit of JME 3 compatibility in the future.

    Thx for anyone's  sugs!  In fact, i use SimpleJmeApplet in prj, these days i had find out why fenggui dint work! It because fenggui's display need to be render in some place , not in simpleAppletUpdate(); And we need to update some codes in order to process the input such as mouse or kb inputs!

    Today , I find use TextureState.setTexture(ts1, 0), TextureState.setTexture(ts2, 1) will make fenggui Textrue  breakdown! Has someone find out the bug!?

   

   

wooyq said:

    Thx for anyone's  sugs!  In fact, i use SimpleJmeApplet in prj, these days i had find out why fenggui dint work! It because fenggui's display need to be render in some place , not in simpleAppletUpdate(); And we need to update some codes in order to process the input such as mouse or kb inputs!
    Today , I find use TextureState.setTexture(ts1, 0), TextureState.setTexture(ts2, 1) will make fenggui Textrue  breakdown! Has someone find out the bug!?


It appears that SimpleApplet or SimplePassApplet will become a requirement.  SimpleJMEApplet does not allow FengJMEInputHandler to plug easily into its frame work of code.  I am working on a patch.  Hopefully, I should have it up soon.

^_^, I never user  FengJMEInputHandler! Just as you say,  it not esay to  plug it into easily into jME frame work !

I cant log into , http://shatterblast.getenjoyment.net/, does the websit work?

wooyq said:

^_^, I never user  FengJMEInputHandler! Just as you say,  it not esay to  plug it into easily into jME frame work !
I cant log into , http://shatterblast.getenjoyment.net/, does the websit work?


I haven't designed the web site for logging into yet.  I have examples posted on the web site for downloading, but it serves mainly as a "blog" right now.  Thank you for looking at it though.  The source code ironically needs updating on my web site.

However, I have a working example on the web page that says "The Integration Example."  It still has the bug I eliminated in the source code on this forum, but at least, it displays that the integration functions.  Please keep in mind that the integration code is meant for future release versions.  As such, there exists a couple of errors.

I'm still putting some effort into SimpleApplet.  I have no additional code or advice to offer.