Slick Forums
http://slick.ninjacave.com/forum/

A few questions
http://slick.ninjacave.com/forum/viewtopic.php?f=18&t=6250
Page 1 of 1

Author:  raft [ Sun Feb 17, 2013 4:01 pm ]
Post subject:  A few questions

hi,

first I'd like to take the opportunity to thank for this great library. really handy :)

I'm trying to build a GUI for my jPCT based 3D game. I have a few questions:

  • When drawing on top of jPCT, font colors aren't rendered. I guess jPCT overrides some GL state and TWL does not restore it when rendering. Any ideas what setting is that? (If jPCT is removed, colors works.)
  • Is it possible to use same font file with different sizes?
  • Is it possible to set width of a widget to something similar to (Gui.width - x) via theme?
  • Adding Gui.invokeLater(Runnable r, long delay) method maybe handy


btw, Widget.requestKeyboardFocus() throws an ArrayIndexOutOfBoundsException when invoked from Widget.afterAddToGUI(Gui) method
Code:
java.lang.ArrayIndexOutOfBoundsException: -2
   at java.util.ArrayList.get(ArrayList.java:324)
   at de.matthiasmann.twl.Widget.getChild(Widget.java:1206)
   at de.matthiasmann.twl.GUI.getTopPane(GUI.java:1035)
   at de.matthiasmann.twl.GUI.requestKeyboardFocus(GUI.java:1248)
   at de.matthiasmann.twl.Widget.requestKeyboardFocus(Widget.java:1410)
   at de.matthiasmann.twl.Widget.requestKeyboardFocus(Widget.java:1856)


thanks,
r a f t

Author:  MatthiasM [ Mon Feb 18, 2013 8:39 pm ]
Post subject:  Re: A few questions

Why is the stack trace incomplete? Are you sure you are calling it from the UI thread?

Author:  raft [ Mon Feb 18, 2013 11:31 pm ]
Post subject:  Re: A few questions

I cut it for brevity. below is full stack trace. it's called in the callback method Widget.afterAddToGUI(..). so I guess it's better you should say if it's UI thread or not ;)

Code:
Feb 19, 2013 1:27:23 AM de.matthiasmann.twl.Widget recursivelyAddToGUI
SEVERE: Exception in afterAddToGUI()
java.lang.ArrayIndexOutOfBoundsException: -2
   at java.util.ArrayList.get(ArrayList.java:324)
   at de.matthiasmann.twl.Widget.getChild(Widget.java:1206)
   at de.matthiasmann.twl.GUI.getTopPane(GUI.java:1054)
   at de.matthiasmann.twl.GUI.requestKeyboardFocus(GUI.java:1267)
   at de.matthiasmann.twl.Widget.requestKeyboardFocus(Widget.java:1410)
   at de.matthiasmann.twl.Widget.requestKeyboardFocus(Widget.java:1856)
   at de.matthiasmann.twl.Widget.requestKeyboardFocus(Widget.java:1410)
   at de.matthiasmann.twl.Widget.requestKeyboardFocus(Widget.java:1856)
   at de.matthiasmann.twl.Widget.requestKeyboardFocus(Widget.java:1410)
   at raft.jumpy.gl.twl.RootWidget.showWidget(RootWidget.java:164)
   at raft.jumpy.gl.twl.RootWidget.setVisibleGui(RootWidget.java:99)
   at raft.jumpy.gl.twl.RootWidget.afterAddToGUI(RootWidget.java:74)
   at de.matthiasmann.twl.Widget.recursivelyAddToGUI(Widget.java:2406)
   at de.matthiasmann.twl.Widget.insertChild(Widget.java:1261)
   at de.matthiasmann.twl.GUI.<init>(GUI.java:213)
   at de.matthiasmann.twl.GUI.<init>(GUI.java:170)
   at raft.jumpy.gl.JumpyTWL.setup(JumpyTWL.java:316)
   at raft.jumpy.gl.JumpyTWL.main(JumpyTWL.java:182)

Author:  MatthiasM [ Tue Feb 19, 2013 7:14 am ]
Post subject:  Re: A few questions

Ok, this is not a threading issue. The issue is that GUI has not yet completed it's construction. I'll try to reproduce this and fix it if possible.

Author:  MatthiasM [ Wed Feb 20, 2013 8:17 pm ]
Post subject:  Re: A few questions

This should now be fixed.

Author:  raft [ Wed Feb 20, 2013 11:08 pm ]
Post subject:  Re: A few questions

thanks:) yes, it's solved now.

what about other questions:

raft wrote:
When drawing on top of jPCT, font colors aren't rendered. I guess jPCT overrides some GL state and TWL does not restore it when rendering. Any ideas what setting is that? (If jPCT is removed, colors works.)

