Modifying camera output using SurfaceTexture and OpenGL

后端 未结 1 548
梦如初夏
梦如初夏 2020-11-27 11:03

I am trying to filter the stream coming from the camera hardware by running it through an openGL filter, then displaying it in a GLSurfaceView. When openGL goes to render t

相关标签:
1条回答
  • 2020-11-27 11:29
    mDirectVideo = new DirectVideo(texture);
    texture = createTexture();
    

    should be

    texture = createTexture();
    mDirectVideo = new DirectVideo(texture);
    

    Shader

    private final String vertexShaderCode =
            "attribute vec4 position;" +
            "attribute vec2 inputTextureCoordinate;" +
            "varying vec2 textureCoordinate;" +
            "void main()" +
            "{"+
                "gl_Position = position;"+
                "textureCoordinate = inputTextureCoordinate;" +
            "}";
    
        private final String fragmentShaderCode =
            "#extension GL_OES_EGL_image_external : require\n"+
            "precision mediump float;" +
            "varying vec2 textureCoordinate;                            \n" +
            "uniform samplerExternalOES s_texture;               \n" +
            "void main() {" +
            "  gl_FragColor = texture2D( s_texture, textureCoordinate );\n" +
            "}";
    

    mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");

    should be

    mColorHandle = GLES20.glGetAttribLocation(mProgram, "s_texture");

    remove initialization stuff from DirectVideo draw.glVertexAttribPointer etc. Put it in some init function.

    public void draw()
    {
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, texture);
        GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length,
                GLES20.GL_UNSIGNED_SHORT, drawListBuffer);
    }
    
    0 讨论(0)
提交回复
热议问题