示例#1
0
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            GLES20.GlClearColor(0.1f, 0.1f, 0.1f, 1.0f);

            // Create the texture and pass it to ARCore session to be filled during update().
            mBackgroundRenderer.CreateOnGlThread(this);
            mSession?.SetCameraTextureName(mBackgroundRenderer.TextureId);

            // Prepare the other rendering objects.
            try
            {
                mVirtualObject.CreateOnGlThread(this, "andy.obj", "andy.png");
                mVirtualObject.setMaterialProperties(0.0f, 3.5f, 1.0f, 6.0f);

                mVirtualObjectShadow.CreateOnGlThread(this, "andy_shadow.obj", "andy_shadow.png");
                mVirtualObjectShadow.SetBlendMode(ObjectRenderer.BlendMode.Shadow);
                mVirtualObjectShadow.setMaterialProperties(1.0f, 0.0f, 0.0f, 1.0f);
            }
            catch (Java.IO.IOException e)
            {
                Log.Error(TAG, "Failed to read obj file");
            }

            try
            {
                mPlaneRenderer.CreateOnGlThread(this, "trigrid.png");
            }
            catch (IOException e)
            {
                Log.Error(TAG, "Failed to read plane texture");
            }
            mPointCloud.CreateOnGlThread(this);
        }
示例#2
0
        public void OnSurfaceCreated(IGL10 unused, EGLConfig config)
        {
            // Set the background frame color
            GLES20.GlClearColor(0.0f, 0.0f, 0.0f, 1.0f);

            mTriangle = new Triangle();
        }
示例#3
0
        public override void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            base.OnSurfaceCreated(gl, config);

            //SETUP OpenGL ES
            GLES20.GlClearColor(0.9f, 0.9f, 0.9f, 1.0f);

            GLES20.GlEnable(GLES20.GlDepthTest); //uncoment if needs enabled dpeth test

            //GLES20.GlEnable(2884); // GlCullFace == 2884 see OpenGL documentation to this constant value  GLES20.GlDisable(2884);
            //GLES20.GlFrontFace(GLES20.GlCcw);
            //GLES20.GlCullFace(GLES20.GlFront);

            GLES20.GlEnable(GL10.GlBlend);
            GLES20.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOneMinusSrcAlpha);

            //  GLES20.GlDisable(GL10.GlLighting);
            // GLES20.GlEnable(2884);
            //  GLES20.GlDisable(GL10.GlDepthBufferBit);
            //  GLES20.GlEnable(GL10.GlDither);
            //   GLES20.GlEnable(GL10.GlBlend);
            // GLES20.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOne);


            //ENDSETUP OpenGL ES

            //Loading objects
            glObjects.Add(new GLObject(this, "vertex_shader", "fragment_shader", "oldhouse_objvertex", "oldhouse_objnormal", "oldhouse_objtexture", "body"));

            //Ask android to run RAM garbage cleaner
            System.GC.Collect();
        }
        public void OnSurfaceCreated(IGL10 unused, EGLConfig config)
        {
            int program = GLES20.GlCreateProgram();

            addShaderTo(GLES20.GlVertexShader, VERTEX_SHADER_STRING, program);
            addShaderTo(GLES20.GlFragmentShader, FRAGMENT_SHADER_STRING, program);

            GLES20.GlLinkProgram(program);
            int[] result = new int[] { GLES20.GlFalse };
            result[0] = GLES20.GlFalse;
            GLES20.GlGetProgramiv(program, GLES20.GlLinkStatus, result, 0);
            abortUnless(result[0] == GLES20.GlTrue, GLES20.GlGetProgramInfoLog(program));
            GLES20.GlUseProgram(program);

            GLES20.GlUniform1i(GLES20.GlGetUniformLocation(program, "y_tex"), 0);
            GLES20.GlUniform1i(GLES20.GlGetUniformLocation(program, "u_tex"), 1);
            GLES20.GlUniform1i(GLES20.GlGetUniformLocation(program, "v_tex"), 2);

            // Actually set in drawRectangle(), but queried only once here.
            posLocation = GLES20.GlGetAttribLocation(program, "in_pos");

            int tcLocation = GLES20.GlGetAttribLocation(program, "in_tc");

            GLES20.GlEnableVertexAttribArray(tcLocation);
            GLES20.GlVertexAttribPointer(tcLocation, 2, GLES20.GlFloat, false, 0, textureCoords);

            GLES20.GlClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            checkNoGLES2Error();
        }
示例#5
0
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            GLES20.GlClearColor(0.1f, 0.1f, 0.1f, 1.0f);

            mBackgroundRenderer.CreateOnGlThread(_context);
            mSession.SetCameraTextureName(mBackgroundRenderer.TextureId);

            try
            {
                mVirtualObject.CreateOnGlThread(/*context=*/ Context, "andy.obj", "andy.png");
                mVirtualObject.setMaterialProperties(0.0f, 3.5f, 1.0f, 6.0f);

                mVirtualObjectShadow.CreateOnGlThread(/*context=*/ Context,
                                                      "andy_shadow.obj", "andy_shadow.png");
                mVirtualObjectShadow.SetBlendMode(ObjectRenderer.BlendMode.Shadow);
                mVirtualObjectShadow.setMaterialProperties(1.0f, 0.0f, 0.0f, 1.0f);
            }
            catch (Java.IO.IOException ex)
            {
                Log.Error(TAG, "Failed to read obj file");
            }

            try
            {
                mPlaneRenderer.CreateOnGlThread(/*context=*/ _context, "trigrid.png");
            }
            catch (Java.IO.IOException ex)
            {
                Log.Error(TAG, "Failed to read plane texture");
            }
            mPointCloud.CreateOnGlThread(/*context=*/ Context);
        }
