LWJGL Texture Error

Hello! :slight_smile:
I am making a simple 2d game. I load the textures into the game using slick-util . But when the textures are loaded, I get this:

This is my draw function:


public static void draw() {
       glLoadIdentity();
       glTranslatef(blockX[count], blockY[count], 0);
       stone.bind();
       glBegin(GL_QUADS);
            glTexCoord2f(0, 0);
            glVertex2f(0, 0);
            glTexCoord2f(0, 1);
            glVertex2f(0, 50);
            glTexCoord2f(1, 1);
            glVertex2f(50, 50);
            glTexCoord2f(1, 0);
            glVertex2f(50, 0);
       glEnd();
       
       count++;
       
       if (count == 9) {
           Textures.isDrawn = true;
       }

And this is my initGL function:


public static void initGL() {
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, width, 0, height, -1, 1);
        glMatrixMode(GL_MODELVIEW);
        glEnable(GL_TEXTURE_2D);
    }

And this is the texture loader:


public static void loadTextures() {
        try {
            stone = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/stone.png")));
        } catch (IOException ex) {
            Logger.getLogger(textureLoader.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

Please Help!

Thanks!

Peter

Make sure your image has power-of-two dimensions. If it hasn’t, the Slick texture loader will add (black) padding pixels. Another way around this is using texcoords that only specifiy the region of the texture containing the image. Slick has some utility methods for that.

In short: this is not a LWJGL problem, it’s a Slick problem.

The slick utility methods are Texture.getWidth() and getHeight(), so use them instead of 1 for your texcoords.

Thanks ra4king! It worked ;D Thanks very much!