【发布时间】:2018-06-14 19:30:01
【问题描述】:
我制作了一个着色器,它使用颜色数组作为元素
private static final String VERTEX_SHADER_CODE =
"uniform mat4 uMVPMatrix;" +
"attribute vec4 vPosition;" +
"attribute vec4 aColor;" +
"varying vec4 vColor;" +
"void main() {" +
" vColor = aColor;" +
" gl_Position = uMVPMatrix * vPosition;" +
"}";
private static final String FRAGMENT_SHADER_CODE =
"precision mediump float;" +
"varying vec4 vColor;" +
"void main() {" +
" gl_FragColor = vColor;" +
"}";
启用混合
GLES20.glEnable(GLES20.GL_BLEND);
GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
如下图
@Override
public void onDrawFrame(GL10 gl) {
lineCoordinatesBuffer.position(0);
lineColorBuffer.position(0);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
GLES20.glUseProgram(program);
final int positionHandle = GLES20.glGetAttribLocation(program, "vPosition");
GLES20.glEnableVertexAttribArray(positionHandle);
GLES20.glVertexAttribPointer(
positionHandle,
COORDINATES_PER_VERTEX,
GLES20.GL_SHORT,
false,
0,
lineCoordinatesBuffer);
final int colorHandle = GLES20.glGetAttribLocation(program, "aColor");
GLES20.glEnableVertexAttribArray(colorHandle);
GLES20.glVertexAttribPointer(
colorHandle,
COLOR_BYTES_PER_VERTEX,
GLES20.GL_UNSIGNED_BYTE,
false,
0,
lineColorBuffer);
final int mvpMatrixHandle = GLES20.glGetUniformLocation(program, "uMVPMatrix");
GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, mvpMatrix, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 24);
}
lineCoordinatesBuffer
493, 906, 533, 790, 483, 902,
533, 790, 524, 787, 483, 902,
76, 1513, 177, 1636, 83, 1507,
177, 1636, 184, 1630, 83, 1507,
988, 439, 928, 531, 996, 444,
928, 531, 936, 536, 996, 444,
950, 413, 905, 591, 960, 415,
905, 591, 915, 594, 960, 415
lineColorBuffer
-1, -1, -1, -122,
-1, -1, -1, -122,
-1, -1, -1, -122,
-1, -1, -1, -122,
-1, -1, -1, -122,
-1, -1, -1, -122,
-1, -1, -1, 97,
-1, -1, -1, 97,
-1, -1, -1, 97,
-1, -1, -1, 97,
-1, -1, -1, 97,
-1, -1, -1, 97,
-1, -1, -1, -110,
-1, -1, -1, -110,
-1, -1, -1, -110,
-1, -1, -1, -110,
-1, -1, -1, -110,
-1, -1, -1, -110,
-1, -1, -1, 72,
-1, -1, -1, 72,
-1, -1, -1, 72,
-1, -1, -1, 72,
-1, -1, -1, 72,
-1, -1, -1, 72
输出:
预期输出:相同但在线条上应用了 alpha
【问题讨论】:
标签: opengl-es opengl-es-2.0 translucency