首先给一个权限:
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
写一个类实现: GLSurfaceView.Renderer
public class MyView extends GLSurfaceView implements GLSurfaceView.Renderer
public class MyView extends GLSurfaceView implements GLSurfaceView.Renderer {
private Context context;
private int program;//渲染的着色器 流水线
private int vPositionIndex;
private int vColorIndex;
//用于包装 下面的float[]
private FloatBuffer verTexBuffer;
private FloatBuffer fragColorBuffer;
private String verTexShader = "attribute vec4 vPosition; void main(){ gl_Position = vPosition;}";//渲染
private String framentShader = "precision mediump float; uniform vec4 vColor; void main(){gl_FragColor= vColor;}";
//坐标系
private float[] verTexArray = {
0.0f,0.5f,0.0f,//上边的点
-0.5f,-0.5f,0.0f,//左下角的点
0.5f,-0.5f,0.0f//右下角的点
};
//颜色(红,绿,蓝,透明度)

本文介绍了如何在Android中使用OpenGL ES20权限设置和创建GLSurfaceView.Renderer类来绘制一个基本的三角形,是安卓图形编程的入门教程。
最低0.47元/天 解锁文章
556





