LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: ToXic73 on August 07, 2013, 13:06:03

Title: Problem loading png with slick_util
Post by: ToXic73 on August 07, 2013, 13:06:03
OK, so I am looking into making pong using lwjgl, I have got it all done, I am now adding textures. I would just like to add textures to both paddles. I also have controller input for it, just comment out all that code if you don't have a controller. I will upload all the code to my dropbox, I will add it to github later.

The problem is when the texture is loaded, it chops it up into two parts, any help is appreciated.

The eclipse project: https://www.dropbox.com/s/dfbfaq21mrlpski/Pong1.zip (https://www.dropbox.com/s/dfbfaq21mrlpski/Pong1.zip)
And this paddle image: http://i.imgur.com/HPctM0X.png (http://i.imgur.com/HPctM0X.png)
Title: Re: Problem loading png with slick_util
Post by: Fool Running on August 08, 2013, 12:57:40
It looks like your texture coordinates are wrong. Try the following:

glTexCoord2f(0, texture.getHeight());
glVertex2f(0, sy);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(texture.getWidth(), 0);
glVertex2f(sx, 0);
glTexCoord2f(texture.getWidth(), texture.getHeight());
glVertex2f(sx, sy);

If that fixes it, then the problem is that your texture is not a power-of-two size on the y-axis (200 pixels) so the Texture class is creating a texture that is 256 pixels high so your texture coordinate of 1.0 is getting the extra space not taken up by your image.
Title: Re: Problem loading png with slick_util
Post by: ToXic73 on August 09, 2013, 02:43:11
That was perfect, when I learned about texture coords, I heard that they had to be "normalized" to between 0 and 1, thanks for the solution.