0
votes

I am using the LWJGL and Slick-Util libraries in an attempt to rotate a texture. Here is my code I'm using to try and rotate a texture.

GL11.glBegin(GL11.GL_QUADS);

GL11.glPushMatrix();
GL11.glTranslatef(x, y, 0);
GL11.glRotatef(r, 1, 1, 0);

GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());
GL11.glTexCoord2f(0, 0);
GL11.glVertex2f(x, y);
GL11.glTexCoord2f(1, 0);
GL11.glVertex2f(x + texture.getTextureWidth(), y);
GL11.glTexCoord2f(1, 1);
GL11.glVertex2f(x + texture.getTextureWidth(), y + texture.getTextureHeight());
GL11.glTexCoord2f(0, 1);
GL11.glVertex2f(x, y + texture.getTextureHeight());

GL11.glPopMatrix();

GL11.glEnd();

It draws the texture perfectly fine at the x and y locations given, but when I pass in a degree, it does not rotate and just draws as if the rotation was zero.

Does anyone know what I'm doing wrong? Thank you in advance.

Edit:

When I run this code with an 'r' of 180 or any other degree. This is what my screen looks like. The red circle image looks exactly like that as a regular un-rotated image.

enter image description here

1
What if you rotate first and then translate ?Abhishek Bansal
It still doesn't work :/ Any other ideas?BigBerger
Your code looks correct to me. Can you upload image of ur outputs ?Abhishek Bansal
Check the edits I made in the question, I've uploaded an image of my code run.BigBerger
what happens if you rotate along z only of any other single axis ? Are u using ortho2D ?Abhishek Bansal

1 Answers

0
votes

I know it is a bit egotistical to answer your own questions, but after much research I have finally found my answer. Here is a working method that will rotate a slick-util texture according to an 'r' given in degrees.

public static void drawTexture(Texture texture, int x, int y, int r)
{
        int width = texture.getTextureWidth();
        int height = texture.getTextureHeight();

        GL11.glTranslatef(x + width / 2, y + height / 2, 0);
        GL11.glRotatef(r, 0, 0, 1);

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());
        GL11.glBegin(GL11.GL_QUADS);

        GL11.glTexCoord2f(0, 0);
        GL11.glVertex3f(-width / 2, -height / 2, 0);

        GL11.glTexCoord2f(1, 0);
        GL11.glVertex3f(width / 2, -height / 2, 0);

        GL11.glTexCoord2f(1, 1);
        GL11.glVertex3f(width / 2, height / 2, 0);

        GL11.glTexCoord2f(0, 1);
        GL11.glVertex3f(-width / 2, height / 2, 0);

        GL11.glEnd();
        GL11.glLoadIdentity();
}