问题描述
我使用带有纹理映射的 OpenGL ES 1.1.我一直认为纹理的 UV 坐标系从左上角开始,到右下角.这在android上很好,我已经测试过了.但是,如果我在桌面上使用 Qt 对其进行测试,我的 UV 坐标系从左下角开始到右上角.那样行吗?我正在使用相同的代码来设置 OpenGL
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();
我也想知道,为什么Qt不支持glOrthof而Android不支持glOrtho?两个框架中是否有共同的功能?
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?
推荐答案
在 OpenGL 中,默认的纹理坐标 (0,0) 对应于纹理的左下角.自从 OpenGL 存在以来,它一直是(并且可能永远是)这样.
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.
顺便说一句,glOrtho
与 Qt 或 Android 无关,它是一个 OpenGL 函数.所以你可能遇到的不是 Qt 和 Android 之间的区别,而是桌面 OpenGL 和 OpenGL ES 之间的区别.但在两个版本中,纹理坐标应该从左下角开始.
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.
这篇关于OpenGL ES有不同的UV坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!