示例#6
0
        public void Initialize()
        {
            GLES20.GlClearColor(0.1f, 0.1f, 0.1f, 0.5f);             // Dark background so text shows up well

            cubeVertices      = PrepareBuffer(WorldLayoutData.CubeCoords);
            cubeNormals       = PrepareBuffer(WorldLayoutData.CubeNormals);
            cubeTextureCoords = PrepareBuffer(WorldLayoutData.CubeTexCoords);

            floorVertices = PrepareBuffer(WorldLayoutData.FloorCoords);
            floorNormals  = PrepareBuffer(WorldLayoutData.FloorNormals);
            floorColors   = PrepareBuffer(WorldLayoutData.FloorColors);

            monkeyFound    = DrawingUtils.LoadGlTexture(resources, Resource.Drawable.texture2);
            monkeyNotFound = DrawingUtils.LoadGlTexture(resources, Resource.Drawable.texture1);

            int vertexShader = DrawingUtils.LoadGlShader(GLES20.GlVertexShader, resources, Resource.Raw.vertex);
            int gridShader   = DrawingUtils.LoadGlShader(GLES20.GlFragmentShader, resources, Resource.Raw.fragment);

            glProgram = GLES20.GlCreateProgram();
            GLES20.GlAttachShader(glProgram, vertexShader);
            GLES20.GlAttachShader(glProgram, gridShader);
            GLES20.GlLinkProgram(glProgram);

            GLES20.GlEnable(GLES20.GlDepthTest);

            // Object first appears directly in front of user
            Matrix.SetIdentityM(modelCube, 0);
            Matrix.TranslateM(modelCube, 0, 0, 0, -mObjectDistance);

            Matrix.SetIdentityM(modelFloor, 0);
            Matrix.TranslateM(modelFloor, 0, 0, -mFloorDepth, 0);             // Floor appears below user

            CheckGlError("onSurfaceCreated");
        }
        public void OnSurfaceCreated(Javax.Microedition.Khronos.Opengles.IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            // Set the background frame color
            GLES20.GlClearColor(0.0f, 0.0f, 0.0f, 1.0f);

            mTriangle = new Triangle();
            mSquare   = new Square();
        }
 /// <summary>
 /// Called when the OpenGL surface its created
 /// </summary>
 public void OnSurfaceCreated(IGL10 gl, EGLConfig config)
 {
     GLES20.GlClearColor(0.1f, 0.1f, 0.1f, 1.0f);
     this.backgroundRenderer.CreateOnGlThread(this.context);
     this.session.SetCameraTextureName(this.backgroundRenderer.TextureId);
     LoadArAssets();
     this.session.Resume();
 }
示例#9
0
 public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
 {
     // Clear the original color and set a new color.
     GLES20.GlClearColor(0.1f, 0.1f, 0.1f, 1.0f);
     foreach (HandRelatedDisplay handRelatedDisplay in mHandRelatedDisplays)
     {
         handRelatedDisplay.Init();
     }
     mTextureDisplay.Init();
     mTextDisplay.SetListener(new HandOnTextInfoChangeListenerClass(this));
 }
 public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
 {
     // Clear the color and set the window color.
     GLES20.GlClearColor(0.1f, 0.1f, 0.1f, 1.0f);
     foreach (BodyRelatedDisplay bodyRelatedDisplay in mBodyRelatedDisplays)
     {
         bodyRelatedDisplay.Init();
     }
     mTextureDisplay.Init();
     mTextDisplay.SetListener(new BodyOnTextInfoChangeListenerClass(this));
 }
示例#11
0
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            // Set the window color.
            GLES20.GlClearColor(0.1f, 0.1f, 0.1f, 1.0f);

            mTextureDisplay.Init();
            mTextDisplay.SetListener(new WorldOnTextInfoChangeListenerClass(this));

            mLabelDisplay.Init(GetPlaneBitmaps());

            mObjectDisplay.Init(mContext);
        }
示例#12
0
        void GLSurfaceView.IRenderer.OnSurfaceCreated(Javax.Microedition.Khronos.Opengles.IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)

        {
            GLES20.GlClearColor(1f, 1f, 1f, 1.0f);
            GLES20.GlEnable(GLES20.GlDepthTest);
            mPointCloud           = new PointCloud(mMaxDepthPoints);
            mGrid                 = new Grid();
            mCameraFrustumAndAxis = new CameraFrustumAndAxis();
            Matrix.SetIdentityM(mViewMatrix, 0);
            Matrix.SetLookAtM(mViewMatrix, 0, 5f, 5f, 5f, 0f, 0f, 0f, 0f, 1f, 0f);
            mCameraFrustumAndAxis.ModelMatrix = ModelMatCalculator.ModelMatrix;
        }
示例#13
0
        public override void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            base.OnSurfaceCreated(gl, config);

            //SETUP OpenGL ES
            GLES20.GlClearColor(0.9f, 0.9f, 0.9f, 0.9f);
            GLES20.GlEnable(GLES20.GlDepthTest); //uncoment if needs enabled dpeth test
            //ENDSETUP OpenGL ES

            //Loading objects
            glObjects.Add(new GLObject(this, "vertex_shader", "fragment_shader", "oldhouse_objvertex", "oldhouse_objnormal", "oldhouse_objtexture", "body"));

            //Ask android to run RAM garbage cleaner
            System.GC.Collect();
        }
示例#14
0
 public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
 {
     // Set background color and enable depth testing
     GLES20.GlClearColor(1f, 1f, 1f, 1.0f);
     GLES20.GlEnable(GLES20.GlDepthTest);
     resetModelMatCalculator();
     mCameraFrustum        = new CameraFrustum();
     mFloorGrid            = new Grid();
     mCameraFrustumAndAxis = new CameraFrustumAndAxis();
     mTrajectory           = new Trajectory(3);
     // Construct the initial view matrix
     Matrix.SetIdentityM(mViewMatrix, 0);
     Matrix.SetLookAtM(mViewMatrix, 0, 5f, 5f, 5f, 0f, 0f, 0f, 0f, 1f, 0f);
     mCameraFrustumAndAxis.ModelMatrix = ModelMatCalculator.ModelMatrix;
 }
