openGl的图形基本绘制以后,该是开始从平面想立体转移了,现在画一个金三角的样子,其实主要的还是定点数组的问题,GL10.GL_TRIANGLES这个参数的主要作用,
GL_TRIANGLES - 这个参数意味着OpenGL使用三个顶点来组成图形。所以,在开始的三个顶点,将用顶点1,顶点2,顶点3来组成一个三角形。完成后,在用下一组的三个顶点来组成三角形,直到数组结束。
那么我们用这个就可以画出一个金三角,代码其实没有多少变化,只是顶点数组的变化:
// 金三角数组
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
};
//金三角颜色数组
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,
};
然后在绘制的时候把 gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 12);
这个方法的最后一个参数改成12,因为是用了12个顶点绘制的
这是绘制一个金三角,还有绘制矩形,那个跟这个有点区别等,马上下班了,等过俩天在学习