Drawing 2D Image help

Started by acevik94, September 02, 2017, 23:10:37

Previous topic - Next topic

acevik94

Hey everybody,
First sorry for my bad English, but I try to give my best :).
So.... I have a problem with drawing 2D images on my screen.
Here is a screenshot, in order that you can understand me better:
https://www2.pic-upload.de/img/33853706/problem.png

As you can see, my program draws the image on the screen, but it also
draws 2 white lines with an invisible space between the lines and the picture.
Can you please explain me, where do these lines and the space come from?
How can I fix this problem?
My Main class:
package Launcher;

import org.lwjgl.opengl.*;

import static Renderer.Renderer.*;

public class Main{
	
	public Main(){
		BeginSession();

		while(!Display.isCloseRequested()){
			
			DrawTexture(QuickLoad("1"), 25, 25, 500, 500);
			
			Display.update();
			Display.sync(60);
		}
		
		Display.destroy();
	}
	
	public static void main(String[] args){
		new Main();
	}
	
}


And renderer class:
package Renderer;

import static org.lwjgl.opengl.GL11.*;

import java.io.IOException;
import java.io.InputStream;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.*;
import org.newdawn.slick.opengl.*;
import org.newdawn.slick.util.ResourceLoader;
public class Renderer{

	public static final int WIDTH = 2048, HEIGHT = 1400;
	
	public static void BeginSession(){
		Display.setTitle("Test");
		try{
			Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
			Display.create();
		}catch(LWJGLException e){
			e.printStackTrace();
		}
		
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, WIDTH , HEIGHT, 0, 1, -1);
        glMatrixMode(GL_MODELVIEW);
        glEnable(GL_TEXTURE_2D);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	}
	
    public static void DrawTexture(Texture tex, float x, float y, float width, float height){
        tex.bind();
        glTranslatef(x, y, 0);
        glBegin(GL_QUADS);
        glTexCoord2f(0, 0);
        glVertex2f(0, 0);
        glTexCoord2f(1, 0);
        glVertex2f(width, 0);
        glTexCoord2f(1, 1);
        glVertex2f(width, height);
        glTexCoord2f(0, 1);
        glVertex2f(0, height);
        glEnd();
        glLoadIdentity();
    }
    
    public static Texture LoadTexture(String path, String fileType){
    	Texture texture = null;
    	InputStream in = ResourceLoader.getResourceAsStream(path);
    	try {
			texture = TextureLoader.getTexture(fileType, in);
		} catch (IOException e) {
			e.printStackTrace();
		}
    	
    	return texture;
    }
    
    public static Texture QuickLoad(String name){
        Texture tex = null;
        tex = LoadTexture("res/" + name + ".jpg", "JPG");
        return tex;
    }
	
}