今天再次出现了几次我以前发现的一个疯狂的bug ...!显示相同的纹理。绑定问题?
而我不知道如何解决它。我希望你知道解决这个问题的一个窍门,或者一个正式的方法来解决问题。一些教程似乎不能以他们承诺的正确方式工作。
我有一些四边形,在我的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);
}
而这里的功能只是用于生成textureunits:
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);
太谢谢你了!
永不读取这在一个教程中。但我相信你!听起来很合逻辑。我会试试看,并做出报告;) – TheWhiteLlama 2012-03-10 10:57:14
完美!现在它也适用于其他设备! :) – TheWhiteLlama 2012-03-10 11:16:27