繁体   English   中英

Android上的OpenGL ES 1.1:Q纹理坐标没有任何作用

[英]OpenGL ES 1.1 on Android: Q texture coordinate not having any effect

我正在为Android开发OpenGL ES 1.1应用程序(OpenGL调用是通过NDK调用的C代码进行的)。

我的问题是我正在尝试使用Q纹理坐标以及通常的(S,T)纹理坐标。 但是,我对Q的投入没有任何明显的影响。

(此外:想要使用Q坐标的原因是我想将矩形纹理映射到空间中具有正确透视效果(即,不仿射)的梯形四边形-如http://www.xyzw中所述。我们/〜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 WildfireS。

为了方便起见,我正在使用SOIL库加载纹理。

更新

我已经下载了第6课NeHe Android端口 这使用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

3D中纹理坐标的透视校正

http://sfml-dev.org/forum/viewtopic.php?t=2893

http://fly.cc.fer.hr/~unreal/theredbook/chapter09.html

我同意你的看法。 某些android设备在OpenGL ES 1.1中不支持纹理q坐标。

以我的经验,Galaxy S,S2,S3可以工作。 Galaxy Note,Galaxy S2 HD没有。 (可能是GPU问题?)

但是OpenGL ES 2.0中的纹理q坐标在那些有问题的设备上起作用。

以下是我的着色器代码。

private final String mVertexShader =
    "uniform mat4 uMVPMatrix;\n" +
        "attribute vec4 aPosition;\n" +
        "attribute vec4 aTextureCoord;\n" +
        "varying vec4 vTextureCoord;\n" +
        "void main() {\n" +
        "  gl_Position = uMVPMatrix * aPosition;\n" +
        "  vTextureCoord = aTextureCoord;\n" +
        "}\n";

private final String mFragmentShader =
    "precision mediump float;\n" +
        "varying vec4 vTextureCoord;\n" +
        "uniform sampler2D sTexture;\n" +
        "void main() {\n" +
        "  gl_FragColor = texture2DProj(sTexture, vTextureCoord);\n" +
        "}\n";

因此,我决定在2.0支持设备上使用OpenGL 2.0,在其他设备上使用1.0。

我发布了应用程序,完成了约200万次下载,还没有听到任何有关渲染问题的投诉。

希望对您有所帮助。

这不是您问题的确切答案,但是您可能需要检查的几件事:

  • 您的纹理是否具有2的幂和高度?
  • R坐标应始终为0.f,因为它用于3d纹理。
  • 为什么不在glTexCoordPointer和glVertexPointer内部传递数据? 例如
 glTexCoordPointer(4, GL_FLOAT, 32 /* stride*/, (GLvoid*)((char*)vertexData + 3*4)); 

尝试在其他Android设备或平台上运行您的应用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM