Slick Forums

Discuss the Slick 2D Library
It is currently Wed May 22, 2013 4:23 pm

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Fri Feb 24, 2012 7:20 am 
Offline

Joined: Sun Feb 05, 2012 2:40 am
Posts: 10
Anyone got any tips on how to do this? Using the inbuilt Slick Image.class seems to result in the image getting darker the further along the x-axis it goes, for the first 900-1000px it is not really noticeable but after that is gets really dark. At first I though it was my monitor but when i rendered it in reverse the right hand side looks fine but the more -x it gets the darker it gets again. The image is just 1px by 14px so I wouldn't expect that to happen (image attached).

Code:
    Image horizontalBorder;
    {
   try {
       horizontalBorder = new Image(TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(RESOURCE_FOLDER + "/border_horizontal.png")));
   } catch (IOException e) {
       throw new RuntimeException(e);
   }
    }

    @Override
    public void render(GameContainer container, Graphics g) {
   horizontalBorder.draw(0, 0, Display.getWidth(), 14);
    }


Attachments:
border_horizontal.png
border_horizontal.png [ 168 Bytes | Viewed 351 times ]
Top
 Profile  
 
PostPosted: Fri Feb 24, 2012 9:48 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Can't reproduce the problem stretching your image to 1920 pixels; looks fine all the way across on my monitor. Try providing a self-contained test.


Top
 Profile  
 
PostPosted: Sat Feb 25, 2012 9:48 pm 
Offline

Joined: Sun Feb 05, 2012 2:40 am
Posts: 10
Full app below. Just put in the default package with the png in the same place.

I have also noticed the top left corner of the screen is not actually 0,0 in windowed mode. it is around (0,10). If you look at my render method I have to put a buffer into the y co-ord to get it to be visible. In fullscreen mode 0,0 works fine.

Another thing I have noticed is using rotate on the same image cause the top left corner of the image to become (-7, -0.5). i.e. if you want to draw it you have to do .draw(7,0). Shouldn't rotate reset the actual x,y co-ords?

I am running jdk 1.6, winxp 32bit and a ATI HD6850 if that makes any difference.

Code:
import java.io.IOException;

import org.lwjgl.opengl.Display;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.Game;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;

public class CopyOfBioroidGame implements Game {

    Image horizontalBorder;

    @Override
    public boolean closeRequested() {
   return true;
    }

    @Override
    public String getTitle() {
   return "test";
    }

    public static void main(String[] args) throws SlickException {
   CopyOfBioroidGame bioroidGame = new CopyOfBioroidGame();

   AppGameContainer agc = new AppGameContainer(bioroidGame);
   agc.setDisplayMode(Display.getDesktopDisplayMode().getWidth(), Display.getDesktopDisplayMode().getHeight(), false);
   agc.setTargetFrameRate(70);
   agc.start();
    }

    @Override
    public void init(GameContainer container) throws SlickException {
   try {
       horizontalBorder = new Image(TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("border_horizontal.png")));
   } catch (IOException e) {
       throw new RuntimeException(e);
   }
    }

    @Override
    public void update(GameContainer container, int delta) throws SlickException {
   if (container.getInput().isKeyPressed(Input.KEY_ESCAPE)) {
       container.exit();
   }
    }

    @Override
    public void render(GameContainer container, Graphics g) throws SlickException {
   horizontalBorder.draw(0, 15, Display.getWidth(), 14);
    }
}


Top
 Profile  
 
PostPosted: Sat Feb 25, 2012 11:34 pm 
Offline

Joined: Sun Dec 25, 2011 5:48 pm
Posts: 34
KorganBloodAxe wrote:
I have also noticed the top left corner of the screen is not actually 0,0 in windowed mode. it is around (0,10). If you look at my render method I have to put a buffer into the y co-ord to get it to be visible. In fullscreen mode 0,0 works fine.
[/code]


This is something i've noticed too, and its annoying. You might think its easy to solve by putting a y-buffer, but infact it's not. Whether you need a buffer or not depends on what OS you run the program on. Win7 needs a buffer, windows xp does not. I don't know about the rest.

Anyway, I wish I could help you with your problem but I don't know how. But it happens to me aswell, although I kind of liked how it looked like so I kept it that way. If I manage to find a solution then ill tell you.


Top
 Profile  
 
