JME2 Renderer for NiftyGUI

Great my first forum post and I have to show how totally lost I am.  :smiley:



I am presently trying to get the JME example working to see how everything work. The Strange thing is that is compiles and but for some reason nifty overlay isnt rendered. Any Ideas?

May 3, 2010 7:45:35 PM com.jme.app.BaseGame start
INFO: Application started.
May 3, 2010 7:45:35 PM com.jme.system.PropertiesGameSettings <init>
INFO: PropertiesGameSettings created
May 3, 2010 7:45:35 PM com.jme.system.PropertiesGameSettings load
INFO: Read properties
May 3, 2010 7:45:38 PM com.jme.system.PropertiesGameSettings save
INFO: Saved properties
May 3, 2010 7:45:38 PM com.jme.app.BaseSimpleGame initSystem
INFO: jME version 2.0 Stable (r4093)
May 3, 2010 7:45:38 PM com.jme.input.joystick.DummyJoystickInput <init>
INFO: Joystick support is disabled
May 3, 2010 7:45:38 PM com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
May 3, 2010 7:45:39 PM com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W: 800 H: 600 Version: 2.1.0
May 3, 2010 7:45:39 PM com.jme.app.BaseSimpleGame initSystem
INFO: Running on: RDPDD
Driver version: null
NVIDIA Corporation - GeForce 9800 GTX+/PCI/SSE2 - 3.2.0
May 3, 2010 7:45:39 PM com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
May 3, 2010 7:45:39 PM com.jme.util.lwjgl.LWJGLTimer <init>
INFO: Timer resolution: 1000 ticks per second
May 3, 2010 7:45:39 PM com.jme.scene.Node <init>
INFO: Node created.
May 3, 2010 7:45:39 PM com.jme.scene.Node <init>
INFO: Node created.
May 3, 2010 7:45:39 PM com.jme.scene.Node <init>
INFO: Node created.
May 3, 2010 7:45:39 PM com.jme.scene.Node attachChild
INFO: Child "Graph node" attached to this node "Stats node"
May 3, 2010 7:45:39 PM com.jme.renderer.lwjgl.LWJGLTextureRenderer <init>
INFO: FBO support detected.
May 3, 2010 7:45:39 PM com.jme.renderer.lwjgl.LWJGLTextureRenderer initCamera
INFO: Init RTT camera
May 3, 2010 7:45:39 PM com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
May 3, 2010 7:45:39 PM com.jme.scene.Node <init>
INFO: Node created.
May 3, 2010 7:45:39 PM com.jme.scene.Line <init>
INFO: Line created.
May 3, 2010 7:45:39 PM com.jme.renderer.lwjgl.LWJGLTextureRenderer setupTexture
INFO: setup fbo tex with id 2: 800,450
May 3, 2010 7:45:39 PM com.jme.scene.Node attachChild
INFO: Child "lineGraph" attached to this node "Graph node"
May 3, 2010 7:45:39 PM com.jme.scene.Node attachChild
INFO: Child "f4" attached to this node "Graph node"
May 3, 2010 7:45:39 PM com.jme.renderer.lwjgl.LWJGLTextureRenderer <init>
INFO: FBO support detected.
May 3, 2010 7:45:39 PM com.jme.renderer.lwjgl.LWJGLTextureRenderer initCamera
INFO: Init RTT camera
May 3, 2010 7:45:39 PM com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
May 3, 2010 7:45:39 PM com.jme.scene.Node <init>
INFO: Node created.
May 3, 2010 7:45:39 PM com.jme.renderer.lwjgl.LWJGLTextureRenderer setupTexture
INFO: setup fbo tex with id 3: 800,150
May 3, 2010 7:45:39 PM com.jme.scene.Node attachChild
INFO: Child "labelGraph" attached to this node "Graph node"
May 3, 2010 7:45:39 PM com.jme.util.resource.ResourceLocatorTool locateResource
WARNING: Unable to locate: model/grass.gif
FOUND URL: null
May 3, 2010 7:45:39 PM com.jme.util.TextureManager loadTexture
WARNING: Could not load image...  URL was null. defaultTexture used.
May 3, 2010 7:45:39 PM com.jme.scene.Node attachChild
INFO: Child "Sphere" attached to this node "rootNode"
May 3, 2010 7:45:39 PM com.jme.scene.Node <init>
INFO: Node created.
May 3, 2010 7:45:39 PM com.jmex.audio.openal.OpenALSystem setupSourcePool
INFO: max source channels: 32
May 3, 2010 7:45:39 PM de.lessvoid.nifty.Nifty loadFromFile
INFO: loadFromFile [console/console.xml]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadNiftyXml
INFO: loading new nifty xml file with schemaId [nifty.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadStyleFile
INFO: loading new nifty style xml file [console/custom-console-style.xml] with schemaId [nifty-styles.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadStyleFile
INFO: loading new nifty style xml file [nifty-default-styles.xml] with schemaId [nifty-styles.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadStyleFile
INFO: loading new nifty style xml file [fonts.xml] with schemaId [nifty-styles.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadStyleFile
INFO: loading new nifty style xml file [panel/nifty-panel.xml] with schemaId [nifty-styles.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadStyleFile
INFO: loading new nifty style xml file [button/nifty-button.xml] with schemaId [nifty-styles.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadStyleFile
INFO: loading new nifty style xml file [label/nifty-label.xml] with schemaId [nifty-styles.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadStyleFile
INFO: loading new nifty style xml file [textfield/nifty-textfield.xml] with schemaId [nifty-styles.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadStyleFile
INFO: loading new nifty style xml file [dropdown/nifty-drop-down.xml] with schemaId [nifty-styles.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadStyleFile
INFO: loading new nifty style xml file [checkbox/nifty-checkbox.xml] with schemaId [nifty-styles.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadStyleFile
INFO: loading new nifty style xml file [scrollbar/nifty-scrollbar-style.xml] with schemaId [nifty-styles.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadStyleFile
INFO: loading new nifty style xml file [scrollpanel/nifty-scrollpanel-style.xml] with schemaId [nifty-styles.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadStyleFile
INFO: loading new nifty style xml file [console/nifty-console-style.xml] with schemaId [nifty-styles.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadStyleFile
INFO: loading new nifty style xml file [listbox/nifty-listbox-style.xml] with schemaId [nifty-styles.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadControlFile
INFO: loading new nifty controls xml file [nifty-default-controls.xml] with schemaId [nifty-controls.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadControlFile
INFO: loading new nifty controls xml file [nifty-controls/nifty-button.xml] with schemaId [nifty-controls.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadControlFile
INFO: loading new nifty controls xml file [nifty-controls/nifty-checkbox.xml] with schemaId [nifty-controls.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadControlFile
INFO: loading new nifty controls xml file [nifty-controls/nifty-console.xml] with schemaId [nifty-controls.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadControlFile
INFO: loading new nifty controls xml file [nifty-controls/nifty-drop-down.xml] with schemaId [nifty-controls.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadControlFile
INFO: loading new nifty controls xml file [nifty-controls/nifty-image-select.xml] with schemaId [nifty-controls.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadControlFile
INFO: loading new nifty controls xml file [nifty-controls/nifty-textfield.xml] with schemaId [nifty-controls.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadControlFile
INFO: loading new nifty controls xml file [nifty-controls/nifty-scrollbar-control.xml] with schemaId [nifty-controls.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadControlFile
INFO: loading new nifty controls xml file [nifty-controls/nifty-scrollpanel.xml] with schemaId [nifty-controls.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadControlFile
INFO: loading new nifty controls xml file [nifty-controls/nifty-listbox.xml] with schemaId [nifty-controls.nxs]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.NiftyLoader loadNiftyXml
INFO: loaded nifty xml file with schemaId [nifty.nxs] took [60 ms]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.types.NiftyType create
INFO: debug out [0]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.types.NiftyType create
INFO: registerStyle [0]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.types.NiftyType create
INFO: registerControlDefinition [2]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.types.NiftyType create
INFO: registerEffect [0]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.types.NiftyType create
INFO: registerSound [0]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.types.NiftyType create
INFO: registerMusic [0]
May 3, 2010 7:45:39 PM de.lessvoid.nifty.loaderv2.types.ScreenType create
INFO: internal prepare screen (start) [2]
May 3, 2010 7:45:40 PM de.lessvoid.nifty.loaderv2.types.ScreenType create
INFO: internal create screen (start) [280]
May 3, 2010 7:45:40 PM de.lessvoid.nifty.loaderv2.types.NiftyType create
INFO: create Screens [296]
May 3, 2010 7:45:40 PM de.lessvoid.nifty.loaderv2.types.NiftyType create
INFO: registerPopup [0]
May 3, 2010 7:45:40 PM de.lessvoid.nifty.Nifty loadFromFile
INFO: loadFromFile took [359]
May 3, 2010 7:45:40 PM de.lessvoid.nifty.Nifty gotoScreen
INFO: gotoScreen [start]
May 3, 2010 7:45:40 PM de.lessvoid.nifty.Nifty gotoScreenInternal
INFO: gotoScreenInternal [start]
May 3, 2010 7:45:40 PM de.lessvoid.nifty.effects.EffectProcessor startEffect
INFO: starting effect [(ImageOverlayPulsate)]
May 3, 2010 7:45:40 PM de.lessvoid.nifty.effects.EffectProcessor startEffect
INFO: starting effect [(ImageOverlayPulsate)]
May 3, 2010 7:45:40 PM de.lessvoid.nifty.effects.EffectProcessor startEffect
INFO: starting effect [(Fade)]
May 3, 2010 7:45:40 PM de.lessvoid.nifty.effects.EffectProcessor startEffect
INFO: starting effect [(ImageOverlayPulsate)]
May 3, 2010 7:45:40 PM de.lessvoid.nifty.effects.EffectProcessor startEffect
INFO: starting effect [(ImageOverlayPulsate)]
May 3, 2010 7:45:40 PM com.jme.scene.Node attachChild
INFO: Child "GUI:NIFTYNODE" attached to this node "rootNode"
May 3, 2010 7:45:40 PM de.lessvoid.nifty.screen.Screen$StartScreenEndNotify perform
INFO: onStartScreen has ended
May 3, 2010 7:45:45 PM com.jme.app.BaseSimpleGame cleanup
INFO: Cleaning up resources.
May 3, 2010 7:45:45 PM com.jme.app.BaseGame start
INFO: Application ending.

Welcome EvalMonkey!



The log looks good, i cant see any obvious errors.



You are using this example?

/nifty-examples/src/main/java/de/lessvoid/nifty/examples/jme/JmeNifty.java



You should see a stylish red background with text in the middle saying "Press F1 for the …"



Please also try to set a breakpoint in /nifty-jme-renderer/src/main/java/de/lessvoid/nifty/jme/render/NiftyNode.java

in function draw.

This must be called by jme on each render cycle. If for some reason the niftynode is not drawn (culled)

the whole gui will not be visible.




Hi larynx,



Thanks for your quick reply, I apologize for not responding sooner I was out of town.  I did put a break point in the render section of the nifty node and Nifty render method is being called but no joy. A nivida driver issue perhaps? I checked the tread stack as well and it seems to be the first render called, maybe its being rendered over? But I am running the JME example and no one else is seems to be having that issue, thats why I suspected maybe a driver issue unless I am missing some other resource that doesn't prevent it from compiling. I should have went into QA, it seems I am great at breaking stuff  :D   

I dont think its a driver issue - other tests would make problems too.



I would try to do:


  1. On the command line run glxinfo to check for hardware opengl support.

    (Just to make sure its not nvidia)



    You should see something like this:

direct rendering: Yes
server glx vendor string: NVIDIA Corporation
server glx version string: 1.4
server glx extensions:
    GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_SGIX_fbconfig, ...


(If you see mesa thats bad)

2) run test /jme/src/jmetest/text/TestBitmapFont.java
to check if ortho mode and font rendering works.

3) fresh update from all nifty svn links as there have been some small changes

4) run /nifty-examples/src/main/java/de/lessvoid/nifty/examples/jme/JmeNifty.java
and check if nifty gets keyboard input:
Press F1 (once) if loading finished and you see a purple rotating ball with the text "missing texture" on it  :D
Was there new logging output if you press F1?
Type 'exit' + enter - any reaction?

5) In /nifty-jme-renderer/src/main/java/de/lessvoid/nifty/jme/render/JmeRenderDevice.java place breakpoints
in renderQuad/renderImage functions to check if they are called.






Issue solved! Thanks for your help Larynx! I'll have to pay it forward.  I updated my my copy of nifty and nifty node that seemed to fix it.   


I followed NickZA's instructions for building all the nifty stuff I needed in eclipse.  Never worked with Maven and it was taking too long to figure out.

I can't seem to get either the JmeNifty example, or my own initial test to correctly find the xml files if they are anywhere other than root context. 


   URL url = InsideMap.class.getClassLoader().getResource("gui/build.xml");
   //works fine
   System.out.println("url for gui/build.xml: " + url);
   //NPE and screen is hung in a really bad state.
   NiftyNode niftyNode = new NiftyNode("GUI:NIFTYNODE", "gui/build.xml", "start");



If I dump the build.xml directly into my projects bin folder and request "build.xml" it works, same results if I modify JmeNifty.  Does anyone else know why its doing this?

First off, from the base revision I have of JmeNifty.java (rev. 703), there is no line containing the path "gui/build.xml" so I suggest you revert to rev. 703 and work from there. What rev. 703 does have is a path "console/console.xml" (line 91) and another "model/grass.gif" (line 71), which I'll talk about next.



(EDITED) There is one thing I missed out in my original post which is that you'll need to download a gif file and rename it to "grass.gif" (line 71) and put it in the correct location, because that file doesn't exist, or at least not in the head revision of any of the 5 projects I checked out. Instaed, I got a replacement off google images so I wouldn't need to change any code to get the example up & running.



Lastly (and this may be obvious) the only other thing that comes to mind without seeing your setup is that in one of the 5 projects you perhaps forgot to include "src/main/resources"? Because AFAIK that is the path that sets the whole thing up to work with the configuration files.

Stop. Right there. What are you trying to do? Your goal is to get NiftyGUI working with jME, yes? Or no?



If "yes", forget changing anything including XML files for now; Just get the basic example working first as checked out from the source repositories – with that I might be able to help you. I am also quite new to jME. Once you've achieved this, you can work step-by-step from there, testing regularly to see where the next thing goes wrong. But a solid foundation is needed first.



If "no", i.e. you've already gotten JmeNifty working and you are now trying to adapt it to your own purposes, then someone else here will be better qualified to help.



Either way, best to stay focused on one problem at a time.





Edit: Sorry if this sounds a bit rough, but I'm just saying, "Help me to help you".

Can you give a xml snippet of the text element and the textSize effect and how you apply it? Some xml code please?



What event do you apply the textSize effect to? onHover? onStartScreen? onActive? onClick? on…?



The only thing that comes to my mind - and I'm guessing - would be that maybe the post attribute of the textSize effect is set to true?



Example:


<onActive name="textSize" post="true" .../>



That would not work, because the textSize effect should be applied BEFORE the element gets rendered to have any effect :) The post attribute will default to false so until you accidently changed that to true everything should be fine.

I think you should post a little bit of xml :)

Ah, yes. I tried this with the LwjglRenderer and it works. Then I checked the JME2 renderer and it seems that it is currently missing font rendering with different font sizes.



So at the moment you can't get the TextSize effect to work with JME2.



I think the JME3 renderer has this but I've not checked it.

excellent (in a strange kind of way…)



many thanks for checking - I was begining to think that I had screwed something up when building the jme renderer.  I'm still a bit of a Java newbie  :-o

Actually I started using the jME2-nifty-renderer and was at the point to resize the font but

postponed it as I wanted to have a look in the code before…



But what is the best way for resizing a font? Do I have to use the TextSize-Effect onStart?



BTW: Can't tell enough that nifty really roxx…

Well I am more than happy offer my services as a tester for the jme renderer… :slight_smile:


Ah, too bad. I've known that this day will come and that somebody will find out that hoverFalloffConstraint="both" does not actually work correctly  8)



I'm sorry, but "both" is somewhat broken and I'm not yet smart enough to figure it out and fix it!



Well, falloff kinda works like this:



Nifty figures out the distance from the center of the element to the mouse cursor when the mouse is in the hover area (specified by hoverWidth and hoverHeight). The problem is to figure out the maximum falloff value. If the falloff is constrained to vertical or horizontal this is easy. We simply use the maximum value specified for either vertical or horizontal hover and calculate the linear distance as a float value. This calculation will yield a value that is 0.0f outside of the hover area and 1.0f in the center of the element. The textsize effect simply uses this falloff float value to change the text size accordingly.



This works well for vertical and horizontal constrained hovers.



When faced with the mode "both" nifty currently uses the maximum value of either vertical or horizontal. This means that the effect will not look correct on the side that is shorter (smaller value in absolute pixel coordinates and not percentages). If you would use the same values for width and height, f.i. fixed pixel values, like "150px" for hoverWidth and hoverHeight then you will see, that the effect will look a lot better. It doesn't work quite right in that case because at the corners of the hover rectangle you get falloff values below 0.0f which will scale the textsize below 0.0f which shrinks the text  :cry:



So I already spent some time with that but haven't found a solution yet. I think we need to add a special hoverDistance attribute to get the "both" mode working that will create a hover circle instead of an rectangle. Maybe that works better. But I haven't tried this yet.



So my apology for the broken "both" hover mode.



I'd be happy for any smart ideas to solve this problem tho. Any ideas?



You could even check the code in the class "de.lessvoid.nifty.effects.Falloff" in the Nifty source code too. It might get a little time to get used too but the class and the algorithm is not too complicated.

:smiley:



Yay! - I am not the source of the problem!



I'll have a look at the code in nifty and see if I can come up with something (always easier once someone has done the groundwork!! ) but it might need some kind of hover elipse rather than circle otherwise the vertical effect would start with the mouse a long way above the text…



…now were did I leave my calculus books?

I have gone a little cross-eyed from looking at eliptical formulae (and have had some awful flashbacks to A-Level math  :-o ) but here is something that seems to work.  I will post it here for anyone who has been watching this thread, and if / when I get a moment (and figure out how) I will post on the nifty forums…



I have put together a modified updateFalloffValue() for "de.lessvoid.nifty.effects.Falloff" that uses an elipse formula and a little bit of trigonometry (SOHCAHTOA anyone? oh the memories…) to determine the radial distance from the centre of the object to a point on the elipses circumference.



@void256: Hopefully this could be integrated into the main nifty source? assuming it passes your approval  :D



[small tweak to the code - certain mouse positions result in a negative falloff, so have added Math.abs to the output]


 public void updateFalloffValue(final Element element, final int mouseX, final int mouseY) {
    if (falloffConstraint == falloffConstraint.none) {
      falloffValue = 1.0f;
      return;
    }

    int centerX = element.getX() + element.getWidth() / 2;
    int centerY = element.getY() + element.getHeight() / 2;

    float dx = mouseX - centerX;
    float dy = mouseY - centerY;

    //int falloff = 0;
    float falloff = 0;
    if (falloffConstraint == falloffConstraint.vertical) {
      dx = 0;
      falloff = getVerticalHover(element) / 2;
    }

    if (falloffConstraint == falloffConstraint.horizontal) {
      dy = 0;
      falloff = getHorizontalHover(element) / 2;
    }

    double dA = 0;
    float elA = element.getWidth() / 2;
    float elB = element.getHeight() / 2;

    if (falloffConstraint == falloffConstraint.both) {
      //falloff = Math.max(getHorizontalHover(element) / 2, getVerticalHover(element) / 2);
      
        dA = Math.atan((dy / dx)); //angle from centre to current mouse position
        //distance to a point on the elipse circumference that is on the same angle.....
        //formula from http://www.nlreg.com/ellipse.htm
        falloff = (float)Math.sqrt( (Math.pow(elA,2) * Math.pow(elB,2)) / ( Math.pow((elA * Math.sin(dA)),2)  + Math.pow(( elB * Math.cos(dA)),2) ) );
        falloff = falloff * 2; //tweak to overcome strange behaviour that I might look at later...

    }

    float d = (float) Math.hypot(dx, dy);
    if (d > falloff) {
      falloffValue = 0.0f;
    }

    falloffValue = Math.abs(1.0f - (float) d / (float) falloff);
  }


? Did this make it in

Yes! An extended and improved version of the initial patch (also from GilesH) is available in Nifty svn. And it will be a part of the upcoming 1.2 Release too!

Excellent !!!, looking forward to 1.2

Just use the svn…



http://nifty-gui.lessvoid.com/archives/category/documentation-tutorials-how-to