I have lines and I want to draw them with the colors of an array.
The color array is a FloatBuffer with RGBA data for each vertex.
I tried it this way, but it doesn't work:
The shader codes:
private final String vertexShaderCode =
"uniform mat4 uMVPMatrix;" +
"attribute vec4 vPosition;" +
"void main() {" +
" gl_Position = vPosition;" +
"}";
private final String fragmentShaderCode =
"precision mediump float;" +
"uniform vec4 vColor;" +
"void main() {" +
" gl_FragColor = vColor;" +
"}";
The drawing method:
public void draw(GL10 gl)
{
GLES30.glUseProgram(mProgram);
mPositionHandle = GLES30.glGetAttribLocation(mProgram, "vPosition");
GLES30.glEnableVertexAttribArray(mPositionHandle);
GLES30.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES30.GL_FLOAT, false, vertexStride, vertexBuffer);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl.glColorPointer(vertexBufferSize / 4 / 4, GL10.GL_FLOAT, 4*4, colorBuffer);
GLES30.glDrawArrays(GLES30.GL_LINES, 0, vertexBufferSize / 4 / COORDS_PER_VERTEX);
GLES30.glDisableVertexAttribArray(mPositionHandle);
gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
}
I use 2 coordinates to set a vertex (COORDS_PER_VERTEX = 2).
What is the problem?