Problem loading png with slick_util

Started by ToXic73, August 07, 2013, 13:06:03

Previous topic - Next topic

ToXic73

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
And this paddle image: http://i.imgur.com/HPctM0X.png

Fool Running

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.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

ToXic73

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.