3rd party GUI w/ jME

Ah so you don't even need a texture, just a TextureState?



There's some OpenGL tracing utilities, but in this case maybe you could just look in LWJGLTextureState.java

Though, if you really don't need a texture and just a TextureState… I dunno what could cause it.

Ah so you don't even need a texture, just a TextureState?


Yes. Well actually, the RenderState has to be assigned to the box to make it work

      
TextureState ts = display.getRenderer().createTextureState();
box.setRenderState(ts);



Removing box.setRenderState(ts); causes FengGUI to fail with the textures. Any new ideas? :)

Johannes

Fail how?  Exception, or no show?

Also, do you do an updateRenderStates on your scene graph after you've got it setup?  The default texturestate would be assigned then.

Fail how?  Exception, or no show?


no show. The textures aren't mapped at all. The rest basically lines and a few quads with plain colors assigned is rendered correctly. The image below will give you an impression of the problem:



Also, do you do an updateRenderStates on your scene graph after you've got it setup?  The default texturestate would be assigned then.


Yes. Here's my code:


      rootNode = new Node("rootNode");
      ZBufferState buf = display.getRenderer().createZBufferState();
      buf.setEnabled(true);
      buf.setFunction(ZBufferState.CF_LEQUAL);
      rootNode.setRenderState(buf);
      PointLight light = new PointLight();
      light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
      light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
      light.setLocation(new Vector3f(100, 100, 100));
      light.setEnabled(true);
      /** Attach the light to a lightState and the lightState to rootNode. */
      lightState = display.getRenderer().createLightState();
      lightState.setEnabled(true);
      lightState.attach(light);
      rootNode.setRenderState(lightState);
      
      box = new Box("The Box", new Vector3f(-1, -1, -1), new Vector3f(3f, 3f, 3f));

      Quaternion rot = new Quaternion();
      rot.fromAngles(FastMath.DEG_TO_RAD*25, FastMath.DEG_TO_RAD*25, 0.0f);
      box.setLocalRotation(rot);
      
      rootNode.attachChild(box);
      
      rootNode.updateGeometricState(0.0f, true);
      rootNode.updateRenderState();
      
      // Create the GUI
      initGUI();



My render loop method reads:


   protected void render(float interpolation)
   {

      display.getRenderer().clearBuffers();

      display.getRenderer().draw(rootNode);

      //Renderer.clearCurrentStates();
      //Renderer.clearCurrentStates();
   //   Renderer.applyDefaultStates();

      disp.display(); // <== That's the FengGUI render call!
   }



Thanks for helping me on this by the way!

Johannes

Hmm, not sure.  I see in fenggui that you enable texture2d, bind the texture, then call to render tris or quads…  Having a texturestate in there with no textures only calls:

                for (int i = 0; i < numFixedTexUnits; i++) {
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + i);
                    GL11.glDisable(GL11.GL_TEXTURE_2D);
                    currentTexture[i] = null;
                }



Which since you are enabling texture2d yourself, should be meaningless.  The only reason I can think of for no textures would be a disabled flag or missing texture coordinates...  Perhaps a consequence of mixing our using of arrays with your use of glStart/glEnd?

You can debug OpenGL calls with programs like this:

http://glintercept.nutty.org/

Good news everyone. llama was right after all. The (re-)activation of the TEXTURE0 unit does the trick. Simply insert



GL13.glActiveTexture(GL13.GL_TEXTURE0);



before you render FengGUI. We will call that per default in FengGUI in future releases.



Here is the proof that it works :slight_smile:









Johannes

Awesome! I will definitely use FengGUI for my current project.

Ah yes…

to be honest, not exactly what I thought it was, but indeed it's a small thing (and related to texture units :))



FengGUI is a pretty small lib too isn't it (as a binary only)? Does it have any other dependecies (aside from LWJGL)?

The only dependency I've found that it needed was on the jcore library, specifically the Signals, which it uses for event delivery.

I'm trying to convince Schabby to do all the event delivery ourselves, instead of using jcore  :stuck_out_tongue:

hmm… doesn't anybody use BUI? i just evaluated it a bit and actually like it very much. currently i'm about to port my whole GUI to BUI.

first i started to write my own gui (wanted something more 'lightweight' than swing) but i ended doing the same that BUI does (except BUI does it better in some aspects).

i noticed there are almost no examples for BUI, which - i suppose - is one of the reasons BUI is not so popular. after i manage to port my GUI to BUI i could try to write some basic BUI tutorials if there is any need for such things. (maybe samskivert could help here)

i'd be greatful for any pointer if anyone knows about the existence of such tutorials (currently i might need them myself)

Have you taken a look at FengGUI? Any reason you prefer BUI to it?

Is BUI up to date with what they use in Bang! Howdy?

@llama: i supposes so. i see checkins in the svn trunk quite often

@darkfrog:

i have to admit i gave feggui just a brief look. i suppose i'll have to evaluate fenggui better, but that's not the point. :slight_smile: i just asked if aynyone uses bui.

