Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 19, 2013 6:35 am

All times are UTC




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: Tue Jun 14, 2011 5:38 pm 
Offline

Joined: Tue Jun 14, 2011 5:09 pm
Posts: 6
Hi,

I am currently trying to use TWL in combination with a Slick StateBasedGame using the demo code from the TWL wiki, which works perfectly.
But now, I'd like to offer multiple screen resolutions to my users -> I use a Slick ScalableGame to do the scaling work for me.
But unfortunately, I did not find a way to scale my TWL GUI - it just does not care about my game's resolution and maintains its size, while my game is scaled perfectly. Also, when I apply a larger resolution like 1920*1080, the TWL GUI disappears completely...
Is there a solution for my problem or do I have to select another GUI for my purposes?

Thanks in advance,

KrawallMann


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2011 9:29 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
You need to subclass the LWJGLRenderer and provide/adjust the OpenGL parameters - the provided renderer is not designed to just scale the UI (because that looks totally ugly).

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2011 1:20 pm 
Offline

Joined: Tue Jun 14, 2011 5:09 pm
Posts: 6
Hi,

thanks for your advice!
After subclassing some classes it finally seems to work.
Maybe I'll post the code later, but it has to refactored first...

But now, I have another problem: At some resolutions, the Fonts look really awkward and grainy - is there a way to scale them a little more smooth?

KrawallMann


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2011 3:28 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
not with bitmap fonts - but there is currently work done (not by me) on a javafreetype (used by theme editor to create high quality fonts) based font renderer for TWL.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2011 10:11 pm 
Offline

Joined: Mon Sep 12, 2011 4:56 pm
Posts: 8
I'm having the same problem as KrawallMann's original post. I can't figure out how to get TWL to scale with Slick's ScalableGame and unfortunately I don't know enough about OpenGL to subclass TWL's LWJGLRenderer and get stuff working.

Can we get a bit of example code on how to scale TWL along with ScalableGame?

Thanks so much.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2011 5:23 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
I strongly advice against scaling the GUI that way - better to create a scalable theme (eg using the 9-way split) and size your widgets based on the available space. This will result in a much better looking UI.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2011 7:39 am 
Offline

Joined: Mon Sep 12, 2011 4:56 pm
Posts: 8
MatthiasM, I understand your concern for not wanting me to scale the entire UI, but this seems like the best option for me to get the look and feel of my game consistent across all resolutions. I do have my sliders set up with 9-way split graphics, but font sizes and the game's aspect ratio are causing problems, and my button graphics are textures and are already being scaled. I'm going to at least give TWL scaling a try, with or without your help, but I would be hugely grateful if you would lend me your knowledge.

So far I've got TWL widgets to scale by modifying TWL's LWJGLRenderer like this:
Code:
    @Override
    public boolean startRenderering() {
        if(width <= 0 || height <= 0) {
            return false;
        }

        hasScissor = false;
        tintStack = tintStateRoot;
        clipStack.clearStack();

        // GL11.glPushAttrib(GL11.GL_ENABLE_BIT|GL11.GL_TRANSFORM_BIT|GL11.GL_HINT_BIT|
        // GL11.GL_COLOR_BUFFER_BIT|GL11.GL_SCISSOR_BIT|GL11.GL_LINE_BIT|GL11.GL_TEXTURE_BIT);
        // GL11.glMatrixMode(GL11.GL_PROJECTION);
        // GL11.glPushMatrix();
        // GL11.glLoadIdentity();
        // GL11.glOrtho(0, width, height, 0, -1.0, 1.0);
        // GL11.glMatrixMode(GL11.GL_MODELVIEW);
        // GL11.glPushMatrix();
        // GL11.glLoadIdentity();
        // GL11.glEnable(GL11.GL_TEXTURE_2D);
        // GL11.glEnable(GL11.GL_BLEND);
        // GL11.glEnable(GL11.GL_LINE_SMOOTH);
        // GL11.glDisable(GL11.GL_DEPTH_TEST);
        // GL11.glDisable(GL11.GL_LIGHTING);
        // GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        // GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);

        return true;
    }

    @Override
    public void endRendering() {
        if(swCursor != null) {
            tintStack = tintStateRoot;
            swCursor.render(mouseX, mouseY);
        }
        // GL11.glPopMatrix();
        // GL11.glMatrixMode(GL11.GL_PROJECTION);
        // GL11.glPopMatrix();
        // GL11.glPopAttrib();
    }


This is most likely not the correct way to do things, but it at least partially works, which is better than what I started with. I'm now having issue with buttons not receiving mouse clicks at low resolutions (even though the on-hover effect works fine?). Also, the clipping rectangles seem to not be scaled properly, so some Widgets are only partially visible.

Any ideas on how to do this properly or how to fix my issues would be greatly appreciated. Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2011 5:41 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
If you scale the UI you also have to scale the clipping rectangles and mouse coordinates. This is a non trivial task. I suggest you subclass LWJGLRenderer instead of modifying it.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re:
PostPosted: Sat Sep 22, 2012 11:34 am 
Offline

Joined: Sat Jun 23, 2012 4:14 pm
Posts: 74
Location: Germany
MatthiasM wrote:
If you scale the UI you also have to scale the clipping rectangles and mouse coordinates. This is a non trivial task. I suggest you subclass LWJGLRenderer instead of modifying it.


Hello, I also need a scaled UI, because I'm using g.scale for a pixelated (Slick2D) game I'm working on (so the UI should be pixelated too):
Code:
   @Override
   protected void preRenderState(GameContainer container, Graphics g)
         throws SlickException
   {
      g.scale(SCALE, SCALE);
      g.setAntiAlias(false);
   }


Can you give an example on how I can achieve a scaled TWL rendering, clipping and so on? Thank you in advance!


Top
 Profile  
 
 Post subject: Re: Re:
PostPosted: Mon Oct 01, 2012 11:19 pm 
Offline

Joined: Mon Sep 12, 2011 4:56 pm
Posts: 8
snapy666 wrote:
Can you give an example on how I can achieve a scaled TWL rendering, clipping and so on? Thank you in advance!


Hey snapy666. Yes, I can give you an example of how to scale TWL correctly. I did eventually get a game working with scaled TWL and correct clipping and scaled input and such. Give me a day or two gut my game and put the code into an example project.


Top
 Profile  
 
PostPosted: Tue Oct 02, 2012 5:20 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
Do you want to put that on the Wiki?

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Tue Oct 02, 2012 5:38 am 
Offline

Joined: Mon Sep 12, 2011 4:56 pm
Posts: 8
MatthiasM wrote:
Do you want to put that on the Wiki?


Yeah, no problem. :)

Edit: Here's the page. It's pretty empty now, but I'll fill it in soon.


Top
 Profile  
 
PostPosted: Sat Oct 20, 2012 12:23 pm 
Offline

Joined: Sat Jun 23, 2012 4:14 pm
Posts: 74
Location: Germany
Getterac7 wrote:
MatthiasM wrote:
Do you want to put that on the Wiki?


Yeah, no problem. :)

Edit: Here's the page. It's pretty empty now, but I'll fill it in soon.


Thank you! I'll look forward to it! :D


Top
 Profile  
 
PostPosted: Tue Nov 06, 2012 6:46 pm 
Offline

Joined: Sat Jun 23, 2012 4:14 pm
Posts: 74
Location: Germany
Getterac7 wrote:
Yeah, no problem. :)

Edit: Here's the page. It's pretty empty now, but I'll fill it in soon.


Can you add a method for scaling your game when using TWLStateBasedGame with a specific scale?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 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:  
Powered by phpBB® Forum Software © phpBB Group