示例#15
0
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            if (RenderManager.externalPaused)
            {
                RenderManager.initShaders();
            }
            else
            {
                RenderManager.createObjects();
            }

            GLES20.GlClearColor(0.1f, 0.1f, 0.9f, 0.0f);
            GLES20.GlEnable(GLES20.GlDepthTest);
            GLES20.GlEnable(GLES20.GlCullFaceMode);
            GLES20.GlCullFace(GLES20.GlBack);
        }
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            // Create the triangle
            SetupTriangle();

            // Create the image information
            SetupImage();

            // Set the clear color to yellow
            GLES20.GlClearColor(1.0f, 1.0f, 0f, 1);

            GLES20.GlEnable(GLES20.GlBlend);
            GLES20.GlBlendFunc(GLES20.GlOne, GLES20.GlOneMinusSrcAlpha);

            #region Solid colors mode

            /*
             * // Create the shaders, solid color
             * int vertexShader = ShaderHelper.LoadShader(GLES20.GlVertexShader, ShaderHelper.VsSolidColor);
             * int fragmentShader = ShaderHelper.LoadShader(GLES20.GlFragmentShader, ShaderHelper.FsSolidColor);
             *
             * ShaderHelper.SpSolidColor = GLES20.GlCreateProgram();             // create empty OpenGL ES Program
             * GLES20.GlAttachShader(ShaderHelper.SpSolidColor, vertexShader);   // add the vertex shader to program
             * GLES20.GlAttachShader(ShaderHelper.SpSolidColor, fragmentShader); // add the fragment shader to program
             * GLES20.GlLinkProgram(ShaderHelper.SpSolidColor);                  // creates OpenGL ES program executables
             *
             * // Set our shader programm
             * GLES20.GlUseProgram(ShaderHelper.SpSolidColor);
             */
            #endregion

            #region Texture mode
            // Create the shaders, images
            int vertexShader   = ShaderHelper.LoadShader(GLES20.GlVertexShader, ShaderHelper.VsImage);
            int fragmentShader = ShaderHelper.LoadShader(GLES20.GlFragmentShader, ShaderHelper.FsImage);

            ShaderHelper.SpImage = GLES20.GlCreateProgram();
            GLES20.GlAttachShader(ShaderHelper.SpImage, vertexShader);
            GLES20.GlAttachShader(ShaderHelper.SpImage, fragmentShader);
            GLES20.GlLinkProgram(ShaderHelper.SpImage);

            // Set our shader programm
            GLES20.GlUseProgram(ShaderHelper.SpImage);
            #endregion
        }
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            GLES20.GlClearColor(0.1f, 0.1f, 0.1f, 1.0f);

            if (isOpenCameraOutside)
            {
                mTextureDisplay.Init(mTextureId);
            }
            else
            {
                mTextureDisplay.Init();
            }
            Log.Debug(TAG, "On surface created textureId= " + mTextureId);

            mFaceGeometryDisplay.Init(mContext);

            mTextDisplay.SetListener(new FaceOnTextInfoChangeListenerClass(this));
        }
示例#18
0
        public void OnSurfaceCreated(IGL10 gl, EGLConfig config)
        {
            // GL configurations
            int bonenum = 48;

            GLES20.GlGetIntegerv(GLES20.GlMaxTextureSize, mTexSize, 0);
            ShellViewModel.MaxBone = bonenum;
            mNpot = hasExt("GL_OES_texture_npot");

            // initialize
            GLES20.GlClearColor(0, 0, 0, 1);
            GLES20.GlEnable(GLES20.GlDepthTest);
            GLES20.GlEnable(GLES20.GlBlend);
            checkGlError("GlEnable");

            // GLUtils.texImage2D generates premultiplied-alpha texture. so we use GL_ONE instead of GL_ALPHA
            GLES20.GlBlendFunc(GL10.GlOne, GL10.GlOneMinusSrcAlpha);
            GLES20.GlDepthFunc(GLES20.GlLequal);
            GLES20.GlFrontFace(GLES20.GlCw);
            checkGlError("GlMiscSettings");

            // shader programs
            mGLSL = new Dictionary <String, GLSL>();

            mGLSL.Add("builtin:default",
                      new GLSL(String.Format(Util.ReadAssetString("shader/vs.vsh"), ShellViewModel.MaxBone),
                               Util.ReadAssetString("shader/fs.fsh")));

            mGLSL.Add("builtin:default_alpha",
                      new GLSL(String.Format(Util.ReadAssetString("shader/vs.vsh"), ShellViewModel.MaxBone),
                               Util.ReadAssetString("shader/fs_alpha.fsh")));

            mGLSL.Add("builtin:nomotion",
                      new GLSL(Util.ReadAssetString("shader/vs_nm.vsh"), Util.ReadAssetString("shader/fs.fsh")));

            mGLSL.Add("builtin:nomotion_alpha",
                      new GLSL(Util.ReadAssetString("shader/vs_nm.vsh"), Util.ReadAssetString("shader/fs_alpha.fsh")));

            // render targets
            mRT = new Dictionary <String, RenderTarget>();
            mRT.Add("screen", new RenderTarget());

            GLES20.GlBindFramebuffer(GLES20.GlFramebuffer, 0);
        }
