的OpenGL ES有不同的UV坐标?坐标、不同、OpenGL、ES

2023-09-05 03:34:14 作者:孤僻似困兽

我使用OpenGL ES 1.1与纹理贴图。我一直认为UV坐标系的纹理开始从左上角,去到右下角。这是精在Android上,我已经测试它。不过,如果我使用Qt测试它在桌面上,我的UV坐标系开始从左下角并进入右上角。这可以吗?我使用的是相同的code设置的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();

我也想知道,为什么会有glOrthof不不支持Android的支持Qt和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和机器人之间的差异,但桌面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.

 
精彩推荐
图片推荐