2010-10-25 82 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

道歉,這是指數,我指定的抽獎元素來電的號碼。我在緩衝區中有更多的索引,並且正在使用這些索引來繪製另一個三角形。

都是我自己的錯!對不起:(