Slick Forums

Discuss the Slick 2D Library
It is currently Wed Jun 19, 2013 5:30 pm

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Tue Jan 10, 2012 7:35 pm 
Offline

Joined: Fri Jan 06, 2012 2:15 am
Posts: 44
I'm using BasicTWLGameState, TWLStateBasedGame, RootPane etc (the standard TWL integration files).

I've narrowed down some weird font (might be the entire UI, not sure yet) issue to a call to getGraphics on an Image instance. Maybe I'm doing something wrong here, but as soon as I uncomment this line (whether or not it's even drawn to the screen) the text for a simple button changes.

mapViewImage = new Image(1390, 750);
mapViewGraphics = mapViewImage.getGraphics();

Image

Any idea what could be going on here or how I can troubleshoot?


Top
 Profile  
 
PostPosted: Tue Jan 10, 2012 8:39 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1189
Do you call this from within TWL's painting code?

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Wed Jan 11, 2012 12:02 am 
Offline

Joined: Fri Jan 06, 2012 2:15 am
Posts: 44
Don't think so, I'm using the TWLStateBasedGame classes from the sticky in this forum.

I'm calling from within the init() method of a class which extends BasicTWLGameState.

@Override
public void init(GameContainer container, StateBasedGame game) throws SlickException {
}

Is that wrong? Working on putting together a small test example which uses those Slick state classes to see if I can repeat the issue.

Or maybe this is the problem - I'm doing this to create the button, in a State class extending BasicTWLGameState:

Code:
   @Override
   protected void createRootPane() {

      super.createRootPane();
      
      rootPane.setTheme("mainTheme");
      
      btn = new Button("Exit");
      btn.addCallback(new Runnable() {
         
         public void run() {

            System.exit(0);
         }
      });
      rootPane.add(btn);
   }
   
   @Override
   protected void layoutRootPane() {

      btn.adjustSize();
      btn.setPosition(10, 5);
   }


Top
 Profile  
 
PostPosted: Wed Jan 11, 2012 12:28 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1189
That code looks fine (except that I don't like System.exit - there should be a nicer way to quit a Slick app - but that's not important for this issue).

A small runnable testcase would be nice (eg if it's a single class using the theme data from one of the examples then it's much easier to upload to the forum - maybe even as code paste).

I assume that getGraphics() modifies some OpenGL state which TWL's LWJGLRenderer doesn't know about - and this then interferes with it's rendering.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Wed Jan 11, 2012 3:00 am 
Offline

Joined: Fri Jan 06, 2012 2:15 am
Posts: 44
Got it down to a single file (ok I cheated with one inner class), a single line "test.getGraphics()" demonstrates the effect. Not sure if the state based game stuff plays a factor but I used that here.

If you drop it into a package 'slick' within TWLExamples/src, and add slick.jar to the build path for that project, etc., you shouldn't have trouble getting it compiling.

Set the boolean at the top "getGraphicsTest" to true and it'll call Image.getGraphics(), and you should see the glitch (I hope). It uses login.xml for a theme.

Image

Code:
package slick;

import java.net.URL;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import slick.twl.BasicTWLGameState;
import slick.twl.TWLStateBasedGame;
import de.matthiasmann.twl.Button;

public class SlickTest extends TWLStateBasedGame {
   
    private boolean getGraphicsTest = false;
   
    public static void main(String[] args) {
       
        try {
           
            AppGameContainer container = new AppGameContainer(new SlickTest("SlickTest"));
            container.setMinimumLogicUpdateInterval(20);
            container.setMaximumLogicUpdateInterval(20);
            container.setDisplayMode(1440, 900, false);
            container.setShowFPS(false);
            container.start();
        } catch (SlickException e) {
            e.printStackTrace();
        }
    }
   
    protected SlickTest(String name) {
        super(name);
    }
   
    @Override
    protected URL getThemeURL() {
        return SlickTest.class.getResource("../login/login.xml");
    }
   
    @Override
    public void initStatesList(GameContainer container) throws SlickException {
       
        addState(new TestState());
    }
   
    private class TestState extends BasicTWLGameState {

        private Button btn;
       
        @Override
        protected void createRootPane() {

            super.createRootPane();
           
            rootPane.setTheme("login-panel");
           
            btn = new Button("Exit");
            btn.addCallback(new Runnable() {
               
                public void run() {

                    System.exit(0);
                }
            });
            rootPane.add(btn);
        }
       
        @Override
        protected void layoutRootPane() {

            btn.adjustSize();
            btn.setPosition(20, 25);
        }
       
        @Override
        public void init(GameContainer container, StateBasedGame game) throws SlickException {
           
            Image test = new Image(1400, 800);
           
            if (getGraphicsTest) {
               
                test.getGraphics();
            }
        }

        @Override
        public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
        }

        @Override
        public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
        }

        @Override
        public int getID() {
            return 0;
        }
    }
}


