2 qq377287098 qq377287098 于 2014.09.25 16:21 提问

Android OpenGL es 下面这段代码在模拟器2.2上可以正常 在真机上都是黑屏

测试环境:平板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);
}

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!