Search code examples
androidopengl-esopengl-es-2.0surfaceegl

Android/OpenGles drawing 2 external texture each taking half of the screen. Left and right half


I have successfully bind 2 external OES texture to my shader. Now I want each texture to take 1/2 of the screen(Left for one texture right for another). How do I go about doing it? Example: http://vicceskep.hu/kepek/vicces_funny_007445.jpg random image from google

Showing a full picture of each picture. It will be nice to have an efficient method to do it. The code that I am currently referencing from is the bikflake/ grafika code from github. Visit http://bigflake.com/mediacodec/CameraToMpegTest.java.txt To check the code out.

Okay I think i will really give in depth clarification for my question as I do not have much knowledge about 3d projections in open GL. Sorry for the numerous edits on the question. This is my Vertex Shader code currently

    private static final String VERTEX_SHADER =

        // UMVPMATRIX IS AN IDENTITY MATRIX
        "uniform mat4 uMVPMatrix;\n" +
        //These are surfacetexture.getTransformationMatrix
        "uniform mat4 uSTMatrixOne;\n" +
        "uniform mat4 uSTMatrixTwo;\n" +        

        "attribute vec4 aPosition;\n" +
        "attribute vec4 aTextureCoord;\n" +

        "varying vec2 vTextureCoord;\n" +
        "varying vec2 vTextureCoordTwo;\n" +
        "void main() {\n" +
        "    gl_Position =  uMVPMatrix * aPosition;\n" +
        "    vTextureCoord = (uSTMatrix * aTextureCoord).xy;\n" +
        "    vTextureCoordTwo = (uSTMatrixTwo* aTextureCoord).xy ;\n" +
        "}\n";

This is my Fragment Shader code currently which does a overlay currently.

        private static final String FRAGMENT_SHADER =
        "#extension GL_OES_EGL_image_external : require\n" +
        "precision mediump float;\n" +      // highp here doesn't seem to matter
        "varying vec2 vTextureCoord;\n" +
        "varying vec2 vTextureCoordTwo;\n" +
        "uniform samplerExternalOES sTextureOne;\n" +
        "uniform samplerExternalOES sTextureTwo;\n" +

        "void main() {\n" +
        "    lowp vec4 pixelTop = texture2D(sTextureOne, vTextureCoord);\n" +
        "    lowp vec4 pixelBot  = texture2D(sTextureTwo, vTextureCoordTwo);" +

                "    gl_FragColor = pixelTop + pixelBot;\n" +
        "}\n";

As for the aPosition and the a texture coordinate it is currently referenced from. It would be nice if someone explained how mTraingleVerticesData works too.

    private final float[] mTriangleVerticesData = {

        // X, Y, Z, U, V
        -1.0f, -1.0f, 0, 0.f, 0.f,
         1.0f, -1.0f, 0, 1.f, 0.f,
        -1.0f,  1.0f, 0, 0.f, 1.f,
         1.0f,  1.0f, 0, 1.f, 1.f,
};
    GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false,
            TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
    checkGlError("glVertexAttribPointer maPosition");
    GLES20.glEnableVertexAttribArray(maPositionHandle);
    checkGlError("glEnableVertexAttribArray maPositionHandle");

    mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
    GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false,
            TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);

My 2 external projection binding currently

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);

    //Cam Code
    //Set texture to be active
    GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTwoTextureID);

Solution

  • Yea I finally got it.I used 2 different programs to draw and used mTriangleVerticesData to edit the image proportions and use gl_position to shift the image.