LWJGL - Issue Binding Texture To An OpenGL Quad

Hello,

I’ve recently started toying with OpenGL, LWJGL and Slick2D. I’ve been having an issue binding a png (loaded into an instance of the Texture class) to an OpenGL quad. Currently it is just displaying a purple box the size of the texture. How could I correctly bind the texture to the quad?

My source:

Game.java: http://pastebin.com/NqYshUXN
Entity.java: http://pastebin.com/fUe5cWFp
GameKeyboard.java: http://pastebin.com/emAkMNmY

Thanks in advance.

You didn’t bind the texture and you didn’t set the texture coords.

Try this.


player.texture.bind();

GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0); GL11.glVertex2f(player.x, player.y ); //Top-left
GL11.glTexCoord2f(1, 0); GL11.glVertex2f(player.x + player.texture.getTextureWidth(), player.y);//Top-right
GL11.glTexCoord2f(1, 1); GL11.glVertex2f(player.x + player.texture.getTextureWidth(), player.y + player.texture.getTextureHeight());//Bottom-right
GL11.glTexCoord2f(0, 1); GL11.glVertex2f(player.x, player.y + player.texture.getTextureHeight());//Bottom-left
GL11.glEnd();

Also, I don’t know if using the texture dimensions to set the quad will turn out pretty well. Better, replace the player.texture.getTextureWidth and height with fixed values, at least for testing purposes.

I added your code. The sprite is being displayed, but not as I would’ve expected it.

Source is the same, just with the extra stuff you told me to include + I flipped the sprite vertically.

What did you expect from the sprite? Transparency? Increased size?

I didn’t expect the black bars running through the sprite. Transparency would also be nice.

To get transparency, you have to enable blending.


glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

This will get the transparency.

plis do from
[.img]http://[/img]
to
[.img width=840][/img]
so we can see the image more clearly. You can put any width.

(Without dots)

I used your code, it’s transparent (in most places).

Why is it rendering with those random colours?

For reference, here’s the png I’m trying to render.