示例#19
0
        /// <summary>
        /// This method will clear the surface view from its last rendered pixels.
        /// This is used to avoid seeing the previous video rendering when setting
        /// a video source to null.
        /// </summary>
        internal void Clear()
        {
#pragma warning disable 618
            // The solution is as described here:
            // https://stackoverflow.com/questions/25660994/clear-video-frame-from-surfaceview-on-video-complete
            if (Holder?.Surface == null)
            {
                return;
            }

            var egl     = Javax.Microedition.Khronos.Egl.EGLContext.EGL.JavaCast <IEGL10>();
            var display = egl.EglGetDisplay(EGL10.EglDefaultDisplay);
            egl.EglInitialize(display, null);

            int[] attribList =
            {
                EGL10.EglRedSize,                         8,
                EGL10.EglGreenSize,                       8,
                EGL10.EglBlueSize,                        8,
                EGL10.EglAlphaSize,                       8,
                EGL10.EglRenderableType, EGL10.EglWindowBit,
                EGL10.EglNone,                            0, // placeholder for recordable [@-3]
                EGL10.EglNone
            };

            var configs    = new Javax.Microedition.Khronos.Egl.EGLConfig[1];
            var numConfigs = new int[1];

            egl.EglChooseConfig(display, attribList, configs, configs.Length, numConfigs);
            var config  = configs[0];
            var context = egl.EglCreateContext(display, config, EGL10.EglNoContext, new int[] { 12440, 2, EGL10.EglNone });

            var eglSurface = egl.EglCreateWindowSurface(display, config, Holder.Surface, new int[] { EGL10.EglNone });

            egl.EglMakeCurrent(display, eglSurface, eglSurface, context);
            GLES20.GlClearColor(0, 0, 0, 1);
            GLES20.GlClear(GLES20.GlColorBufferBit);
            egl.EglSwapBuffers(display, eglSurface);
            egl.EglDestroySurface(display, eglSurface);
            egl.EglMakeCurrent(display, EGL10.EglNoSurface, EGL10.EglNoSurface, EGL10.EglNoContext);
            egl.EglDestroyContext(display, context);
            egl.EglTerminate(display);
#pragma warning restore 618
        }
