测试环境:平板Android 2.3.1 和 mtk6592 cpu Android4.2.2
mtk6592 cpu Android4.2.2 还报错
09-20 15:00:30.264: E/linker(13810): load_library(linker.cpp:761): library "libmaliinstr.so" not found
09-20 15:00:30.265: E/(13810): appName=cn.it.opengl, acAppName=com.android.cts.openglperf
09-20 15:00:30.265: E/(13810):
009-20 15:00:30.266: E/(13810): appName=cn.it.opengl, acAppName=com.android.browser09-20 15:00:30.266: E/(13810): 0
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view = new MyGLSurfaceView(this);
this.setContentView(view);
//渲染模式:持续渲染(默认)|命令渲染
view.setRenderer(new MyRendererCirclePoint());
//设置脏渲染(命令渲染)
view.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
//请求渲染,renderer.onDrawFrame();
// view.requestRender();
}
class MyGLSurfaceView extends GLSurfaceView{
public MyGLSurfaceView(Context context) {
super(context);
}
}
public class MyRendererCirclePoint implements Renderer {
private float ratio;
/**
* 表层创建时调用该方法
*/
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
//清屏色(黑色)
gl.glClearColor(0, 0, 0, 1);
//颜色缓冲和顶点缓冲区
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
}
/**
* 表层大小改变时调用该方法
*/
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
ratio = (float)width / height;
//投影矩阵
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();//重置矩阵
gl.glFrustumf(-ratio, ratio, -1, 1, 3, 100);//设置平截头体
}
/**
* 绘图
*/
public void onDrawFrame(GL10 gl) {
//清除颜色缓冲去
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);//设置模型视图矩阵
gl.glLoadIdentity();
GLU.gluLookAt(gl, 0, 0, 5, 0, 0, 0, 0, 1, 0);//架设相机位置
/**
* vertextList,顶点集合
*/
float r = 0.6f ;//半径
List<Float> vertextList = new ArrayList<Float>();
float x = 0 , y = 0 , z = 0.8f ;
for(float angle = 0 ; angle <= Math.PI * 6 ; angle = (float) (angle + (Math.PI / 20))){
x = (float) (r * Math.cos(angle));
y = (float) (r * Math.sin(angle));
z = z - 0.01f ;
vertextList.add(x);
vertextList.add(y);
vertextList.add(z);
}
ByteBuffer vbb = ByteBuffer.allocateDirect(vertextList.size() * 4);
vbb.order(ByteOrder.nativeOrder());
FloatBuffer fbb = FloatBuffer.allocate(vertextList.size());
for(Float f : vertextList){
fbb.put(f);
}
fbb.position(0);
vbb.position(0);
//设置蓝色
gl.glColor4f(0, 0, 1, 1);
gl.glPointSize(5f);
gl.glRotatef(-90, 1, 0, 0);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vbb);
gl.glDrawArrays(GL10.GL_POINTS, 0, vertextList.size() / 3);
}
}