Hope this helps find the issue, I've been dying for a good theme-able Java GUI library (that isn't Swing) for years!


Top
 Profile  
 
PostPosted: Wed Jan 11, 2012 7:09 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1189
I can reproduce the problem (even so you seem to use an older version of the TWLSlick classes).
Sadly I have no idea what is happening - I'll take another look at it when I have more time.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Thu Jan 12, 2012 12:40 am 
Offline

Joined: Fri Jan 06, 2012 2:15 am
Posts: 44
I got those files from here: http://wiki.l33tlabs.org/bin/view/TWL/I ... eBasedGame

Going to try and do some more experimenting with this to find out more. But what I do find weird is that nobody noticed this before.

Edit:
Well, here's something that could be a useful clue. I've noticed that if I change the position of the button, the further away from the upper left I position it - the actual draw location of the button gets out of sync.
Ex.
Code:
        @Override
        protected void layoutRootPane() {
           
            btn.adjustSize();
            btn.setPosition(20, 125);
        }


Clicking on the button label in this position doesn't click the button, but if you go slightly below the button and click, it works fine. Setting the test boolean to false (no getGraphics call) makes the button work as expected.


Top
 Profile  
 
PostPosted: Thu Jan 12, 2012 1:36 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1189
Maybe the OpenGL viewport setting is not correct?

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Thu Jan 12, 2012 4:16 am 
Offline

Joined: Fri Jan 06, 2012 2:15 am
Posts: 44
I've never used OpenGL directly (just through wrappers like Slick or jme) so my knowledge is limited here, but maybe that is a factor. I can't really guess as to what the issue is. When I change the resolution from the one I posted above to 1920x1200 (my desktop res) - you need to click slightly above the button to trigger it. Lower the res back to 1440x900 and you have to click below the button's displayed location. Also tried 1920x1200 fullscreen and still got the same result (well, with the added plus of somehow managing to crash Eclipse. :roll: )

So, the rendered button graphic is either high or low depending on it's position on screen and seemingly the application resolution.

Is this looking like a Slick2D specific issue?


Top
 Profile  
 
PostPosted: Thu Jan 12, 2012 4:32 am 
Offline

Joined: Fri Jan 06, 2012 2:15 am
Posts: 44
I tried the Demo.java here: http://wiki.l33tlabs.org/bin/view/TWL/U ... with+Slick

And added a call within init() to getGraphics() like so:

Code:
    @Override
    public void init(GameContainer gc) throws SlickException {
        // construct & configure root widget
        root = new Widget();
        root.setTheme("");
       
        Image i = new Image(1300, 800);
        i.getGraphics();


But the demo seems fine still. Hmm..


Top
 Profile  
 
PostPosted: Thu Jan 12, 2012 7:37 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1189
I added the following test code into the layoutRoorPane() method:
Code:
            LWJGLRenderer r = (LWJGLRenderer)btn.getGUI().getRenderer();
            IntBuffer ib = BufferUtils.createIntBuffer(16);
            GL11.glGetInteger(GL11.GL_VIEWPORT, ib);
           
            System.out.printf("gl: x=%d y=%d w=%d h=%d\nrender: x=%d y=%d w=%d h=%d\n",
                    ib.get(0), ib.get(1), ib.get(2), ib.get(3),
                    r.getViewportX(), r.getViewportY(), r.getWidth(), r.getHeight());


This outputs the following values:
Code:
when false:
  gl: x=0 y=0 w=1440 h=900
  render: x=0 y=0 w=1440 h=900

when true:
  gl: x=0 y=0 w=1440 h=900
  render: x=0 y=0 w=2048 h=1024

So somehow getGraphics() leaves a wrong GL_VIEWPORT size active at the time the LWJGLRenderer is syncing it's display size (eg at creation time, can manually sync later - eg for resizing support).

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Fri Jan 13, 2012 12:15 am 
Offline

Joined: Fri Jan 06, 2012 2:15 am
Posts: 44
Wow... and adding

Code:
r.setViewport(0, 0, 1440, 900);


after that "fixes" the issue (but maybe, only until the next call to getGraphics()?) I guess I'll post on the bug forum and link to this thread. Thanks!

Edit: Actually it seems to stay "fixed" after a later call to getGraphics(). Seems like a workaround I guess.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


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:  
Powered by phpBB® Forum Software © phpBB Group