示例#20
0
            /**
             * Draws the external texture in SurfaceTexture onto the current EGL surface.
             */
            public void drawFrame(SurfaceTexture st, bool invert)
            {
                checkGlError("onDrawFrame start");
                st.GetTransformMatrix(mSTMatrix);
                if (invert)
                {
                    mSTMatrix[5]  = -mSTMatrix[5];
                    mSTMatrix[13] = 1.0f - mSTMatrix[13];
                }

                // (optional) clear to green so we can see if we're failing to set pixels
                GLES20.GlClearColor(0.0f, 1.0f, 0.0f, 1.0f);
                GLES20.GlClear(GLES20.GlColorBufferBit);

                GLES20.GlUseProgram(mProgram);
                checkGlError("glUseProgram");

                GLES20.GlActiveTexture(GLES20.GlTexture0);
                GLES20.GlBindTexture(GLES11Ext.GlTextureExternalOes, mTextureID);

                mTriangleVertices.Position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
                GLES20.GlVertexAttribPointer(maPositionHandle, 3, GLES20.GlFloat, 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.GlFloat, false,
                                             TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
                checkGlError("glVertexAttribPointer maTextureHandle");
                GLES20.GlEnableVertexAttribArray(maTextureHandle);
                checkGlError("glEnableVertexAttribArray maTextureHandle");

                Android.Opengl.Matrix.SetIdentityM(mMVPMatrix, 0);
                GLES20.GlUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
                GLES20.GlUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);

                GLES20.GlDrawArrays(GLES20.GlTriangleStrip, 0, 4);
                checkGlError("glDrawArrays");

                GLES20.GlBindTexture(GLES11Ext.GlTextureExternalOes, 0);
            }
        public void RenderTexture(int texId)
        {
            try
            {
                // Bind default FBO
                GLES20.GlBindFramebuffer(GLES20.GlFramebuffer, 0);

                // Use our shader program
                GLES20.GlUseProgram(MProgram);
                GlToolbox.CheckGlError("glUseProgram");

                // Set viewport
                GLES20.GlViewport(0, 0, MViewWidth, MViewHeight);
                GlToolbox.CheckGlError("glViewport");

                // Disable blending
                GLES20.GlDisable(GLES20.GlBlend);

                // Set the vertex attributes
                GLES20.GlVertexAttribPointer(MTexCoordHandle, 2, GLES20.GlFloat, false, 0, MTexVertices);
                GLES20.GlEnableVertexAttribArray(MTexCoordHandle);
                GLES20.GlVertexAttribPointer(MPosCoordHandle, 2, GLES20.GlFloat, false, 0, MPosVertices);
                GLES20.GlEnableVertexAttribArray(MPosCoordHandle);
                GlToolbox.CheckGlError("vertex attribute setup");

                // Set the input texture
                GLES20.GlActiveTexture(GLES20.GlTexture0);
                GlToolbox.CheckGlError("glActiveTexture");
                GLES20.GlBindTexture(GLES20.GlTexture2d, texId);
                GlToolbox.CheckGlError("glBindTexture");
                GLES20.GlUniform1i(MTexSamplerHandle, 0);

                // Draw
                GLES20.GlClearColor(0.0f, 0.0f, 0.0f, 1.0f);
                GLES20.GlClear(GLES20.GlColorBufferBit);
                GLES20.GlDrawArrays(GLES20.GlTriangleStrip, 0, 4);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
        public void afterDrawFrame()
        {
            GLES20.GlBindFramebuffer(36160, mOriginalFramebufferId /*.array()[0]*/.Get(0));
            GLES20.GlViewport(0, 0, mHmd.getScreen().getWidth(), mHmd.getScreen().getHeight());

            GLES20.GlGetIntegerv(2978, mViewport);
            GLES20.GlGetIntegerv(2884, mCullFaceEnabled);
            GLES20.GlGetIntegerv(3089, mScissorTestEnabled);
            GLES20.GlDisable(3089);
            GLES20.GlDisable(2884);

            GLES20.GlClearColor(0.0F, 0.0F, 0.0F, 1.0F);
            GLES20.GlClear(16640);

            GLES20.GlUseProgram(mProgramHolder.program);

            GLES20.GlEnable(3089);
            GLES20.GlScissor(0, 0, mHmd.getScreen().getWidth() / 2, mHmd.getScreen().getHeight());

            renderDistortionMesh(mLeftEyeDistortionMesh);

            GLES20.GlScissor(mHmd.getScreen().getWidth() / 2, 0, mHmd.getScreen().getWidth() / 2, mHmd.getScreen().getHeight());

            renderDistortionMesh(mRightEyeDistortionMesh);

            GLES20.GlDisableVertexAttribArray(mProgramHolder.aPosition);
            GLES20.GlDisableVertexAttribArray(mProgramHolder.aVignette);
            GLES20.GlDisableVertexAttribArray(mProgramHolder.aTextureCoord);
            GLES20.GlUseProgram(0);
            GLES20.GlBindBuffer(34962, 0);
            GLES20.GlBindBuffer(34963, 0);
            GLES20.GlDisable(3089);
            if (mCullFaceEnabled /*.array()[0]*/.Get(0) == 1)
            {
                GLES20.GlEnable(2884);
            }
            if (mScissorTestEnabled /*.array()[0]*/.Get(0) == 1)
            {
                GLES20.GlEnable(3089);
            }
            GLES20.GlViewport(mViewport /*.array()[0]*/.Get(0), mViewport /*.array()[1]*/.Get(1), mViewport /*.array()[2]*/.Get(2), mViewport /*.array()[3]*/.Get(3));
        }
示例#23
0
        public override void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            base.OnSurfaceCreated(gl, config);

            //SETUP OpenGL ES
            GLES20.GlClearColor(0.5f, 0.5f, 0.5f, 1.0f);
            GLES20.GlEnable(GLES20.GlDepthTest); //uncoment if needs enabled dpeth test
            //  GLES20.GlEnable(2884); // GlCullFace == 2884 see OpenGL documentation to this constant value
            //  GLES20.GlCullFace(GLES20.GlFront);
            //ENDSETUP OpenGL ES

            //Loading objects
            glObjects.Add(new GLObject(this, "den_vertex_shader", "den_fragment_shader", "den_house1_objvertex", "den_house1_objnormal", "den_house1_objtexture", "den_housetextutre2"));
            glObjects.Add(new GLObject(this, "den_vertex_shader", "den_fragment_shader", "den_house2_objvertex", "den_house2_objnormal", "den_house2_objtexture", "den_housetextutre2"));
            glObjects.Add(new GLObject(this, "den_vertex_shader", "den_fragment_shader", "den_house3_objvertex", "den_house3_objnormal", "den_house3_objtexture", "den_housetextutre2"));
            glObjects.Add(new DenGlassObject(this, "den_glass"));


            //Ask android to run RAM garbage cleaner
            System.GC.Collect();
        }
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            GLES20.GlClearColor(0.1f, 0.1f, 0.1f, 1.0f);

            // Create the texture and pass it to ARCore session to be filled during update().
            mBackgroundRenderer.CreateOnGlThread(/*context=*/ this);
            if (mSession != null)
            {
                mSession.SetCameraTextureName(mBackgroundRenderer.TextureId);
            }

            // Prepare the other rendering objects.
            try
            {
                mVirtualObject.CreateOnGlThread(/*context=*/ this, "andy.obj", "andy2.png");
                mVirtualObject.setMaterialProperties(0.0f, 3.5f, 1.0f, 6.0f);

                mVirtualObjectShadow.CreateOnGlThread(/*context=*/ this, "andy_shadow.obj", "vsplogo.png");
                mVirtualObjectShadow.SetBlendMode(ObjectRenderer.BlendMode.Shadow);
                mVirtualObjectShadow.setMaterialProperties(1.0f, 0.0f, 0.0f, 1.0f);
                showLoadingObjMessage("1. loaded obj file");
            }
            catch (Java.IO.IOException e)
            {
                Log.Error(TAG, "Failed to read obj file");
                showLoadingObjMessage("2. Failed to read obj file");
            }

            try
            {
                mPlaneRenderer.CreateOnGlThread(/*context=*/ this, "dot4.png");
                showLoadingObjMessage("3. load floor image file");
            }
            catch (Java.IO.IOException e)
            {
                Log.Error(TAG, "Failed to read plane texture");
            }
            mPointCloud.CreateOnGlThread(/*context=*/ this);
        }
        /**
         * Generates a frame of data using GL commands.
         * <p>
         * We have an 8-frame animation sequence that wraps around. It looks like this:
         * <pre>
         * 0 1 2 3
         * 7 6 5 4
         * </pre>
         * We draw one of the eight rectangles and leave the rest set to the zero-fill color. */
        private void generateSurfaceFrame(int frameIndex)
        {
            frameIndex %= 8;
            int startX, startY;

            if (frameIndex < 4)
            {
                // (0,0) is bottom-left in GL
                startX = frameIndex * (mWidth / 4);
                startY = mHeight / 2;
            }
            else
            {
                startX = (7 - frameIndex) * (mWidth / 4);
                startY = 0;
            }
            GLES20.GlDisable(GLES20.GlScissorTest);
            GLES20.GlClearColor(TEST_R0 / 255.0f, TEST_G0 / 255.0f, TEST_B0 / 255.0f, 1.0f);
            GLES20.GlClear(GLES20.GlColorBufferBit);
            GLES20.GlEnable(GLES20.GlScissorTest);
            GLES20.GlScissor(startX, startY, mWidth / 4, mHeight / 2);
            GLES20.GlClearColor(TEST_R1 / 255.0f, TEST_G1 / 255.0f, TEST_B1 / 255.0f, 1.0f);
            GLES20.GlClear(GLES20.GlColorBufferBit);
        }
