0

I have not been able to load any textures using the TextureLoader class with LWJGL and slick for use with OpenGL. Here is my code:

try {
        sprite = TextureLoader.getTexture("PNG", new FileInputStream("sprite.png"));
    }catch(Exception e) {}

    if(sprite == null) {
        System.out.println("Sprite is null");
    }else {sprite.bind();}

    glBegin(GL_QUADS);
    glTexCoord3f(0, 1, 0);
    glVertex3f(0, 1, 0);
    glTexCoord3f(1, 1, 0);
    glVertex3f(1, 1, 0);
    glTexCoord3f(1, 0, 0);
    glVertex3f(1, 0, 0);
    glTexCoord3f(0, 0, 0);
    glVertex3f(0, 0, 0);
    glEnd();

I know the image is in the same directory in my class, and I don't believe anything is wrong with my OpenGL code because I have been able to draw quads/cubes successfully.

PJCH
  • 9
  • 2
  • 7
  • What is your exact problem? Be detailed in explanation. – Tim Jun 28 '12 at 22:41
  • The texture 'sprite' is null, so I can't use it. – PJCH Jun 28 '12 at 22:45
  • You shouldn't catch and disregard an exception like that. The whole point of the exception is to tell you when something has gone wrong. Try catching the exception and logging e.getMessage() and e.printStackTrace(). – Tim Jun 29 '12 at 01:44
  • Possible duplicate: [Java: Load a resource contained in a jar](http://stackoverflow.com/q/574809/1262542), and others. I've not been able to track down how _exactly_ resources are packed into a jar; _sigh_. – Stefan Hanke Jun 29 '12 at 04:45

1 Answers1

1

I don't know why, but while using lwjgl textures, you have to create a 2d texture image on top of the 3d quad [like so: ]

        glBegin(GL_QUADS);

        glTexCoord2d(0, 0);
        glVertex3d(0, 0, 0);
        glTexCoord2d(1, 0);
        glVertex3d(32, 0, 0);
        glTexCoord2d(1, 1);
        glVertex3d(32, 32, 0);
        glTexCoord2d(0, 1);
        glVertex3d(0, 32, 0);

        glEnd();
Nikhil
  • 67
  • 1
  • 8