【发布时间】:2012-03-10 02:20:50
【问题描述】:
今天又出现了一个我之前好几次的野虫……!
而且我不知道如何解决它。我希望您知道解决问题的技巧或使其正常工作的官方方法。有些教程似乎并没有按照他们承诺的正确方式工作。
我有一些四边形,在我的 Surfaceview 上显示为图片。我也有两个纹理。一个用于瓷砖和墙壁,一个用于目前的物体。
我按照自己的等距系统顺序绘制瓷砖和对象。 (因为防止重叠图像) 在我的智能手机上,它运行良好。瓦片使用瓦片的纹理,物体使用物体的纹理。
如你看到的。房间本身是用第一个纹理绘制的。烤箱是用第二个绘制的。 (我用的是 Xperia Mini Pro)
我的一个朋友使用 Galaxy S。现在,发生了一些奇怪的事情。所有四边形都使用相同的纹理。没有明显的解决方案我找到了如何修复这个错误。 这是用相机拍摄的图像: 在第二个纹理中也有红色瓷砖,所以不要怀疑颜色。事实上,所有的瓷砖突然使用第一个纹理。您看不到使用第二个绘制的任何部分。
这是我的一些绘图功能:
绘图功能:
public void render(float posX, float posY) {
// ======== Pass Masking Color ========
if (this.masked) {
GLES20.glUniform1i(ShaderCache.activeShader.masked, 1);
GLES20.glUniform3i(ShaderCache.activeShader.maskColor, this.maskColor.r, this.maskColor.g, this.maskColor.b);
} else {
GLES20.glUniform1i(ShaderCache.activeShader.masked, 0);
}
// ======== Passing Vertex And UV Attributes ========
if (ImageCache.lastUsedImageBuffer != this.buffer) {
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, this.buffer);
GLES20.glVertexAttribPointer(ShaderCache.activeShader.attributeVertex, 2, GLES20.GL_FLOAT, false, 16, 0);
GLES20.glVertexAttribPointer(ShaderCache.activeShader.attributeUV, 2, GLES20.GL_FLOAT, false, 16, 8);
ImageCache.lastUsedImageBuffer = this.buffer;
}
// ======== Set Sampler Texture2D ========
if (TextureCache.lastTextureUnit != this.imagetexture.unit) {
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, this.imagetexture.unit);
GLES20.glUniform1i(ShaderCache.activeShader.texture, this.imagetexture.unit);
TextureCache.lastTextureUnit = this.imagetexture.unit;
}
// ======== Passing Image Position ========
GLES20.glUniform2f(ShaderCache.activeShader.position, posX, posY);
// ======== Draw Arrays With Image Vertices ========
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, this.vertices);
}
这里的函数只是用于生成纹理单元:
int[] textureID = new int[1];
GLES20.glGenTextures(1, textureID, 0);
this.unit = textureID[0];
GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + this.unit);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, this.unit);
非常感谢!
【问题讨论】:
标签: java android data-binding opengl-es textures