Search code examples
javawindowlwjglslick2d

texture not loading properly slick java


texture is not loading properly it has lines and it is backwards. what is wrong. EDIT: I chopped some irrelevant code off so some things may look weird.

package package01;


import java.io.IOException;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;


public class Graph {

    ...

public void initGraph(){

    ... 


        Texture strbutton,defbutton,vitbutton,intbutton,dexbutton,agibutton;
        try {
            strbutton = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("/res/grphbuttons/strbutton.png"));
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            strbutton.bind();
        GL11.glBegin(GL11.GL_QUADS);
            GL11.glTexCoord2f(0,0);
            GL11.glVertex2f(70,120);
            GL11.glTexCoord2f(0,1);
            GL11.glVertex2f(70,120+strbutton.getImageHeight());
            GL11.glTexCoord2f(1,1);
            GL11.glVertex2f(70+strbutton.getImageWidth(),120+strbutton.getImageHeight());
            GL11.glTexCoord2f(1,0);
            GL11.glVertex2f(70+strbutton.getImageWidth(),120);

        GL11.glEnd();
            GL11.glDisable(GL11.GL_TEXTURE_2D);
        } catch (IOException e) {
            e.printStackTrace();
        }

    ...

    }
}

This is the main class

package package01;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

public class DisplayScreen {
CharCreateScreen ccs = new CharCreateScreen();


void start(){
    initGL(1000,562);

    while(!Display.isCloseRequested()){
        ccs.openccscreen();
        Display.update();


    }
    Display.destroy();
}
void initGL(int width, int height){
    try {
        Display.setDisplayMode(new DisplayMode(1000,562));
        Display.create();
        Display.setVSyncEnabled(true);
    } catch(LWJGLException e) {
        e.printStackTrace();
        System.exit(0); 
    }

    GL11.glClearColor(0.9f, 0.9f, 1.0f, 0.0f);


    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glLoadIdentity();
    GL11.glOrtho(-500, 500, -281, 281, -1, 1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
}


public static void main(String[] args){

    DisplayScreen ds = new DisplayScreen();
    ds.start();

}
}

I keep encountering problems with loading the texture to slick, what's the problem this time? Can't I just load the image and put it on the screen without having this weird applying to textures? I'm only using slick to be able to upload a few images to use as buttons is there an easier way.

Here is what comes out. https://i.sstatic.net/onto1.png The button is labeled 'STR' or at least it should be. And what are those lines on the top and right?!


Solution

  • Try change it to

    GL11.glTexCoord2f(0,0);
    GL11.glTexCoord2f(1,0);
    GL11.glTexCoord2f(1,1);
    GL11.glTexCoord2f(0,1);
    

    From

    GL11.glTexCoord2f(0,0);
    GL11.glTexCoord2f(0,1);
    GL11.glTexCoord2f(1,1);
    GL11.glTexCoord2f(1,0);
    

    Didn't have a good look at your code though.