I have an Android application using OpenGL ES 2.0. I need to draw 10 lines from an array, each of which is described by a start point and an end point. Thus, there are 10 rows = 20 points = 60 float values. None of the points are connected, so each pair of points in the array is not connected with the rest, so I draw with GL_LINES.
I draw them by putting values in a floating-point buffer and calling some helper code as follows:
public void drawLines(FloatBuffer vertexBuffer, float lineWidth,
int numPoints, float colour[]) {
GLES20.glLineWidth(lineWidth);
drawShape(vertexBuffer, GLES20.GL_LINES, numPoints, colour);
}
protected void drawShape(FloatBuffer vertexBuffer, int drawType,
int numPoints, float colour[]) {
GLES20.glDrawArrays(drawType, 0, numPoints);
}
DrawLines accepts a float buffer (60 floats), line width, number of dots (20) and 4 float color arrays. I did not show the shader setup code, but it basically provides the color variable with a uniform uColour value.
, uColour, .
precision mediump float;
uniform vec4 uColour;
uniform float uTime;
void main() {
gl_FragColor = uColour;
}
:
uniform mat4 uMVPMatrix;
attribute vec4 vPosition;
void main() {
gl_Position = uMVPMatrix * vPosition;
}
- . , . - . , - , . #ffffff, #eeeeee, #dddddd ..
, uColour , . GL 10 , .
, , uVertexCount, ? uVertexCount 0, , , . , uVertexCount. . , .
? , . , , 0, 1, * , 2, 3, * ..
- - , - ?