How to render Android's YUV-NV21 camera image on the background in libgdx with OpenGLES 2.0 in real-time?

前端 未结 2 913
暗喜
暗喜 2020-11-28 03:10

Unlike Android, I\'m relatively new to GL/libgdx. The task I need to solve, namely rendering the Android camera\'s YUV-NV21 preview image to the screen background inside lib

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 03:53

    For the fastest and most optimized way, just use the common GL Extention

    //Fragment Shader
    #extension GL_OES_EGL_image_external : require
    uniform samplerExternalOES u_Texture;
    

    Than in Java

    surfaceTexture = new SurfaceTexture(textureIDs[0]);
    try {
       someCamera.setPreviewTexture(surfaceTexture);
    } catch (IOException t) {
       Log.e(TAG, "Cannot set preview texture target!");
    }
    
    someCamera.startPreview();
    
    private static final int GL_TEXTURE_EXTERNAL_OES = 0x8D65;
    

    In Java GL Thread

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureIDs[0]);
    GLES20.glUniform1i(uTextureHandle, 0);
    

    The color conversion is already done for you. You can do what ever you want right in the Fragment shader.

    At all its a none Libgdx solution since it is platform dependent. You can Initialize the Platform dependant stuff in the wraper and than send it to Libgdx Activity.

    Hope that saves you some time in your research.

提交回复
热议问题