开发者

Android OpenGL using both Java and C++

开发者 https://www.devze.com 2022-12-20 07:16 出处:网络
Can you blend Java and nativ开发者_如何学Pythone OpenGL calls. For instance having the setup happen in the onSurfaceCreated, but having the onDraw call into native code (or even both)? I\'m having tro

Can you blend Java and nativ开发者_如何学Pythone OpenGL calls. For instance having the setup happen in the onSurfaceCreated, but having the onDraw call into native code (or even both)? I'm having trouble getting native code to render, but can't tell if this could be a problem or if I'm throwing c++ exceptions, but they don't bubble up...

    private static native void drawFromJni();

public void onDrawFrame(GL10 gl) {
    try{
        drawFromJni();
       //gl.glDrawArrays... also
    }
    catch (Exception ex){
        ex.printStackTrace();
        Log.e("sv", ex.getMessage());
    }
} 

public void onSurfaceChanged(GL10 gl, int width, int height) {

    gl.glViewport(0, 0, width, height);

    float ratio = (float) width / height;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    gl.glDisable(GL10.GL_DITHER);
     gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
     gl.glClearColor(0,0,0,0);
     gl.glEnable(GL10.GL_CULL_FACE);
     gl.glShadeModel(GL10.GL_SMOOTH);
     gl.glEnable(GL10.GL_DEPTH_TEST);
}


Quick answer is yes, it works.

0

精彩评论

暂无评论...
验证码 换一张
取 消