0

我有一个非常奇怪的问题,希望很容易解决。

我正在绘制一个四边形作为三角形条带。它只是在条带中有 2 个三角形,我对其应用了一个包含 Alpha 通道的纹理。

对于其中一个三角形,alpha 似乎很好,并且完全符合我的要求,但是对于第一个三角形,它看起来好像 alpha 是 1.0 或 0.0,而不是正确的中间值。

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

阿尔法问题

奇怪的是,这是从 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;

不知怎的,我在那里做错了什么,我只是看不到它。

4

1 回答 1

1

抱歉,这是我在绘制元素调用中指定的索引数量。我在缓冲区中有更多索引,它正在使用这些索引来绘制另一个三角形。

都是我自己的错!对于那个很抱歉 :(

于 2010-10-25T13:35:45.927 回答