Results 1 to 6 of 6
  1. #1
    Zelaine is offline Senior Member
    Join Date
    Aug 2013
    Location
    Sweden
    Posts
    161
    Rep Power
    2

    Question LWJGL - Blurry Images

    I wanted to use 16x16 pixel images in my game to make it look more "pixely", but the images get really blurry when they're rendered. How do I make them clearer?

    Java Code:
    import static org.lwjgl.opengl.GL11.*;
    import org.lwjgl.opengl.*;
    import org.lwjgl.*;
    import org.lwjgl.input.Mouse;
    import org.lwjgl.input.Keyboard;
    import org.newdawn.slick.opengl.Texture;
    import org.newdawn.slick.opengl.TextureLoader;
    
    import java.io.*;
    
    public class Test{
    	int DISPLAY_WIDTH = 1000, DISPLAY_HEIGHT = 500;
    	
    	Texture BALL, BLUE_PLATFORM, RED_PLATFORM;
    	
    	public Test(){
    		try{
    			Display.setDisplayMode(new DisplayMode(DISPLAY_WIDTH, DISPLAY_HEIGHT));
    			Display.setTitle("Ball Game");
    			Display.create();
    		}catch(LWJGLException e){
    			e.printStackTrace();
    		}
    		
    		BALL = loadTexture("ball");
    		BLUE_PLATFORM = loadTexture("blueplatform");
    		RED_PLATFORM = loadTexture("redplatform");
    		
    		glMatrixMode(GL_PROJECTION);
    		glLoadIdentity();
    		glOrtho(0, DISPLAY_WIDTH, DISPLAY_HEIGHT, 0, 1, -1);
    		glMatrixMode(GL_MODELVIEW);
    		glEnable(GL_TEXTURE_2D);
    		glEnable(GL_BLEND); 
    		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    		
    		while(!Display.isCloseRequested()){
    			glClear(GL_COLOR_BUFFER_BIT);
    			
    			if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)){
    				Display.destroy();
    				System.exit(0);
    			}
    			
    			BALL.bind();
    			
    			glBegin(GL_QUADS);
    				glVertex2i(100, 100);
    				glTexCoord2f(0, 0);
    				glVertex2i(200, 100);
    				glTexCoord2f(1, 0);
    				glVertex2i(200, 200);
    				glTexCoord2f(1, 1);
    				glVertex2i(100, 200);
    				glTexCoord2f(0, 1);
    			glEnd();
    			
    			Display.update();
    			Display.sync(60);
    		}
    		
    		Display.destroy();
    	}
    	
    	private Texture loadTexture(String key){
    		try{
    			return TextureLoader.getTexture("PNG", new FileInputStream(new File("res/" + key + ".png")));
    		}catch(FileNotFoundException e) {
    			e.printStackTrace();
    		}catch(IOException e){
    			e.printStackTrace();
    		}
    		return null;
    	}
    	
    	public static void main(String[] args){
    		new Test();
    	}
    }

  2. #2
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,350
    Rep Power
    6

    Default Re: LWJGL - Blurry Images

    Perhaps the texture is being stretched while you want it to repeat in stead. I'd investigate the different ways of applying a texture in OpenGL.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Zelaine is offline Senior Member
    Join Date
    Aug 2013
    Location
    Sweden
    Posts
    161
    Rep Power
    2

    Default Re: LWJGL - Blurry Images

    Hm. It shouldn't be stretched, the box being 100 pixels wide and 100 pixels tall. Maybe I could show you a picture of what it looks like?

    I'd investigate the different ways of applying a texture in OpenGL.
    I'll try that.

  4. #4
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: LWJGL - Blurry Images

    Can you put up a picture of the problem? Also, Id investigate other ways of rendering things completely. Look at Vertex Buffer Objects and Display Lists.

    Also, make sure all texture sizes are powers of 2 and id recommend they are square. I've had the most success with 512x512 images.
    Last edited by zFollette; 01-21-2014 at 01:36 AM.

  5. #5
    Zelaine is offline Senior Member
    Join Date
    Aug 2013
    Location
    Sweden
    Posts
    161
    Rep Power
    2

    Default Re: LWJGL - Blurry Images

    I changed the code a little bit, the pictures are now clear, but some images are not showed in their entirety. I believe it's only showing the top left pixel of the images, but I am not sure.

    Here's a picture of what it looks like: LWJGL - Imgur
    Compare what the platforms are supposed to look like (if you can, they are a bit small so it's hard to see) and how they are rendered. The rendering only shows one color, even though the picture contains several different colors. The ball works though, the only issue is that it is mirrored but I guess that doesn't matter really.

    Also, make sure all texture sizes are powers of 2 and id recommend they are square.
    Yeah, they are :) 16x16 and 32x16.

  6. #6
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: LWJGL - Blurry Images

    Here is why your image is mirrored. The coordinate system is weird. 0, 0 is bottom left. 1, 1 is top right. 0, 1 is top left, and 1, 0 is bottom right.

    LWJGL - Blurry Images-ccs-8549-0-98845200-1307472511_thumb.jpg

    Can you post code for the other textures?

    EDIT: Call glTexCoord2f BEFORE you call glVertex2i
    Last edited by zFollette; 01-23-2014 at 12:23 AM.

Similar Threads

  1. Another LWJGL Question
    By zFollette in forum Advanced Java
    Replies: 0
    Last Post: 01-07-2014, 09:36 PM
  2. LWJGL - Where to go from here
    By mitchbutter1210 in forum Advanced Java
    Replies: 0
    Last Post: 06-27-2012, 06:37 AM
  3. LWJGL help please
    By Brandon@JavaForums in forum Advanced Java
    Replies: 12
    Last Post: 12-31-2011, 11:19 AM
  4. lwjgl help PLEASE!
    By Brandon in forum New To Java
    Replies: 1
    Last Post: 10-06-2011, 07:11 AM
  5. Text looks blurry at point size below 9
    By TAdamson1981 in forum Java 2D
    Replies: 1
    Last Post: 04-28-2009, 06:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •