To anyone who wants to use "TWL"opengl java gui

http://twl.l33tlabs.org/



It's a great lib…



There are are some demos that look really promising…



If anyone needs it, I made this gamestate that makes TWL work in JMonkey

package net.ob3d.twl;
import com.jme.input.KeyInput;
import com.jme.input.KeyInputListener;
import com.jme.input.MouseInput;
import com.jme.input.MouseInputListener;
import com.jme.system.DisplaySystem;
import com.jmex.game.state.GameState;
import de.matthiasmann.twl.GUI;
import de.matthiasmann.twl.Widget;
import de.matthiasmann.twl.renderer.lwjgl.LWJGLRenderer;
import de.matthiasmann.twl.theme.ThemeManager;

public class TWLState extends GameState implements KeyInputListener,
      MouseInputListener {
   protected GUI gui;
   protected Widget root = new Widget();
   public TWLState() throws Exception {
      super();
      LWJGLRenderer renderer = new LWJGLRenderer();
      ThemeManager theme = ThemeManager.createThemeManager(TWLState.class
            .getResource("simple.xml"), renderer);
      root.setTheme("");
      gui = new GUI(root, renderer);
      gui.setVisible(true);
      gui.setSize();
      gui.applyTheme(theme);
      KeyInput.get().addListener(this);
      MouseInput.get().addListener(this);
   }
   public void onButton(final int button, final boolean pressed, final int x,
         final int y) {
      if (isActive())
         gui.handleMouse(x, recalcY(y), button, pressed);
   }
   int recalcY(int y) {
      return DisplaySystem.getDisplaySystem().getHeight() - y;
   }
   public void onMove(int delta, int delta2, final int newX, final int newY) {
      if (isActive())
         gui.handleMouse(newX, recalcY(newY), -1, false);
   }
   public void onWheel(int wheelDelta, int x, int y) {
      if (isActive())
         gui.handleMouseWheel(wheelDelta);
   }
   public void onKey(char character, int keyCode, boolean pressed) {
      if (isActive())
         gui.handleKey(keyCode, character, pressed);
   }
   public GUI getGui() {
      return gui;
   }
   @Override
   public void cleanup() {
      gui.destroy();
      KeyInput.get().removeListener(this);
      MouseInput.get().removeListener(this);
   }
   @Override
   public void render(float tpf) {
      gui.update();
   }
   @Override
   public void update(float tpf) {
   }
}



And this example..

package net.ob3d.test;
import java.util.concurrent.Callable;
import net.ob3d.twl.TWLState;
import com.jme.input.MouseInput;
import com.jme.util.GameTaskQueueManager;
import com.jmex.editors.swing.settings.GameSettingsPanel;
import com.jmex.game.StandardGame;
import com.jmex.game.state.GameStateManager;
import de.matthiasmann.twl.Button;

public class TestTWLState extends TWLState {
   public TestTWLState() throws Exception {
      super();
      root.add(new Button("HELLO WORLD"));
   }
   public static void main(String[] args) throws Exception {
      StandardGame game = new StandardGame("TWLTest");
      GameTaskQueueManager.getManager().update(new Callable<Object>() {
         public Object call() throws Exception {
            initGame();
            MouseInput.get().setCursorVisible(true);
            return null;
         }
      });
      if (GameSettingsPanel.prompt(game.getSettings())) {
         game.start();
      }
   }
   public static void initGame() throws Exception {
      TestTWLState f = new TestTWLState();
      f.setActive(true);
      GameStateManager.getInstance().attachChild(f);
   }
}




1 Like

wow… goodwork… how can we integrate this with JME?

SingSong also uses TWL - and looks stunning:

http://singthegame.com/screenshots.php

The problem is that, as far as I know, this library depends on LWJGL. If you plan to include it into JME, it will be fine to think about a way of making it work with JOGL too.

gouessej said:

The problem is that, as far as I know, this library depends on LWJGL. If you plan to include it into JME, it will be fine to think about a way of making it work with JOGL too.
Hence it should probably not be in the core, but definitely be kept around in wide open view for everyone to find with ease, 'cause it's a great contribution!
erlend_sh said:

Hence it should probably not be in the core, but definitely be kept around in wide open view for everyone to find with ease, 'cause it's a great contribution!

Yes I agree with you, it provides a nice glow effect and a powerful XML system to define the look and feel.

Thanks for your efford on this!

It really looks great, for an HUD or GUI!



I'm thinking of using this as the GUI in my Game… :smiley:

