Hello Guest

Texture Flipped On X and Y axis...

  • 6 Replies
  • 7216 Views
*

Offline dangerdoc

  • **
  • 75
  • Thats right... Nikola Tesla
Texture Flipped On X and Y axis...
« 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?

*

Offline Cornix

  • *****
  • 488
Re: Texture Flipped On X and Y axis...
« Reply #1 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();
       
    }

*

Offline dangerdoc

  • **
  • 75
  • Thats right... Nikola Tesla
Re: Texture Flipped On X and Y axis...
« Reply #2 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:


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):

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


*

Offline dangerdoc

  • **
  • 75
  • Thats right... Nikola Tesla
Re: Texture Flipped On X and Y axis...
« Reply #3 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.

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: Texture Flipped On X and Y axis...
« Reply #4 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.

*

Offline dangerdoc

  • **
  • 75
  • Thats right... Nikola Tesla
Re: Texture Flipped On X and Y axis...
« Reply #5 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)

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: Texture Flipped On X and Y axis...
« Reply #6 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.