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)。
什麼問題?