1
我有行,我想用数组的颜色绘制它们。OpenGL ES 3.0 Java使用颜色Array绘制顶点(每个顶点颜色不同)
颜色数组是一个FloatBuffer,每个顶点都有RGBA数据。
我尝试了这种方式,但它不工作:
着色器代码:
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;" +
"}";
的绘图方法:
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);
}
我用2个坐标设置顶点(COORDS_PER_VERTEX = 2)。
什么问题?