2

I use OpenGL ES 1.1 with texture mapping. I always thought that UV coordinate system for textures starts from the top-left and goes to bottom-right. This is fine on android, I have tested it. However, if I test it with Qt on the desktop, my UV coordinate system starts from the bottom-left and goes to top-right. Is that OK? I am using the same code to setup OpenGL

glViewport(0, 0, m_screenWidth, m_screenHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

#ifdef DESKTOP_QT
glOrtho(0, 1, 0, 1, -1, 1);
#else
glOrthof(0, 1, 0, 1, -1, 1);
#endif

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

Also I wonder, why there is glOrthof is not supported by Qt and glOrtho is not supported by Android? Is there a function that is common in both frameworks?

psyched
  • 1,859
  • 1
  • 21
  • 28

2 Answers2

2

In OpenGL by default the texture coordinate (0,0) corresponds to the lower left corner of the texture. It has always been (and probably will always be) that way since OpenGL exists.

Nevertheless you can change this convention by altering the texture matrix or by just storing your texture flipped bottom to top.

And by the way, glOrtho has nothing to do with Qt or Android, it's an OpenGL function. So what you are probably experiencing is not a difference between Qt and Android, but between desktop OpenGL and OpenGL ES. But nevertheless texture coordinates should start at the bottom left corner in both versions.

Christian Rau
  • 45,360
  • 10
  • 108
  • 185
  • 1
    You can look here http://www.youtube.com/watch?feature=player_detailpage&v=_WcMe4Yj0NM#t=2439s This is OpenGL ES tutorial from Stanford's University, I doubt that guy can be wrong. The UV coordinates should start from top-left – psyched Dec 24 '11 at 07:12
  • @user1113852 Maybe this guy speaks about the theoretical texturing concept or whatever. But **in OpenGL the texture coordinate system starts at the lower left corner**. You can get it in bold and captilal letters if you ask me again. – Christian Rau Dec 25 '11 at 02:49
  • You can use whatever letters you want, but I still have my y-down UV coordinates on android. For god sake, why is it happening? – psyched Dec 28 '11 at 14:15
  • 1
    Is your camera inverted? When you call glOrtho or glPerspective, you set which direction the "camera" is facing, including which way is up/down. I had a similar issue and it's because when I was calling GLOrtho I was inverting the viewport. –  Feb 17 '12 at 00:35
  • The other problem could be how you're loading in the textures. When loading a file, most image processing libraries will read your texture into a data structure with the origin 0,0 at the top left. If you need some sample code for how to do that let me know. –  Feb 17 '12 at 00:41
0

How do you know that the texture is starting from the bottom left and goes to the top right? I have never heard of this type of orientation for texture mapping.

Kizik Studios
  • 179
  • 2
  • 12
  • 1
    In fact this is exactly how OpenGL has done it and will do it since the beginning of time. – Christian Rau Dec 23 '11 at 23:31
  • 1
    @ChristianRau can I suggest being a little more polite? I realize that he probably ruffled your pride feathers by saying he disagrees with you, but you don't need to start being sarcastic with the way you're replying. If you can't keep your cool then just walk away and find something else to do. –  Feb 17 '12 at 00:37
  • 2
    @AscensionSystems I wouldn't really regard that comment impolite or overly sarcastic. He himself spoke of **never** hearing of this type of orientation for texture mapping, which is a rather strong word when used to answer a question about OpenGL (where this type of orientation has always been and will always be standard). But well, if you find it that impolite, politically incorrect or arrogant, feel free to flag it as offensive. – Christian Rau Feb 17 '12 at 01:06
  • 1
    @ChristianRau "You can get it in bold and captilal letters if you ask me again" - That's pretty strong. I don't feel a need to flag anything, just saying that if you find someone who is looking for help but unwilling to accept the right answer, let that be their problem rather than letting it get to you. :) –  Feb 17 '12 at 23:06
  • 1
    @AscensionSystems Ah, you mean the other answer. Ok, I have to admit that this comment was maybe a bit too sarcastic, got it. – Christian Rau Feb 17 '12 at 23:16