Chapter 2 of OpenGl learning and Chapter 2 of opengl
After openGl is basically drawn, it's time to move from a plane to a three-dimensional one. Now, to draw a Golden Triangle, the main problem is the fixed-point array, GL10.GL _ TRIANGLES,
GL_TRIANGLES-this parameter means OpenGL uses three vertices to form a graph. Therefore, in the first three vertices, vertex 1, vertex 2, and vertex 3 are used to form a triangle. After that, use the three vertices in the next group to form a triangle until the end of the array.
So we can use this to draw a golden triangle. The Code has not changed much, but the changes in the vertex array:
// Golden Triangle Array
Private float [] mTriangleArray = {
0.0f, 1.0f, 0.0f,
-1.0f,-1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
0.0f, 1.0f, 0.0f,
1.0f,-1.0f, 1.0f,
1.0f,-1.0f,-1.0f,
0.0f, 1.0f, 0.0f,
1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
0.0f, 1.0f, 0.0f,
-1.0f,-1.0f,-1.0f,
-1.0f,-1.0f, 1.0f
};
// Golden Triangle color array
Private float [] mColorArray = {
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
};
Then, when plotting, put gl. glDrawArrays (GL10.GL _ TRIANGLES, 0, 12 );
The last parameter of this method is changed to 12 because it is drawn using 12 vertices.
This is to draw a golden triangle, and draw a rectangle, which is a little different from this, etc. The horse went to work and waited for two days to study.