Log in or register to post comments

2d image on ARVR app using eyewear

August 18, 2016 - 1:21am #1

private void renderARWorld(float[] targetPose, float[] projectionMatrix, int viewId, int[] viewport, boolean isARObjectVisible) {

        int vbVideoTextureUnit = 0;

        // Bind the video bg texture and get the Texture ID from Vuforia

        GLTextureUnit tex = new GLTextureUnit();

        tex.setTextureUnit(vbVideoTextureUnit);

        if (viewId != VIEW.VIEW_RIGHTEYE )

        {

            if (!Renderer.getInstance().updateVideoBackgroundTexture(tex))

            {

                Log.e(LOGTAG, "Unable to bind video background texture");

                return;

            }

        }

        renderVideoBackground(viewId, viewport, vbVideoTextureUnit);

        GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT);

        GLES20.glEnable(GLES20.GL_DEPTH_TEST);

        GLES20.glEnable(GLES20.GL_CULL_FACE);

        GLES20.glCullFace(GLES20.GL_BACK);

        // Check if the viewer is active and set a scissor test to clip the augmentation to be constrained inside of the video background

        if(Device.getInstance().isViewerActive()) {

            float sceneScaleFactor = getSceneScaleFactor(viewId);

            Matrix.scaleM(projectionMatrix, 0, sceneScaleFactor, sceneScaleFactor, 1.0f);

        }

        // If target detected render the augmentation

        if (isARObjectVisible) {

            if (Renderer.getInstance().getVideoBackgroundConfig().getReflection() == VIDEO_BACKGROUND_REFLECTION.VIDEO_BACKGROUND_REFLECTION_ON)

                GLES20.glFrontFace(GLES20.GL_CW); // Front camera

            else

                GLES20.glFrontFace(GLES20.GL_CCW); // Back camera

            float[] modelViewProjection = new float[16];

            // deal with the modelview and projection matrices

            /*Matrix.rotateM(targetPose, 0, 90, 1.0f, 0.0f, 0.0f);

            Matrix.translateM(targetPose, 0, 0.0f, 0.0f,

                    AR_OBJECT_SCALE_FLOAT);

            Matrix.scaleM(targetPose, 0, AR_OBJECT_SCALE_FLOAT,

                    AR_OBJECT_SCALE_FLOAT, AR_OBJECT_SCALE_FLOAT);*/

            Matrix.translateM(targetPose, 0, 0.0f, 0.0f,

                    0.0f);

            Matrix.scaleM(targetPose, 0, AR_OBJECT_SCALE_FLOAT, AR_OBJECT_SCALE_FLOAT, 0.0f);

            Matrix.multiplyMM(modelViewProjection, 0, projectionMatrix, 0, targetPose, 0);

            GLES20.glUseProgram(shaderProgramID);

            GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT, false, 0, mPlane.getVertices());

            GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT, false, 0, mPlane.getNormals());

            GLES20.glVertexAttribPointer(textureCoordHandle, 2, GLES20.GL_FLOAT, false, 0, mPlane.getTexCoords());

            GLES20.glEnableVertexAttribArray(vertexHandle);

            GLES20.glEnableVertexAttribArray(normalHandle);

            GLES20.glEnableVertexAttribArray(textureCoordHandle);

            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures.get(0).mTextureID[0]);

            GLES20.glUniform1i(texSampler2DHandle, 0);

            // pass the model view matrix to the shader

            GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false,

                    modelViewProjection, 0);

            GLES20.glDrawElements(GLES20.GL_TRIANGLES, mPlane.getNumObjectIndex(), GLES20.GL_UNSIGNED_SHORT, mPlane.getIndices());



            // disable the enabled arrays

            GLES20.glDisableVertexAttribArray(vertexHandle);

            GLES20.glDisableVertexAttribArray(normalHandle);

            GLES20.glDisableVertexAttribArray(textureCoordHandle);

            //mMountainModelAR.render(targetPose, modelViewProjection);

        }



        if(Device.getInstance().isViewerActive())

        {

            GLES20.glDisable(GLES20.GL_SCISSOR_TEST);

        }

    }

 

< GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures.get(0).mTextureID[0]); >

AttachmentSize
Image icon aaa.png105.07 KB
Log in or register to post comments