示例#26
0
        public void OnSurfaceCreated(Javax.Microedition.Khronos.Opengles.IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            // Set the background frame color
            GLES20.GlClearColor(0.0f, 0.0f, 0.0f, 1.0f);

            initTex();
            mSTexture = new SurfaceTexture(hTex[0]);
            mSTexture.SetOnFrameAvailableListener(this);

            mCamera = Android.Hardware.Camera.Open();
            try
            {
                mCamera.SetPreviewTexture(mSTexture);
            }
            catch (Exception ioe)
            {
            }

            GLES20.GlClearColor(0.0f, 0.0f, 0.0f, 1.0f);

            hProgram = loadShader(vss, fss);

            mTriangle = new Triangle();
        }
示例#27
0
        /**
         * Draws the collection of tracked planes, with closer planes hiding more distant ones.
         *
         * @param allPlanes The collection of planes to draw.
         * @param cameraPose The pose of the camera, as returned by {@link Frame#getPose()}
         * @param cameraPerspective The projection matrix, as returned by
         *     {@link Session#getProjectionMatrix(float[], int, float, float)}
         */
        public void DrawPlanes(IEnumerable <Plane> allPlanes, Pose cameraPose, float[] cameraPerspective)
        {
            // Planes must be sorted by distance from camera so that we draw closer planes first, and
            // they occlude the farther planes.
            List <SortablePlane> sortedPlanes = new List <SortablePlane>();

            float[] normal  = new float[3];
            float   cameraX = cameraPose.Tx();
            float   cameraY = cameraPose.Ty();
            float   cameraZ = cameraPose.Tz();

            foreach (var plane in allPlanes)
            {
                if (plane.GetType() != Plane.Type.HorizontalUpwardFacing ||
                    plane.GetTrackingState() != Plane.TrackingState.Tracking)
                {
                    continue;
                }

                var center = plane.CenterPose;
                // Get transformed Y axis of plane's coordinate system.
                center.GetTransformedAxis(1, 1.0f, normal, 0);
                // Compute dot product of plane's normal with vector from camera to plane center.
                float distance = (cameraX - center.Tx()) * normal[0] +
                                 (cameraY - center.Ty()) * normal[1] + (cameraZ - center.Tz()) * normal[2];
                if (distance < 0)
                {  // Plane is back-facing.
                    continue;
                }
                sortedPlanes.Add(new SortablePlane(distance, plane));
            }

            sortedPlanes.Sort((x, y) => x.Distance.CompareTo(y.Distance));


            var cameraView = new float[16];

            cameraPose.Inverse().ToMatrix(cameraView, 0);

            // Planes are drawn with additive blending, masked by the alpha channel for occlusion.

            // Start by clearing the alpha channel of the color buffer to 1.0.
            GLES20.GlClearColor(1, 1, 1, 1);
            GLES20.GlColorMask(false, false, false, true);
            GLES20.GlClear(GLES20.GlColorBufferBit);
            GLES20.GlColorMask(true, true, true, true);

            // Disable depth write.
            GLES20.GlDepthMask(false);

            // Additive blending, masked by alpha chanel, clearing alpha channel.
            GLES20.GlEnable(GLES20.GlBlend);
            GLES20.GlBlendFuncSeparate(
                GLES20.GlDstAlpha, GLES20.GlOne,            // RGB (src, dest)
                GLES20.GlZero, GLES20.GlOneMinusSrcAlpha);  // ALPHA (src, dest)

            // Set up the shader.
            GLES20.GlUseProgram(mPlaneProgram);

            // Attach the texture.
            GLES20.GlActiveTexture(GLES20.GlTexture0);
            GLES20.GlBindTexture(GLES20.GlTexture2d, mTextures[0]);
            GLES20.GlUniform1i(mTextureUniform, 0);

            // Shared fragment uniforms.
            GLES20.GlUniform4fv(mGridControlUniform, 1, GRID_CONTROL, 0);

            // Enable vertex arrays
            GLES20.GlEnableVertexAttribArray(mPlaneXZPositionAlphaAttribute);

            ShaderUtil.CheckGLError(TAG, "Setting up to draw planes");

            foreach (var sortedPlane in sortedPlanes)
            {
                var     plane       = sortedPlane.Plane;
                float[] planeMatrix = new float[16];
                plane.CenterPose.ToMatrix(planeMatrix, 0);


                updatePlaneParameters(planeMatrix, plane.ExtentX,
                                      plane.ExtentZ, plane.PlanePolygon);

                // Get plane index. Keep a map to assign same indices to same planes.

                int planeIndex = -1;
                if (!mPlaneIndexMap.TryGetValue(plane, out planeIndex))
                {
                    planeIndex = Java.Lang.Integer.ValueOf(mPlaneIndexMap.Count).IntValue();
                    mPlaneIndexMap.Add(plane, planeIndex);
                }

                // Set plane color. Computed deterministically from the Plane index.
                int colorIndex = planeIndex % PLANE_COLORS_RGBA.Length;

                colorRgbaToFloat(mPlaneColor, PLANE_COLORS_RGBA[colorIndex]);
                GLES20.GlUniform4fv(mLineColorUniform, 1, mPlaneColor, 0);
                GLES20.GlUniform4fv(mDotColorUniform, 1, mPlaneColor, 0);

                // Each plane will have its own angle offset from others, to make them easier to
                // distinguish. Compute a 2x2 rotation matrix from the angle.
                float angleRadians = planeIndex * 0.144f;
                float uScale       = DOTS_PER_METER;
                float vScale       = DOTS_PER_METER * EQUILATERAL_TRIANGLE_SCALE;
                mPlaneAngleUvMatrix[0] = +(float)Math.Cos(angleRadians) * uScale;
                mPlaneAngleUvMatrix[1] = -(float)Math.Sin(angleRadians) * uScale;
                mPlaneAngleUvMatrix[2] = +(float)Math.Sin(angleRadians) * vScale;
                mPlaneAngleUvMatrix[3] = +(float)Math.Cos(angleRadians) * vScale;
                GLES20.GlUniformMatrix2fv(mPlaneUvMatrixUniform, 1, false, mPlaneAngleUvMatrix, 0);


                Draw(cameraView, cameraPerspective);
            }

            // Clean up the state we set
            GLES20.GlDisableVertexAttribArray(mPlaneXZPositionAlphaAttribute);
            GLES20.GlBindTexture(GLES20.GlTexture2d, 0);
            GLES20.GlDisable(GLES20.GlBlend);
            GLES20.GlDepthMask(true);

            ShaderUtil.CheckGLError(TAG, "Cleaning up after drawing planes");
        }
        public void OnDrawFrame(IGL10 unused)
        {
            // Clear view.
            GLES20.GlClearColor(0.5f, 0.5f, 0.5f, 1.0f);
            GLES20.GlClear(GLES20.GlColorBufferBit);

            // If we have new preview texture.
            if (_surfaceTextureUpdate)
            {
                // Update surface texture.
                _surfaceTexture.UpdateTexImage();
                // Update texture transform matrix.
                _surfaceTexture.GetTransformMatrix(_transformM);
                _surfaceTextureUpdate = false;

                // Bind offscreen texture into use.
                _fboOffscreen.Bind();
                _fboOffscreen.BindTexture(0);

                // Take copy shader into use.
                _shaderCopyOes.UseProgram();

                // Uniform variables.
                var uOrientationM = _shaderCopyOes.GetHandle("uOrientationM");
                var uTransformM   = _shaderCopyOes.GetHandle("uTransformM");

                // We're about to transform external texture here already.
                GLES20.GlUniformMatrix4fv(uOrientationM, 1, false,
                                          _sharedData._orientationM, 0);
                GLES20.GlUniformMatrix4fv(uTransformM, 1, false, _transformM, 0);

                // We're using external OES texture as source.
                GLES20.GlActiveTexture(GLES20.GlTexture0);
                //GLES20.GlBindTexture(GLES20.GlTexture2d, mFboExternal.getTexture(0));

                // Trigger actual rendering.
                renderQuad(_shaderCopyOes.GetHandle("aPosition"));
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("OK");
            }

            // Bind screen buffer into use.
            GLES20.GlBindFramebuffer(GLES20.GlFramebuffer, 0);
            GLES20.GlViewport(0, 0, _width, _height);

            // Take filter shader into use.
            _shaderFilterDefault.UseProgram();

            // Uniform variables.
            var uBrightness   = _shaderFilterDefault.GetHandle("uBrightness");
            var uContrast     = _shaderFilterDefault.GetHandle("uContrast");
            var uSaturation   = _shaderFilterDefault.GetHandle("uSaturation");
            var uCornerRadius = _shaderFilterDefault.GetHandle("uCornerRadius");

            var uAspectRatio        = _shaderFilterDefault.GetHandle("uAspectRatio");
            var uAspectRatioPreview = _shaderFilterDefault.GetHandle("uAspectRatioPreview");

            // Store uniform variables into use.
            GLES20.GlUniform1f(uBrightness, _sharedData._brightness);
            GLES20.GlUniform1f(uContrast, _sharedData._contrast);
            GLES20.GlUniform1f(uSaturation, _sharedData._saturation);
            GLES20.GlUniform1f(uCornerRadius, _sharedData._cornerRadius);

            GLES20.GlUniform2fv(uAspectRatio, 1, _aspectRatio, 0);
            GLES20.GlUniform2fv(uAspectRatioPreview, 1,
                                _sharedData._aspectRatioPreview, 0);

            // Use offscreen texture as source.
            GLES20.GlActiveTexture(GLES20.GlTexture1);
            GLES20.GlBindTexture(GLES20.GlTexture2d, _fboOffscreen.GetTexture(0));

            // Trigger actual rendering.
            renderQuad(_shaderCopyOes.GetHandle("aPosition"));
        }