but are there any reasons to preffer fenggui over bui? (except the bad class member naming used in bui  :smiley: - still i found some strange comments in fenggui too: "This class has never been tested or used :P" ) fenggui and bui are quite the same except bui builds on top of jme and uses a css-like style description for its visual components. oh, and there's a lwjgl dependency in bui (it uses lwjgl directly).

did anyone do an objective comparison between these two? as in performance, ease of use, dependencies and extensibility? i suppose this would be very interesting for everyone who doesn't want to use swing in their app.

Any drag n drop with fengui ? Doesnt seem so.

@Todi: I haven't tried it myself, but there are classes in there that are supposed to support DnD.



@All: I'm currently working on a tutorial that demonstrates basic interaction between FengGUI and jME.

I'm also working on a class that will do all of the heavy lifting of event delivery between the two frameworks.

I'll post an update when that's in working order.



Also thought I'd mention that FengGUI is under heavy development, so expect to see lots of improvements

in the near future.  The activity on the FengGUI developers mailing list is pretty heavy.

I'm pretty interested in this, I've used the JmeDesktop stuff a bit, and it's impressive, but it just doesn't seem as suitable/efficient as it should be, it's also somewhat cumbersome/tricky at times, I assume performance wise fengUI will stomp on the swing stuff (due to swing being swing, not due to how it's implemented in jME) but is it possibly easier to work with too?



I'll be watching for this tutorial.

i'll be waiting for that tut too because i have no idea how to integrate fenggui with jme anyways.

…in the meantime i'll port my gui to bui(because i already started). if in the end fenggui turns out to be more performant and to integrate good with jme i'll do another port.

to Schabby or anybody

can you provide code for use jme and fengui (not part)?

i'm mean where and how you greate gui. how you create root node and resolve mouse input and etc. Thank's



i'm try but only i'm has it's top menu, 3d cube and no mouse :frowning:

ok i'm do it :)))) sorry for panic message :slight_smile:

for undestanding how do what:


/*
 * FengGUI - Java GUIs in OpenGL (http://fenggui.dev.java.net)
 *
 * Copyright (c) 2005, 2006 FengGUI Project
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details:
 * http://www.gnu.org/copyleft/lesser.html#TOC3
 *
 * $Id: ExampleBasisLWJGL.java,v 1.15 2006/09/19 18:45:12 charlierby Exp $
 */
package org.fenggui.example;

import org.fenggui.render.lwjgl.EventHelper;
import org.fenggui.render.lwjgl.LWJGLBinding;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.glu.GLU;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.ZBufferState;
import com.jme.scene.state.LightState;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.system.DisplaySystem;
import com.jme.math.Vector3f;
import com.jme.math.Quaternion;
import com.jme.math.FastMath;
import com.jme.light.PointLight;

/**
 * Examplary LWJGL app that shows the 'Everyhing' example.
 *
 *
 * @todo Comment this class... #
 *
 * @author Johannes Schaback, last edited by $Author: charlierby $, $Date: 2006/09/19 18:45:12 $
 * @version $Revision: 1.15 $
 */
public class ExampleBasisLWJGL {

    public org.fenggui.Display desk = null;
    private int lastButtonDown = -1;

    Node rootNode;
    Camera cam = null;
    protected DisplaySystem display;

    public ExampleBasisLWJGL() {
        execute();
    }

    public static void main(String[] args) {
        new ExampleBasisLWJGL().execute();
        System.exit(0);
    }

    private void readBufferedKeyboard() {

          //check keys, buffered
          Keyboard.poll();

          // @todo 'autofire' for mousePressed not supported yet,
          // because we read the events from the buffer. Polling
          // the keyboard like Keyboard.isKeyDown(Keyboard.KEY_A),
          // Keyboard.isKeyDown(Keyboard.KEY_B),
          // Keyboard.isKeyDown(Keyboard.KEY_C),
          // Keyboard.isKeyDown(Keyboard.KEY_D) and so on
          // is quite cumbersome (it's a solution though) #
          while (Keyboard.next()) {
              if(Keyboard.isKeyDown(Keyboard.getEventKey())) {
                  desk.fireKeyPressedEvent(Keyboard.getEventCharacter(), EventHelper.mapEventKey());
              } else {
                  desk.fireKeyReleasedEvent(Keyboard.getEventCharacter(), EventHelper.mapEventKey());
              }
            }


    }

      /**
       * reads a mouse in buffered mode
       */
      private void readBufferedMouse() {
          int x = Mouse.getX();
          int y = Mouse.getY();

          boolean hitGUI = false;


          // @todo the click count is not considered in LWJGL! #

          if(lastButtonDown != -1 && Mouse.isButtonDown(lastButtonDown)) {
              hitGUI |= desk.fireMouseDraggedEvent(x, y,
                      EventHelper.getMouseButton(lastButtonDown));
          } else {
              if(Mouse.getDX() != 0 || Mouse.getDY() != 0)
                  hitGUI |= desk.fireMouseMovedEvent(x, y);

              if(lastButtonDown != -1) {
                  hitGUI |= desk.fireMouseReleasedEvent(x, y,
                          EventHelper.getMouseButton(lastButtonDown), 1);
                  lastButtonDown = -1;
              }
                while(Mouse.next()) {
                    if(Mouse.getEventButton() != -1 && Mouse.getEventButtonState()) {
                        lastButtonDown = Mouse.getEventButton();
                        hitGUI |= desk.fireMousePressedEvent(x, y,
                                EventHelper.getMouseButton(lastButtonDown), 1);
                    }
                    int wheel = Mouse.getEventDWheel();
                    if(wheel != 0) {
                        hitGUI |= desk.fireMouseWheel(x, y, wheel > 0);
                    }
                  }
          }
      }




