Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 25, 2013 9:27 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Oct 12, 2009 1:27 am 
Offline

Joined: Mon Oct 12, 2009 12:35 am
Posts: 1
Location: Brazil
Hello everybody.
While displaying a 800x600 image scaled to fit a 1024x768 screen, I noticed that the interpolation algorithm being used was nearest neighbour. This is the code where I construct the image:
Code:
    @Override
    public void init(GameContainer container) throws SlickException {
        final InputStream in = getClass().getResourceAsStream("/slick/img/bg.png");
        background = new Image(in, "bg", false);
    }

    public void render(GameContainer container, Graphics g) throws SlickException {
        background.draw(0, 0, container.getWidth(), container.getHeight());
    }

    public static void main(String[] args) throws SlickException {
        AppGameContainer app =
                new AppGameContainer(new MyGame());
        app.setDisplayMode(1024, 768, false);
        app.start();
    }

After that, I used the 4 arguments Image constructor:
Code:
    @Override
    public void init(GameContainer container) throws SlickException {
        final InputStream in = getClass().getResourceAsStream("/slick/img/bg.png");
        background = new Image(in, "bg", false, Image.FILTER_LINEAR);
    }

But it had no effect.
Taking a look at the source code I found a possible bug in the method load of Image class (see the comments on the code):
Code:
private void load(InputStream in, String ref, boolean flipped, int f, Color transparent) throws SlickException {
   // this.filter receives SGL.GL_LINEAR value
   this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
   
   try {
      this.ref = ref;
      int[] trans = null;
      if (transparent != null) {
         trans = new int[3];
         trans[0] = (int) (transparent.r * 255);
         trans[1] = (int) (transparent.g * 255);
         trans[2] = (int) (transparent.b * 255);
      }
      // filter has SGL.GL_LINEAR value here (which is different from FILTER_LINEAR), so filter receives SGL.GL_NEAREST
      texture = InternalTextureLoader.get().getTexture(in, ref, flipped, filter == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST, trans);
   } catch (IOException e) {
      Log.error(e);
      throw new SlickException("Failed to load image from: "+ref, e);
   }
}

As a workaround, I am creating a Texture and constructing the image with it:
Code:
    final InputStream in = getClass().getResourceAsStream("/slick/img/bg.png");
    Texture texture = InternalTextureLoader.get().getTexture(in, "bg", false, GL11.GL_LINEAR);
    background = new Image(texture);


The 0.3 tag on SVN seems to not have this issue, but the current build (b269) apparently is affected.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 23, 2009 8:16 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Your bug spot was right, great stuff. Fixed in SVN.

Kev


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