示例#29
0
        private int[] VBOBuffers = new int[2]; //2 buffers for vertices and colors

        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            const float edge = 1.0f;

            // X, Y, Z,
            float[] triangleVerticesData =
            {
                -1.5f,       -0.25f, 0.0f,
                0.5f,        -0.25f, 0.0f,
                0.0f,  0.559016994f, 0.0f
            };

            FloatBuffer mTriangleVertices = ByteBuffer.AllocateDirect(triangleVerticesData.Length * mBytesPerFloat).Order(ByteOrder.NativeOrder()).AsFloatBuffer();

            mTriangleVertices.Put(triangleVerticesData).Flip();

            // R, G, B, A
            float[] triangleColorsData =
            {
                1.0f, 0.0f, 0.0f, 0.5f,
                0.0f, 0.5f, 1.0f, 1.0f,
                0.0f, 1.0f, 0.0f, 1.0f
            };

            FloatBuffer mTriangleColors = ByteBuffer.AllocateDirect(triangleColorsData.Length * mBytesPerFloat).Order(ByteOrder.NativeOrder()).AsFloatBuffer();

            mTriangleColors.Put(triangleColorsData).Flip();

            //Use VBO
            GLES20.GlGenBuffers(2, VBOBuffers, 0); //2 buffers for vertices and colors
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOBuffers[0]);
            GLES20.GlBufferData(GLES20.GlArrayBuffer, mTriangleVertices.Capacity() * mBytesPerFloat, mTriangleVertices, GLES20.GlStaticDraw);

            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOBuffers[1]);
            GLES20.GlBufferData(GLES20.GlArrayBuffer, mTriangleColors.Capacity() * mBytesPerFloat, mTriangleColors, GLES20.GlStaticDraw);


            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0);


            GLES20.GlClearColor(1.0f, 1.0f, 1.0f, 1.0f);

            // Position the eye behind the origin.
            float eyeX = 0.0f;
            float eyeY = 0.0f;
            float eyeZ = 4.5f;

            // We are looking toward the distance
            float lookX = 0.0f;
            float lookY = 0.0f;
            float lookZ = -5.0f;

            // Set our up vector. This is where our head would be pointing were we holding the camera.
            float upX = 0.0f;
            float upY = 1.0f;
            float upZ = 0.0f;

            // Set the view matrix. This matrix can be said to represent the camera position.
            // NOTE: In OpenGL 1, a ModelView matrix is used, which is a combination of a model and
            // view matrix. In OpenGL 2, we can keep track of these matrices separately if we choose.
            Matrix.SetLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);

            string vertexShader =
                "uniform mat4 u_MVPMatrix;      \n"         // A constant representing the combined model/view/projection matrix.
                + "attribute vec4 a_Position;     \n"       // Per-vertex position information we will pass in.
                + "attribute vec4 a_Color;        \n"       // Per-vertex color information we will pass in.
                + "varying vec4 v_Color;          \n"       // This will be passed into the fragment shader.
                + "void main()                    \n"       // The entry point for our vertex shader.
                + "{                              \n"
                + "   v_Color = a_Color;          \n"       // Pass the color through to the fragment shader. It will be interpolated across the triangle.
                + "   gl_Position = u_MVPMatrix   \n"       // gl_Position is a special variable used to store the final position.
                + "                 * a_Position; \n"       // Multiply the vertex by the matrix to get the final point in normalized screen coordinates.
                + "}                              \n";

            string fragmentShader =
                "precision mediump float;       \n"     // Set the default precision to medium. We don't need as high of a
                                                        // precision in the fragment shader.
                + "varying vec4 v_Color;          \n"   // This is the color from the vertex shader interpolated across the triangle per fragment.
                + "void main()                    \n"   // The entry point for our fragment shader.
                + "{                              \n"
                + "   gl_FragColor = v_Color;     \n"   // Pass the color directly through the pipeline.
                + "}                              \n";

            int vertexShaderHandle = GLES20.GlCreateShader(GLES20.GlVertexShader);

            if (vertexShaderHandle != 0)
            {
                // Pass in the shader source.
                GLES20.GlShaderSource(vertexShaderHandle, vertexShader);

                // Compile the shader.
                GLES20.GlCompileShader(vertexShaderHandle);

                // Get the compilation status.
                int[] compileStatus = new int[1];
                GLES20.GlGetShaderiv(vertexShaderHandle, GLES20.GlCompileStatus, compileStatus, 0);

                // If the compilation failed, delete the shader.
                if (compileStatus[0] == 0)
                {
                    GLES20.GlDeleteShader(vertexShaderHandle);
                    vertexShaderHandle = 0;
                }
            }

            if (vertexShaderHandle == 0)
            {
                throw new Exception("Error creating vertex shader.");
            }

            // Load in the fragment shader shader.
            int fragmentShaderHandle = GLES20.GlCreateShader(GLES20.GlFragmentShader);

            if (fragmentShaderHandle != 0)
            {
                // Pass in the shader source.
                GLES20.GlShaderSource(fragmentShaderHandle, fragmentShader);

                // Compile the shader.
                GLES20.GlCompileShader(fragmentShaderHandle);

                // Get the compilation status.
                int[] compileStatus = new int[1];
                GLES20.GlGetShaderiv(fragmentShaderHandle, GLES20.GlCompileStatus, compileStatus, 0);

                // If the compilation failed, delete the shader.
                if (compileStatus[0] == 0)
                {
                    GLES20.GlDeleteShader(fragmentShaderHandle);
                    fragmentShaderHandle = 0;
                }
            }

            if (fragmentShaderHandle == 0)
            {
                throw new Exception("Error creating fragment shader.");
            }

            // Create a program object and store the handle to it.
            int programHandle = GLES20.GlCreateProgram();

            if (programHandle != 0)
            {
                // Bind the vertex shader to the program.
                GLES20.GlAttachShader(programHandle, vertexShaderHandle);

                // Bind the fragment shader to the program.
                GLES20.GlAttachShader(programHandle, fragmentShaderHandle);

                // Bind attributes
                GLES20.GlBindAttribLocation(programHandle, 0, "a_Position");
                GLES20.GlBindAttribLocation(programHandle, 1, "a_Color");

                // Link the two shaders together into a program.
                GLES20.GlLinkProgram(programHandle);

                // Get the link status.
                int[] linkStatus = new int[1];
                GLES20.GlGetProgramiv(programHandle, GLES20.GlLinkStatus, linkStatus, 0);

                // If the link failed, delete the program.
                if (linkStatus[0] == 0)
                {
                    GLES20.GlDeleteProgram(programHandle);
                    programHandle = 0;
                }
            }

            if (programHandle == 0)
            {
                throw new Exception("Error creating program.");
            }

            // Set program handles. These will later be used to pass in values to the program.
            mMVPMatrixHandle = GLES20.GlGetUniformLocation(programHandle, "u_MVPMatrix");
            mPositionHandle  = GLES20.GlGetAttribLocation(programHandle, "a_Position");
            mColorHandle     = GLES20.GlGetAttribLocation(programHandle, "a_Color");

            // Tell OpenGL to use this program when rendering.
            GLES20.GlUseProgram(programHandle);
        }
 public void OnDrawFrame(IGL10 gl)
 {
     GLES20.GlClearColor(1, 1, 1, 1);
     GLES20.GlClear(GLES20.GlStencilBufferBit | GLES20.GlColorBufferBit);
 }