Slick Forums

Discuss the Slick 2D Library
It is currently Tue May 21, 2013 10:00 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: BUG: BigImage scaling
PostPosted: Fri Aug 22, 2008 2:07 am 
Offline
Game Developer
User avatar

Joined: Sun May 25, 2008 9:45 am
Posts: 578
I use a gigantic image for my title screen. I use BigImage and scale it down and position it based on the resolution and aspect ratio. Two issues:

1) When I do a BigImage#getScaledCopy, the result doesn't appear to be a BigImage. Will doing this be safe on cards that can't support such a large image?

2) When I scale down my BigImage with getScaledCopy, the resulting image is square and has a bunch of black space. Unfortunately you'll need this (gigantic) image file to run the test below:
http://n4te.com/temp/title.png

Code:
public class ThingleTest {
   public static void main (String[] args) throws SlickException {
      BasicGame game = new BasicGame("ThingleTest") {
         Image testImage;

         public void init (GameContainer container) throws SlickException {
            testImage = new BigImage("title.png", Image.FILTER_LINEAR);
            testImage = testImage.getScaledCopy(0.1f);

            Graphics g = container.getGraphics();
            g.setBackground(Color.red);
         }

         public void update (GameContainer container, int delta) throws SlickException {
         }

         public void render (GameContainer container, Graphics g) throws SlickException {
            g.drawImage(testImage, 100, 100);
         }
      };
      AppGameContainer container = new AppGameContainer(game);
      container.setDisplayMode(600, 800, false);
      container.start();
   }
}


Going camping so I won't be back to programming until Monday. :cry:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 4:40 am 
Offline
Game Developer
User avatar

Joined: Sun May 25, 2008 9:45 am
Posts: 578
Ignore #1, BigImage#getScaledCopy does return a BigImage.

For #2, turns out it has nothing to do with the scaling. On my hardware, internally the BigImage uses a 2048x2048 texture to hold the 1920x1200 image. The part of the texture not occupied by the image is black, as demostrated here...

Code:
public class ThingleTest {
   public static void main (String[] args) throws SlickException {
      BasicGame game = new BasicGame("ThingleTest") {
         Image testImage;

         public void init (GameContainer container) throws SlickException {
            testImage = new BigImage("title.png", Image.FILTER_LINEAR);
            container.getGraphics().setBackground(Color.red);
         }

         public void update (GameContainer container, int delta) throws SlickException {
         }

         public void render (GameContainer container, Graphics g) throws SlickException {
            g.drawImage(testImage, 100, -1100);
         }
      };
      AppGameContainer container = new AppGameContainer(game);
      container.setDisplayMode(600, 800, false);
      container.start();
   }
}


If I replace the drawImage call above with this...
Code:
g.drawImage(testImage, 100, 100, 100 + 384, 100 + 240, 0, 0, 1920, 1200);

...then internally it calls getSubImage which creates a new BigImage of the correct size, not 2048x2048, and is displayed correctly. The workaround I have for this bug then is this:
Code:
testImage = new BigImage("title.png", Image.FILTER_LINEAR);
testImage = testImage.getSubImage(0, 0, testImage.getWidth(), testImage.getHeight());
...then later...
testImage.draw(100, 100, 384, 240);


Interestingly, I don't think there is a performance gain by using getScaledCopy, which is why I was trying to use it. Is this true? I thought it might be draining to scale a 1920x1200 image down to 800x600 (for example) a hundred times or so per second.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 7:13 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
It's just the texture coordinates that are scaled, and it's done once. Other than that it's the same.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 31, 2008 4:11 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
In case this still matters to anyone :)

Fixed in SVN.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2008 12:50 am 
Offline
Game Developer
User avatar

Joined: Sun May 25, 2008 9:45 am
Posts: 578
It matters to me! I took out my getSubImage workaround and it is indeed fixed. Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 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