PostPosted: Sun Feb 26, 2012 12:28 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Here's what's happening:
Your 1x14 image is being converted to a 2x32 OpenGL texture by Slick. The extra pixels are filled with transparent black pixels. When you up-size your texture with linear filtering, the colour pixels are blended with the transparent black pixels, resulting in the "fade" you are seeing (but only on the right side).

The best way to fix this is to use FILTER_NEAREST scaling when you construct the image.
Code:
horizontalBorder = new Image(RESOURCE_FOLDER + "/border_horizontal.png", false, Image.FILTER_NEAREST);


Alternatively, you could make your border graphic 2 pixels wide instead of just 1, which would allow you to use linear filtering.


Top
 Profile  
 
PostPosted: Sun Feb 26, 2012 1:00 am 
Offline

Joined: Sun Feb 05, 2012 2:40 am
Posts: 10
Thanks mate that is perfect, it works when I use the Image(String, false, filter) constructor.

Just out of interest though, is there a bug in the texture loader? It seems to to result in a white box when I do the following:

Code:
Texture tex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(RESOURCE_FOLDER + "/border_horizontal.png"), false,
          Image.FILTER_NEAREST);
horizontalBorder = new Image(tex);


Is there a common workaround that I can use for the windowed mode offset problem I described above?


Top
 Profile  
 
PostPosted: Sun Feb 26, 2012 1:37 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
If you're using TextureLoader or InternalTextureLoader, the passed filter should be an OpenGL type:
Code:
SGL.GL_LINEAR (same as GL11.GL_LINEAR)
SGL.GL_NEAREST (same as GL11.GL_NEAREST)


Ideally Image constants should match the OpenGL values -- I'll bring it up with the other devs and see if we can get that fixed.

KorganBloodAxe wrote:
I have also noticed the top left corner of the screen is not actually 0,0 in windowed mode. it is around (0,10). If you look at my render method I have to put a buffer into the y co-ord to get it to be visible. In fullscreen mode 0,0 works fine.

The folks in #lwjgl tell me it's a bug on Windows with LWJGL; it should be fixed with the latest version of LWJGL. Update your lwjgl.jar and natives (and restart Eclipse/NetBeans to clear its cache) and let us know if it works.

Quote:
Another thing I have noticed is using rotate on the same image cause the top left corner of the image to become (-7, -0.5). i.e. if you want to draw it you have to do .draw(7,0). Shouldn't rotate reset the actual x,y co-ords?

Probably due to this bug:
viewtopic.php?f=1&t=4569

If you're planning to rotate your image to make it a "vertical border", here's a simple solution:
Code:
       int x = 0, y = 0, borderHeight = 14;
       g.rotate(x,  y, 90);
       //draw the image from its bottom-left corner, stretched to the HEIGHT of the screen
       horizontalBorder.draw(x, y-borderHeight, gameContainer.getHeight(), borderHeight);
       g.rotate(x, y, -90);


Top
 Profile  
 
PostPosted: Sun Feb 26, 2012 2:11 am 
Offline

Joined: Sun Feb 05, 2012 2:40 am
Posts: 10
Thanks for all the help davedes. I think I have enough to get me going again, sorry I am a bit of a newbie when it comes to the graphics stuff.

Unfortunately that lwjgl windowed (Y-coord) problem still exists even with the latest nightly build 2.8.4. I might log a bug on their forums and see what happens. Thanks again for all your help.


Top
 Profile  
 
PostPosted: Sun Feb 26, 2012 4:42 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Strange that it's still there - that might suggest it's something on Slick's end. I'll boot up my old Windows laptop tomorrow and see if I can test it out.

For the time being, here are two workarounds. Either one will (hopefully) fix the problem.
  • Set the display mode to a smaller resolution, such as 800x600 or 640x480
  • Use the following VM flag to remove the window title bar:
    Code:
    -Dorg.lwjgl.opengl.Window.undecorated=true

    Or call setProperty before initializing your game container.
    Code:
    System.setProperty("org.lwjgl.opengl.Window.undecorated", "true");


Top
 Profile  
 
PostPosted: Sun Feb 26, 2012 5:06 am 
Offline

Joined: Sun Feb 05, 2012 2:40 am
Posts: 10
Thanks. The undecorated flag also does the trick and I will make that the default.

I am leaning towards it being slick as well - my lwjgl examples render 0,0 correctly in both windowed and full screen.


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

All times are UTC


Who is online

Users browsing this forum: raeleus and 2 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