Reputation: 9
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.
Upvotes: 0
Views: 449
Reputation: 67
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();
Upvotes: 1