    /**
     *
     */
    public void execute() {
        try {
            initEverything();
        } catch (LWJGLException le) {
            le.printStackTrace();
            System.out.println("Failed to initialize Gears.");
            return;
        }

        mainLoop();

        destroy();
    }

    /**
     *
     */
    private void destroy() {
        Display.destroy();
    }

    private void mainLoop() {
        while (!Display.isCloseRequested()) {

            readBufferedKeyboard();
            readBufferedMouse();

            glRender();
            Display.update();
        }
    }

    /**
     *
     */
    private void glRender() {
//        GL11.glLoadIdentity();
//        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

        display.getRenderer().clearBuffers();
//        GLU.gluLookAt(10, 8, 8, 0, 0, 0, 0, 0, 1);

       // GL11.glRotatef(rotAngle, 1f, 1f, 1);
      //  GL11.glColor3f(0.42f, 0.134f, 0.44f);

       // rotAngle += 0.5;
        display.getRenderer().draw(rootNode);

        // draw GUI stuff
        desk.display();


        // hmm, i think we need to query the mouse pointer and
        // keyboard here and call the according
        // desk.mouseMoved, desk.keyPressed, etc.
        // methods...

    }

    /**
     *
     */
    public final void initEverything() throws LWJGLException {
        initMainNode();

        Display.setDisplayMode(new DisplayMode(800, 600));
        Display.setTitle("Gears");
//        Display.create();

//        glInit(800, 600);

        // initialize keyboard
//        Keyboard.create();



        // build the gui
        buildGUI();
    }

    private void initMainNode() {
         //todo init
        display = DisplaySystem.getDisplaySystem("LWJGL");
        /** Create a window with the startup box's information. */
        display.createWindow(
                800,
                600,
                16,
                60,
                false);

        /** Create a camera specific to the DisplaySystem that works with
         * the display's width and height*/
 cam = display.getRenderer().createCamera( display.getWidth(),
            display.getHeight() );
cameraPerspective();
Vector3f loc = new Vector3f( 0.0f, 0.0f, 25.0f );
Vector3f left = new Vector3f( -1.0f, 0.0f, 0.0f );
Vector3f up = new Vector3f( 0.0f, 1.0f, 0.0f );
Vector3f dir = new Vector3f( 0.0f, 0f, -1.0f );
/** Move our camera to a correct place and orientation. */
cam.setFrame( loc, left, up, dir );
/** Signal that we've changed our camera's location/frustum. */
cam.update();
/** Assign the camera to this renderer. */
display.getRenderer().setCamera( cam );
//                        Node rootNode = new Node( "rootNode" );
rootNode = new Node("rootNode");
ZBufferState buf = display.getRenderer().createZBufferState();
buf.setEnabled(true);
buf.setFunction(ZBufferState.CF_LEQUAL);
rootNode.setRenderState(buf);
PointLight light = new PointLight();
light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
light.setLocation(new Vector3f(100, 100, 100));
light.setEnabled(true);
/** Attach the light to a lightState and the lightState to rootNode. */
LightState lightState = display.getRenderer().createLightState();
lightState.setEnabled(true);
lightState.attach(light);
rootNode.setRenderState(lightState);

Box box = new Box("The Box", new Vector3f(-1, -1, -1), new Vector3f(3f, 3f, 3f));

Quaternion rot = new Quaternion();
rot.fromAngles(FastMath.DEG_TO_RAD*25, FastMath.DEG_TO_RAD*25, 0.0f);
box.setLocalRotation(rot);

rootNode.attachChild(box);

rootNode.updateGeometricState(0.0f, true);
rootNode.updateRenderState();
    }


    public void buildGUI()
    {
        // init. the LWJGL Binding
        LWJGLBinding binding = new LWJGLBinding();

        // init the root Widget, that spans the whole
        // screen (i.e. the OpenGL context within the
        // Microsoft XP Window)
        desk = new org.fenggui.Display(binding);
        // build a simple test FengGUI-Window
        Everything everything = new Everything();
        everything.buildGUI(desk);
    }

    private void glInit(int width, int height) {
        // Go into orthographic projection mode.
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        GLU.gluOrtho2D(0, width, 0, height);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glLoadIdentity();
        GL11.glViewport(0, 0, width, height);

        //set clear color to ... ugly
        GL11.glClearColor(0.1f, 0.5f, 0.2f, 0.0f);
        //sync frame (only works on windows)
        Display.setVSyncEnabled(true);
    }

    protected void cameraPerspective() {
        cam.setFrustumPerspective( 45.0f, (float) display.getWidth()
                / (float) display.getHeight(), 1, 1000 );
        cam.setParallelProjection( false );
        cam.update();
    }
}