Texture Flipped On X and Y axis...

Started by dangerdoc, July 20, 2013, 20:23:58

Previous topic - Next topic

dangerdoc

My texture is rendering properly, but it is flipped on both the X and Y axis... How can I flip it back?

    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?
“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla

Cornix

You are inputting the vertices clockwise, to flip it you have to input the vertices counter-clockwise.

Like this:
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();
        
    }

dangerdoc

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:


Yeah I used random crap on my computer as the test texture...
Code for this image:
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):

Stupid dyslexia why didn't I realise it was only flipped...

“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla

dangerdoc

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.
“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla

quew8

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.

dangerdoc

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)
“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla

quew8

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.