2010-10-25 136 views
0

我有一个很奇怪的问题,希望能迎刃而解。Android OpenGL - 三角形带中三角形的ES alpha透明度不同?

我绘制四边形作为三角形带。它在条上只有2个三角形,我将一个包含alpha通道的纹理应用到它上面。

对于其中一个三角形,它看起来好像和我想要的一样,但是对于第一个三角形,它看起来好像alpha或者是1.0或者0.0,而不是正确的中间值。

这可能是什么原因造成的?我是否正确地认为这是问题所在?我会附上的图像,使人们可以明白我的意思:

Alpha problem

奇怪的是,这是画成三角形排列,并从1个质地所以我不确定我怎样可以更改设置或影响纹理某种程度上来说。我想也许三角形是在不同的旋转中画出来的,但它们都是逆时针的。

代码明智得出像这样:

gl.glBindTexture(GL10.GL_TEXTURE_2D, texturePointer); 
    //Enable the vertices buffer for writing and to be used during our rendering 
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 
    //Specify the location and data format of an array of vertex coordinates to use when rendering 
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); 

    //Enable the texture buffer 
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); 
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer); 

    gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer); 

所以我有点为难,如果我是诚实的。

编辑:多看看这一点,就好像其中一个三角形被纹理两次,所以alpha明显增加了,它得到了更多的应用。这可能意味着我正在做我的三角形地带有问题。我做出这样的条左右(手开始写出来,以检查..):

//Top left 
    vertices[vertPlace++] = 0.0f; 
    vertices[vertPlace++] = height; 
    vertices[vertPlace++] = 0.0f; 

    //Bottom left 
    vertices[vertPlace++] = 0.0f; 
    vertices[vertPlace++] = 0.0f; 
    vertices[vertPlace++] = 0.0f; 

    //top right 
    vertices[vertPlace++] = width; 
    vertices[vertPlace++] = height; 
    vertices[vertPlace++] = 0.0f; 

    //Bottom right 
    vertices[vertPlace++] = width; 
    vertices[vertPlace++] = 0.0f; 
    vertices[vertPlace++] = 0.0f; 

    //Now set the indices 
    indices[indiPlace++] = (short)0; 
    indices[indiPlace++] = (short)1; 
    indices[indiPlace++] = (short)2; 
    indices[indiPlace++] = (short)3; 

    //Top Left 
    textureCoords[textPlace++] = 0.0f; 
    textureCoords[textPlace++] = 1.0f; 

    ///Bottom left 
    textureCoords[textPlace++] = 0.0f; 
    textureCoords[textPlace++] = 0.0f; 

    //Top right 
    textureCoords[textPlace++] = 1.0f; 
    textureCoords[textPlace++] = 1.0f; 

    //Bottom right 
    textureCoords[textPlace++] = 1.0f; 
    textureCoords[textPlace++] = 0.0f; 

不知怎的,我做错了那里,我只是无法看到它。

回答

1

道歉,这是指数,我指定的抽奖元素来电的号码。我在缓冲区中有更多的索引,并且正在使用这些索引来绘制另一个三角形。

都是我自己的错!对不起:(