Does it also have the same 'side effects' as FengGUI when using together with jME?



With side effects i mean, the need to apply default renderstates or the need to render the gui in a separate renderpass to avoid that jme inherits wrong texture coordinates or id's etc.

mhelz0001 said:

hi sir... yours got a very good effect regarding GUIs... could it be integrated with JME since it also runs fine under LWGL?... if yes, how? from the download I can't quite see an existing project where I could just include it in my project... sorry for being such a noob

Well just goto the download section and download twl source files, or just the jar..then run the example from my first post.
Core-Dump said:

Does it also have the same 'side effects' as FengGUI when using together with jME?

With side effects i mean, the need to apply default renderstates or the need to render the gui in a separate renderpass to avoid that jme inherits wrong texture coordinates or id's etc.

I didnt see no such thing yet.

hi sir… yours got a very good effect regarding GUIs… could it be integrated with JME since it also runs fine under LWGL?.. if yes, how? from the download I can't quite see an existing project where I could just include it in my project… sorry for being such a noob

Possibly a dumb question, but I'll ask it anyway:

The sample code imports "test.SimpleTest" and references "simple.xml".  Where do I find these?

mjsimpson said:

Possibly a dumb question, but I'll ask it anyway:
The sample code imports "test.SimpleTest" and references "simple.xml".  Where do I find these?

I forgot about these..I downloaded some testclasses from their repositoty.
SimpleTest doesnt matter (Ill replace it for clarity), just use any class, like "TWLState". Simple.xml is a stylesheet, sort of. You find these files in their repository here. Just click "raw" to download them.
http://hg.l33tlabs.org/twlexamples/file/5eab09207221/src/test/

The repo is "mercury" or something that I dont know…

I'm always amazed by guys like that, building what seems to be a solid library and stays discreet.  Would be great to have his library as a new alternative for Jme !

I just tried the webstart demo and I'm speechless  :-o

orelero said:

I'm always amazed by guys like that, building what seems to be a solid library and stays discreet.  Would be great to have his library as a new alternative for Jme !

It cant be an alternative to JME just a good GUI for JME. The webstart had me jawdropping as well..but try to figure this library out, there's almost no documentation..for me I'll stay with swing for a bit since most I dont have the energy to rewrite all this, but if I should start over, I would probably use this.

For quite a noob to java and GUI programming in general (I am a native PHP programmer). TWL seems to be quite an easy to use addition to jME - The only thing I wish we had was more documentation on how to implement own styles (Im currently just modding the Eferon instead of creating a new one)…



The actual creation of the gui using setHorizontalGroup/setVerticleGroup/setParallelGroup and setSequentialGroup is 'very' confusing from a noobs POV. But otherwise implementation and overall functionality is very easy to work with.



Im thinking once I get to understanding the internal Group layout part of things and find any external tools to map the xml to the png skin this interface will be exactly what I have been looking for. (Do any of these tools exist? Its quite a pain to have to map every single tiny box to its defined area by hand) & Does anyone have documentation  or tips on the Group ordering aspect?



Also it would be great to have a tutorial on how to run its in its own gamestate as a layer on top of a SimpleGame or something. The sample demo here is great for just "menu" functions but needs some tweaking be used as an actual ingame Hud)



As I have said, Im a Java noob still and learn my programming languages from experience not much from books (I started with AI programming and Modding in C# for a MMORPG back around 10yrs ago) from there moved to web programming and am greatly looking forward to the jump back into game programming… If I make my way around the gamestates Ill post something - But im sure an experienced programmer could do this in a matter of minutes - it might take me a few weeks between other projects/work/etc…

I'm still getting errors similar to what Bonechilla was getting here: http://www.jmonkeyengine.com/forum/index.php?topic=12056.msg89961#msg89961



The errors are stemming from the same try/catch block… any ideas?  I've got the simple.xml and all the png's in the same folder and have hard wired the URL to the application (and have verified the URL is correct)

Has anybody used TWL in a SimpleGame, without GameStates? I don’t get it working, no idea of GL States and stuff.



edit: To be more precise I mean a project that extends a jme2 SimpleGame. I can render the TWL GUI standalone in the SimpleGame context, but as soon as the game gets rendered before, with all the state changes included, the GUI is not to be seen anymore.



edit2: don’t know if anybody reads this at all, but i’ll go on asking :wink:

if i make a (LWJGL-) Display.update() after the GUI render, which happens after the game render, i see the game and the GUI but it flickers. I guess two different buffers are used and they become switched by the update(). How can I use only one buffer?