Help for HUD

I'm trying to make an HUD with FengGui. I've done the menu with FengGUI but the same code doesn't work during game, I've not find any example of HUD with Feng GUI in jME, somebody know something about?? thanks a lot!!

Can you give us more of an idea of what you're wanting to see out of it?

This code work in my MenuGameState, but when I use the same code in the MainGameState (ingame) it cannot find my texture, that I would to use for the HUD.



display = new Display(new LWJGLBinding());
      input = new FengJMEInputHandler(display);
      
      final Container menu = new Container();
      final Container bg = new Container();
      
      window = FengGUI.createWindow(display, false, false, false, true);
            
      MouseInput.get().setCursorVisible(true);
                  
      menu.setExpandable(false);
      menu.setShrinkable(false);
            
      //c.getAppearance().add(new PlainBackground(Color.WHITE));
      ITexture tex;
        Binding bind = Binding.getInstance();
     // bind.setUseClassLoader(true);
       
       Binding.getInstance().setUseClassLoader(true);
                       
   //--->tex = bind.getTexture(MainGameState.class.getClassLoader().getResource("images/main.png"));
                  
        Pixmap pm = new Pixmap(tex);
      bg.getAppearance().add(new PixmapBackground(pm, true));
      StaticLayout.center(bg, display);
      bg.setSize(display.getWidth(), display.getHeight());
      bg.setX(0);
      bg.setY(0);      
      
      display.addWidget(bg);
      display.addWidget(menu);
      menu.getAppearance().setPadding(new Spacing(10, 10));
      menu.setLayoutManager(new RowLayout(false));
   



in my render method I have


Texture defTex = TextureState.getDefaultTexture().createSimpleClone();
        defTex.setScale(new Vector3f(1, 1, 1));
        TextureState defaultTextureState = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
        defaultTextureState.setTexture(defTex);
        defaultTextureState.apply();
       
        // render the GUI
        display.display();





At the line

//--->tex = bind.getTexture(MainGameState.class.getClassLoader().getResource("images/main.png"));



I've a NullPointerException...I've tried also to put the absolute path and "bind.setUseClassLoader(true);" but It does Exception.


Have you checked that

MainGameState.class.getClassLoader().getResource("images/main.png")


evaluates to a valid url, in other words is not null?

the URL is right but returns null. I used the same code in another class and it finds that file.

I've solved using different GameStates, even if I don't know why it works now!  :wink:

In multithreaded environments (your usage of GameStates seems to indicate that you are using StandardGame, which in turn proably implies multithreading) it may be better to use

Thread.currentThread().getContextClassLoader()

in favor of

Class.getClassLoader()


You could also use the system class loader (ClassLoader.getSystemClassLoader()) on any jvm jME will run on.

I've been having the same problem–I thought it was associated with the fact you can't import textures in a thread other than the OpenGL thread (which is the "main" thread).



Am I wrong?



Hevee, your code gives me an NPE still…

Trussell said:

Hevee, your code gives me an NPE still...

In that case you are wrong with this assumption:
Trussell said:

I've been having the same problem--I thought it was associated with the fact you can't import textures in a thread other than the OpenGL thread (which is the "main" thread).


Think about it - at the time the class loader resource location evaluates to null, jME hasn't even had a chance to cause any multithreading problems!
One thing to be aware of in some IDEs (namely netbeans) is that the non-java files you add to your project's class path might not be available to the runtime class loader before you do a full build of your project (clean build).

I still haven't figured out how to make it so my resource folders aren't destroyed doing a clean/build…



EDIT: I actually had changed the name of the resource… but now I get this (with the resource name correct, obviously).


Exception in thread "Thread-4" java.lang.NullPointerException
        at org.lwjgl.opengl.GL11.glGenTextures(GL11.java:1348)
        at org.fenggui.render.lwjgl.LWJGLTexture.createTextureID(Unknown Source)
        at org.fenggui.render.lwjgl.LWJGLTexture.createTexture(Unknown Source)
        at org.fenggui.render.lwjgl.LWJGLBinding.getTexture(Unknown Source)
        at org.fenggui.render.Binding.getTexture(Unknown Source)
        at gamestates.MenuGameState.<init>(MenuGameState.java:53)
        at core.Main$GameLoader.run(Main.java:117)



I assume THAT is caused by the fact it's not in the OpenGL Thread?

Trussell said:

I assume THAT is caused by the fact it's not in the OpenGL Thread?

Most likely :) You know the routine, use the GameTaskQueueManager to stick your task into the render queue.

Never got the hang of using the GameTaskQueueManager… wanna let me in on the know-how ;)?

Trussell said:

Never got the hang of using the GameTaskQueueManager.... wanna let me in on the know-how ;)?

[sarcasm]...and when I'm done searching the forum for you and reading you the javadoc of GameTaskQueueManager's four public methods, maybe I can make you some pancakes?[/sarcasm]
Seriously, it's not that hard to figure out.

GameTaskQueueManager.getManager().render(Callable c)



If you are using your own BaseGame implementation it will actually be necessary to call execute on the qeues on your own inside the render loop, you can consult the BaseSimpleGame source code (render() and update()) for details.

Pancakes sound nice.



But in all honesty it's not a priority atm, I was just curious for later use. I'll figure out the whole Callable thing once I have a terrain-creation solution.