Drawing the textures

In the upper-left you can see the texture data. Note: “0,1” should be “0,0”. In the bottom-right you can see the shape that uses the texture data.

OpenGL knows where to find its texture data through texture coordinates. Texture coordinates are coordinates ranging from 0.0 to 1.0 ( (0,0) being upper-left; (1,1) being bottom-left ). They represent a point on the texture. Specify a texture coordinate using the following code.

glTexCoord2f(float, float);

In order for OpenGL to know which texture it wants to extract the data from, the texture needs to be bound. Just like with colours, it uses a global state; only one texture can be bound at a time. The binding of textures works with the following method.

glBindTexture(GL_TEXTURE_2D, texture_id);

You can retrieve your texture id from the texture object by calling.

texture.getTextureID();

Similarly, you can unbind a texture from OpenGL when you no longer need to draw with it.

I keep trying to do it but it won’t work. I get the error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.Sys$1.run(Sys.java:73)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:95)
at org.lwjgl.Sys.(Sys.java:112)
at org.lwjgl.opengl.Display.(Display.java:135)
at org.lwjgldemo.Main.main(Main.java:16)

Sat Nov 02 19:54:20 GMT 2013 WARN:class org.newdawn.slick.opengl.PNGImageData failed to read the data
java.io.IOException: unsupported interlace method
at org.newdawn.slick.opengl.PNGDecoder.readIHDR(PNGDecoder.java:606)
at org.newdawn.slick.opengl.PNGDecoder.(PNGDecoder.java:116)
at org.newdawn.slick.opengl.PNGImageData.loadImage(PNGImageData.java:81)
at org.newdawn.slick.opengl.CompositeImageData.loadImage(CompositeImageData.java:62)
at org.newdawn.slick.opengl.CompositeImageData.loadImage(CompositeImageData.java:43)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:292)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:254)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:200)
at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:64)
at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:24)
at otherClasses.TextTest.main(TextTest.java:32)

or for some textures it just wont work (Diagonal lines randomly instead of a texture)

hi
first i wanna thank you so much because your lessons are my resource for my final project at university:)
I have an odd problem. I put my texture pic in the folder src at the project workspace
I did whatever you did in your video at youtube
BUT when I run my code, the empty window appears for one second and it closed by itself!
why? do you want me to send you my code?
please answer quickly:) thanks:)

Does the program throw an exception? Try putting System.out.println(texture.getID()); after the texture has been loaded. If the program prints out 0, then the texture was never properly loaded. If the program prints out a number > 0, then something else is wrong.

it resolved. thank you:)
I can’t reach youtube anymore because it has been filtered in my country and no anti filters can open it:(
have you upload your videos on another data base? or can I download them anywhere?…

Hi, and thanks for the great tutorials 😀 ! I’m having a slight problem with my code I was hoping you’d know what I did wrong. I did a slight variation of your program with three boxes that are just colored , and of course the textured box. Here’s my problem. The texture loads fine and displays on the box, but there is also a color overlay from one of the boxes that were rendered before. Here’s part of the code that i’m using:

Oskar, your lesson was very helpful, but I have a question. My texture is only mapping to a portion of a quad. I used .getWidth() and .getHeight() on the texture out of curiosity, and the width is 0.66015625 and the height is 0.9453125. I don’t want those numbers. I want 1 and 1. In the glTexCoord2f’s, it even says (0,0), (0,1), (1,1), and (1,0). How can I get the width and height to 1 like they are supposed to be instead of these crazy floats?