我正在为Android开发一个OpenGL ES 1.1应用程序(OpenGL调用是由通过NDK调用的C代码制作的)。Android上的OpenGL ES 1.1:Q纹理坐标没有任何效果
我的问题是,我试图使用Q纹理坐标以及通常的(S,T)纹理坐标。但是,我对Q所做的任何事情都没有任何明显的影响。 (另外:想要用Q坐标来玩的原因是我想用正确的透视效果(即不是仿射)将矩形纹理映射到空间中的梯形四边形 - 如http://www.xyzw.us/~cass/qcoord/所述)。
我的方法试图设置Q坐标(对于默认的1.0f以外的东西)是通常的:我提供4个纹理坐标,而不是通常的2.我试过把各种值Q坐标(甚至进入通常未使用的R坐标,如果两者混淆),对我的纹理没有明显影响。我期望从Q!= 1.0看到我的纹理效果 - 例如,对于每个纹理坐标,Q = 0.5应该将每个导出的(S,T)值加倍 - 实际上,将表观纹理大小减半。但没有改变。
我真的不能发布完整的代码,但这里的基本面:
我的顶点结构定义如下:
typedef struct
{
GLfloat x, y, z; // 3 x spacial coord - 12 bytes
GLfloat tx, ty, tr, tq; // 4 x texture coord - 16 bytes
GLfloat padding[1]; // make it up to 32 bytes (or 8 floats, in effect)
} VertexData;
创建每个顶点缓冲对象(VBO):
// alloc space for my vertex buffer
int vertexBufferSize = numVertices * sizeof(VertexData);
VertexData* vertexData = (VertexData *)malloc(vertexBufferSize);
..//for each vertex I'm creating:
vertex.x = (... appropriate coord)
vertex.y = (... appropriate coord)
vertex.z = (... appropriate coord)
vertex.tx = (... appropriate coord) // AKA the 's' texture coord
vertex.ty = (... appropriate coord) // AKA the 't' texture coord
vertex.tr = 0.5f; // 'R' texture coord. Usually ignored, but I set in case of mixup between Q and R
vertex.tq = 0.5f; // 'Q' texture coord
下面是我如何给我的顶点和文本坐标指针:
glVertexPointer(3, GL_FLOAT, stride, (GLvoid*)((char*)NULL));
// note the 4 below - we want to give 4 tex coordinates, not 2.
// 3*4 corresponds to the offset of texture coords in the VertexData struct
glTexCoordPointer(4, GL_FLOAT, 32 /*stride*/, (GLvoid*)((char*)NULL + 3*4));
这一切都工作得很好,除非我说,我的Q坐标没有区别。如果改变我glTextCoordPointer
呼吁只提供2个或3个坐标,没有在程序的行为没有改变:
glTexCoordPointer(2, GL_FLOAT, 32 /*stride*/, (GLvoid*)((char*)NULL + 3*4));
// OR:
glTexCoordPointer(3, GL_FLOAT, 32 /*stride*/, (GLvoid*)((char*)NULL + 3*4));
我的问题是:为什么我的Q纹理坐标没有什么影响?如果它是设备或Android API级别特定的,我可以找出它的工作设备或API级别?如果我不能依靠Q坐标来做任何有用的事情,我还能如何实现相同的效果(逼真的非仿射纹理映射到梯形)?
我测试的实际Android设备上我的代码:在HTC野火S.
我现在用的是SOIL library为了方便装载我的纹理。
更新
我已经下载了NeHe Android port for Lesson 6。这使用Java OpenGL ES接口(无NDK)。我添加了随机的R和Q纹理坐标,并且再次没有可见的效果。
更新2
我放弃了试图获得第q纹理坐标产生任何影响;我认为它只是不支持所有设备。仍然对权威信息感兴趣。
相关链接:
http://www.xyzw.us/~cass/qcoord/
http://www.gamedev.net/topic/419296-skewedsheared-texture-mapping-in-opengl
http://hacksoflife.blogspot.com/2009/11/perspective-correct-texturing-q.html
perspective correction of texture coordinates in 3d
http://sfml-dev.org/forum/viewtopic.php?t=2893
http://fly.cc.fer.hr/~unreal/theredbook/chapter09.html
您的示例是否适用于某些平台/操作系统?您是否在使用OpenGLES二进制文件的Mac/Win/Linux上尝试过? – rockeye 2011-12-22 14:58:04
嗨rockeye,还没有尝试过,但它确实在我的待办事项列表(在这一刻缺乏时间)。我肯定有其他人使用Q坐标来获得效果的例子。 – occulus 2011-12-22 15:52:52
'glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST)'改变了什么? – genpfault 2011-12-22 22:22:23