Slick Forums

Discuss the Slick 2D Library
It is currently Sat Dec 16, 2017 4:48 pm

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: A few questions
PostPosted: Sun Feb 17, 2013 4:01 pm 
Offline

Joined: Sun Jul 18, 2010 2:10 pm
Posts: 32
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


Top
 Profile  
 
 Post subject: Re: A few questions
PostPosted: Mon Feb 18, 2013 8:39 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
Why is the stack trace incomplete? Are you sure you are calling it from the UI thread?

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: A few questions
PostPosted: Mon Feb 18, 2013 11:31 pm 
Offline

Joined: Sun Jul 18, 2010 2:10 pm
Posts: 32
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)


Top
 Profile  
 
 Post subject: Re: A few questions
PostPosted: Tue Feb 19, 2013 7:14 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
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.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: A few questions
PostPosted: Wed Feb 20, 2013 8:17 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
This should now be fixed.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: A few questions
PostPosted: Wed Feb 20, 2013 11:08 pm 
Offline

Joined: Sun Jul 18, 2010 2:10 pm
Posts: 32
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


Top
 Profile  
 
 Post subject: Re: A few questions
PostPosted: Wed Feb 20, 2013 11:24 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
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.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: A few questions
PostPosted: Wed Jun 19, 2013 1:08 pm 
Offline

Joined: Wed Jun 19, 2013 12:58 pm
Posts: 2
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.


Top
 Profile  
 
 Post subject: Re: A few questions
PostPosted: Mon Jun 24, 2013 10:14 am 
Offline

Joined: Sun Jul 18, 2010 2:10 pm
Posts: 32
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);
   }
}

   


Top
 Profile  
 
 Post subject: Re: A few questions
PostPosted: Mon Jun 24, 2013 11:34 am 
Offline

Joined: Wed Jun 19, 2013 12:58 pm
Posts: 2
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)


Top
 Profile  
 
 Post subject: Re: A few questions
PostPosted: Mon Jun 24, 2013 11:48 am 
Offline

Joined: Sun Jul 18, 2010 2:10 pm
Posts: 32
mm, it works for me. maybe related to lwjgl version? I'm using 2.8.5


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group