Skip to content

Nanamare/opengl_camera

Repository files navigation

opengl_camera

This project is a sample camera project using OpenGL2.

There are about 50 filters, and you can add more.

Adding a filter is very simple.

example1 example2 (This is my car..)

How to add camera filter?

  1. implementation filter class
class EdgeDetectionFilter(context: Context, filterName: String) :
    CameraFilter(context, filterName) {
    private val program: Int =
        MyGLUtils.buildProgram(context, R.raw.shader_vertext, R.raw.shader_edge_detection)

    public override fun onDraw(cameraTexId: Int, canvasWidth: Int, canvasHeight: Int) {
        setupShaderInputs(
            program,
            intArrayOf(canvasWidth, canvasHeight),
            intArrayOf(cameraTexId),
            arrayOf()
        )
        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4)
    }
}

  1. implementation shader class
#extension GL_OES_standard_derivatives : enable
precision mediump float;

uniform vec3                iResolution;
uniform sampler2D           iChannel0;
varying vec2                texCoord;

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = fragCoord.xy;
    vec4 color =  texture2D(iChannel0, fragCoord);
    float gray = length(color.rgb);
    fragColor = vec4(vec3(step(0.06, length(vec2(dFdx(gray), dFdy(gray))))), 1.0);
}

void main() {
    mainImage(gl_FragColor, texCoord);
}
  1. Just append
liveCameraFilters.value?.append(1, EdgeDetectionFilter(context, "EdgeDetection"))

Done

Image save

Change filter

Camera on/off relative to lifecycle

About 50 number filter

TODO

Recording

Portrait filter

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published