LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: dangerdoc on July 20, 2013, 20:23:58

Title: Texture Flipped On X and Y axis...
Post by: dangerdoc on July 20, 2013, 20:23:58
My texture is rendering properly, but it is flipped on both the X and Y axis... How can I flip it back?

Code: [Select]
    public static void render(Texture texture, Vector2f min, Vector2f max) {
       
        texture.bind();
        //GL11.glColor3f(0.5f,0.5f,1.0f);
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glTexCoord2f(0f, 0f);
        GL11.glVertex2f(min.x, min.y);
        GL11.glTexCoord2f(1f, 0f);
        GL11.glVertex2f(max.x, min.y);
        GL11.glTexCoord2f(1f, 1f);
        GL11.glVertex2f(max.x, max.y);
        GL11.glTexCoord2f(0f, 1f);
        GL11.glVertex2f(min.x, max.y);
        GL11.glEnd();
       
    }
I read that you switch the texture coordinates... I have tried changing them around and I don't know how to get them right. Can someone enlighten me?
Title: Re: Texture Flipped On X and Y axis...
Post by: Cornix on July 20, 2013, 20:26:54
You are inputting the vertices clockwise, to flip it you have to input the vertices counter-clockwise.

Like this:
Code: [Select]
public static void render(Texture texture, Vector2f min, Vector2f max) {
       
        texture.bind();
        //GL11.glColor3f(0.5f,0.5f,1.0f);
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glTexCoord2f(0f, 0f);
        GL11.glVertex2f(min.x, min.y);
        GL11.glTexCoord2f(0f, 1f);
        GL11.glVertex2f(min.x, max.y);
        GL11.glTexCoord2f(1f, 1f);
        GL11.glVertex2f(max.x, max.y);
        GL11.glTexCoord2f(1f, 0f);
        GL11.glVertex2f(max.x, min.y);
        GL11.glEnd();
       
    }
Title: Re: Texture Flipped On X and Y axis...
Post by: dangerdoc on July 20, 2013, 20:59:29
My err dyslexia said that it was flipped on both actually it was only flipped... I got it to be correct but it didn't look right:

(http://i1154.photobucket.com/albums/p524/dangerdoc44/test_zps75892d3d.png) (http://s1154.photobucket.com/user/dangerdoc44/media/test_zps75892d3d.png.html)
Yeah I used random crap on my computer as the test texture...
Code for this image:
Code: [Select]
public static void render(Texture texture, Vector2f min, Vector2f max) {
       
        texture.bind();
        //GL11.glColor3f(0.5f,0.5f,1.0f);
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glTexCoord2f(0f, 1f);
        GL11.glVertex2f(min.x, min.y);
        GL11.glTexCoord2f(0f, 0f);
        GL11.glVertex2f(min.x, max.y);
        GL11.glTexCoord2f(1f, 0f);
        GL11.glVertex2f(max.x, max.y);
        GL11.glTexCoord2f(1f, 1f);
        GL11.glVertex2f(max.x, min.y);
        GL11.glEnd();
       
    }
You can see that the image is pushed up... Why is this?


Here is the flipped version (uses the code you gave me):
(http://i1154.photobucket.com/albums/p524/dangerdoc44/test2_zps95fbaf11.png) (http://s1154.photobucket.com/user/dangerdoc44/media/test2_zps95fbaf11.png.html)
Stupid dyslexia why didn't I realise it was only flipped...

Title: Re: Texture Flipped On X and Y axis...
Post by: dangerdoc on July 22, 2013, 21:13:53
Please can someone help me? I have tried to understand how the texture points relate to where it is rendered on the screen. Can someone either explain how this works or link me to a place that does explain? I have tried so many things and I think I missed the really important part of it.
Title: Re: Texture Flipped On X and Y axis...
Post by: quew8 on July 23, 2013, 10:12:01
In OpenGL, texture coords are measured from the top of the texture going down. So the top is y = 0, and the bottom is y = 1. Change all your texture coords from y to 1 - y and it should fix it, or you can flip the textures before loading them into OpenGL.
Title: Re: Texture Flipped On X and Y axis...
Post by: dangerdoc on July 23, 2013, 16:14:35
Ahh. That's where I went wrong. I got a bit confused, thinking that X was the verticle axis for textures and I was confused when that didn't fix it. With that info I was able to fix it all. Thanks for the help, and I'm sorry for not writing my post correctly... (stupid dyslexia.. At least it is only minor :P)
Title: Re: Texture Flipped On X and Y axis...
Post by: quew8 on July 24, 2013, 05:55:05
No worries. This gets EVERYONE. Most people just flip the tex coords assuming they made a mistake somewhere else and hope no one notices. And I completely understand.