this is strange: this doesn't work for the test/font.fnt used in demo, but works for the font I prepared with theme editor.

raft wrote:
Is it possible to use same font file with different sizes?

ok, I got an answer for this, not possible

raft wrote:
Is it possible to set width of a widget to something similar to (Gui.width - x) via theme?


raft wrote:
Adding Gui.invokeLater(Runnable r, long delay) method maybe handy

maybe really handy

Author:  MatthiasM [ Wed Feb 20, 2013 11:24 pm ]
Post subject:  Re: A few questions

There is a Timer class and also a GUI.createTimer method.

No idea what jPCT is doing - just look at LWJGLRenderer and either subclass it or write your own renderer. It has one method to setup GL: setupGLState() and one to revert to the previous state: revertGLState()

You can set parameters like minWidth and maxWidth or any other parameter you want. The rest is up to your code and the layout() method.

Author:  prmejc [ Wed Jun 19, 2013 1:08 pm ]
Post subject:  Re: A few questions

Hi,

where can I see an example code, how to draw TWL components on top of JPCT?
The TWL wiki is offline and I am having difficulties with using TWL.

I tried with couple examples that i found, but as soon as I call Display.create(), i get a black screen.

Author:  raft [ Mon Jun 24, 2013 10:14 am ]
Post subject:  Re: A few questions

here is jPCT's HelloWorldOGL sample modified to work with TWL. copy it to TWL's gameui package and it should work. I guess this will give you a start.

you should also comment out the background line in gameui.xml theme file, otherwise that background covers the whole scene.
Code:
<param name="background"><image>background-image</image></param>


Code:
package gameui;

import com.threed.jpct.Config;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;

import de.matthiasmann.twl.GUI;
import de.matthiasmann.twl.renderer.Renderer;
import de.matthiasmann.twl.renderer.lwjgl.LWJGLRenderer;
import de.matthiasmann.twl.theme.ThemeManager;

/**
 * A simple HelloWorld using the OpenGL-renderer.
 * @author EgonOlsen + raft
 *
 */
public class HelloWorldTWL {

   private World world;
   private FrameBuffer buffer;
   private Object3D box;

   public static void main(String[] args) throws Exception {
      new HelloWorldTWL().loop();
   }

   public HelloWorldTWL() throws Exception {
      world = new World();
      world.setAmbientLight(0, 255, 0);

      TextureManager.getInstance().addTexture("box", new Texture("box.jpg"));

      box = Primitives.getBox(13f, 2f);
      box.setTexture("box");
      box.setEnvmapped(Object3D.ENVMAP_ENABLED);
      box.build();
      world.addObject(box);

      world.getCamera().setPosition(50, -50, -5);
      world.getCamera().lookAt(box.getTransformedCenter());
   }

   private void loop() throws Exception {
        Config.nearPlane = 0.9f;
      Config.glIgnoreNearPlane = false;
      
      buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
      buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
      buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
      
      Renderer twlRenderer = new LWJGLRenderer();
      ThemeManager theme = ThemeManager.createThemeManager(
            getClass().getResource("gameui.xml"), twlRenderer);

      GUI gui = new GUI(new GameUIDemo(), twlRenderer);
      gui.applyTheme(theme);
      

      while (!org.lwjgl.opengl.Display.isCloseRequested()) {
         box.rotateY(0.01f);
         buffer.clear(java.awt.Color.BLUE);
         world.renderScene(buffer);
         world.draw(buffer);
         
            gui.update();
           
            buffer.update();
            buffer.displayGLOnly();
         
         Thread.sleep(10);
      }
      buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
      buffer.dispose();
      System.exit(0);
   }
}

   

Author:  prmejc [ Mon Jun 24, 2013 11:34 am ]
Post subject:  Re: A few questions

Thank you for reply.
I was trying that before, but I got the folowing exception on last line:
Code:
buffer = new FrameBuffer(resWidth, resHeight, FrameBuffer.SAMPLINGMODE_GL_AA_2X);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL, IRenderer.MODE_OPENGL);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);

Renderer twlRenderer = new LWJGLRenderer();


Code:
Caused by: java.lang.NullPointerException
   at org.lwjgl.opengl.GL11.glGetInteger(GL11.java:1436)
   at de.matthiasmann.twl.renderer.lwjgl.LWJGLRenderer.syncViewportSize(LWJGLRenderer.java:224)
   at de.matthiasmann.twl.renderer.lwjgl.LWJGLRenderer.<init>(LWJGLRenderer.java:125)

Author:  raft [ Mon Jun 24, 2013 11:48 am ]
Post subject:  Re: A few questions

mm, it works for me. maybe related to lwjgl version? I'm using 2.8.5

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/