Пример #1
0
        public override void Present(float deltaTime)
        {
            IGL10 gl = _glGraphics.GL10;

            gl.GlViewport(0, 0, _glGraphics.Width, _glGraphics.Height);
            gl.GlClearColor(0, 0, 0, 1);
            gl.GlClear(GL10.GlColorBufferBit);
            gl.GlMatrixMode(GL10.GlProjection);
            gl.GlLoadIdentity();
            gl.GlOrthof(0, 540, 0, 960, 1, -1);
            gl.GlEnable(GL10.GlTexture2d);


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

            gl.GlBindTexture(GL10.GlTexture2d, _textureId);



            gl.GlEnableClientState(GL10.GlVertexArray);
            gl.GlEnableClientState(GL10.GlTextureCoordArray);

            _vertices.Position(0);
            gl.GlVertexPointer(2, GL10.GlFloat, _vertexSize, _vertices);
            _vertices.Position(2);
            gl.GlTexCoordPointer(2, GL10.GlFloat, _vertexSize, _vertices);
            gl.GlDrawArrays(GL10.GlTriangles, 0, 3);
            //gl.GlDisableClientState(GL10.GlVertexArray);
            //gl.GlDisableClientState(GL10.GlTextureCoordArray);
        }
Пример #2
0
 public void DrawFrame(SurfaceTexture st)
 {
     CheckGlError("onDrawFrame start");
     st.GetTransformMatrix(mSTMatrix);
     GLES20.GlClearColor(0.0f, 1.0f, 0.0f, 1.0f);
     GLES20.GlClear(GLES20.GlDepthBufferBit | GLES20.GlColorBufferBit);
     GLES20.GlUseProgram(mProgram);
     CheckGlError("glUseProgram");
     GLES20.GlActiveTexture(GLES20.GlTexture0);
     GLES20.GlBindTexture(GLES11Ext.GlTextureExternalOes, _textureID);
     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.GlFinish();
 }
Пример #3
0
        public virtual void DrawElements(FloatBuffer vertices, ShortBuffer indices, int size)
        {
            vertices.Position(0);
            AXy.VertexPointer(2, 4, vertices);

            vertices.Position(2);
            AUv.VertexPointer(2, 4, vertices);

            GLES20.GlDrawElements(GLES20.GlTriangles, size, GLES20.GlUnsignedShort, indices);
        }
Пример #4
0
        public virtual void DrawQuad(FloatBuffer vertices)
        {
            vertices.Position(0);
            AXy.VertexPointer(2, 4, vertices);

            vertices.Position(2);
            AUv.VertexPointer(2, 4, vertices);

            GLES20.GlDrawElements(GLES20.GlTriangles, Quad.SIZE, GLES20.GlUnsignedShort, Quad.GetIndices(1));
        }
Пример #5
0
        public void OnDrawFrame(IGL10 gl)
        {
            GLES20.GlClear(GLES20.GlColorBufferBit | GLES20.GlDepthBufferBit);

            // Draw the triangle facing straight on.
            angleInDegrees += 1.0f;
            float[] mModelMatrix = new float[16];
            Matrix.SetIdentityM(mModelMatrix, 0);

            Matrix.RotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
            //  Matrix.ScaleM(mModelMatrix, 0, angleInDegrees / 1000.0f, 1.0f, 1.0f);
            //  Matrix.TranslateM(mModelMatrix, 0, angleInDegrees / 1000.0f, angleInDegrees / 1000.0f, 0.0f);

            // Pass in the position information
            mTriangle1Vertices.Position(mPositionOffset);
            GLES20.GlVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GlFloat, false, mStrideBytes, mTriangle1Vertices);
            GLES20.GlEnableVertexAttribArray(mPositionHandle);

            // Pass in the color information
            mTriangle1Vertices.Position(mColorOffset);
            GLES20.GlVertexAttribPointer(mColorHandle, mColorDataSize, GLES20.GlFloat, false, mStrideBytes, mTriangle1Vertices);
            GLES20.GlEnableVertexAttribArray(mColorHandle);

            // This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix
            // (which currently contains model * view).
            // Allocate storage for the final combined matrix. This will be passed into the shader program. */
            float[] mMVPMatrix = new float[16];
            Matrix.MultiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);

            // This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix
            // (which now contains model * view * projection).
            // THIS IS NOT WORK AT C# Matrix class -> Matrix.MultiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
            float[] _mMVPMatrix = new float[16];
            Matrix.MultiplyMM(_mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);

            GLES20.GlUniformMatrix4fv(mMVPMatrixHandle, 1, false, _mMVPMatrix, 0);
            //GLES20.GlDrawArrays(GLES20.GlTriangles, 0, 3);

            for (int y = 0; y < 10; y++)
            {
                for (int x = 0; x < 10; x++)
                {
                    Matrix.SetIdentityM(mModelMatrix, 0);
                    Matrix.ScaleM(mModelMatrix, 0, 0.1f, 0.1f, 0.1f);
                    Matrix.TranslateM(mModelMatrix, 0, x * 2.0f, y * 2.0f, 0.0f);
                    Matrix.RotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);

                    Matrix.MultiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
                    Matrix.MultiplyMM(_mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
                    GLES20.GlUniformMatrix4fv(mMVPMatrixHandle, 1, false, _mMVPMatrix, 0);
                    GLES20.GlDrawArrays(GLES20.GlTriangles, 0, 3);
                }
            }
        }
Пример #6
0
        public virtual void DrawQuadSet(FloatBuffer vertices, int size)
        {
            if (size == 0)
            {
                return;
            }

            vertices.Position(0);
            AXy.VertexPointer(2, 4, vertices);

            vertices.Position(2);
            AUv.VertexPointer(2, 4, vertices);

            GLES20.GlDrawElements(GLES20.GlTriangles, Quad.SIZE * size, GLES20.GlUnsignedShort, Quad.GetIndices(size));
        }
Пример #7
0
		public Square ()
		{
			// initialize vertex byte buffer for shape coordinates
			ByteBuffer bb = ByteBuffer.AllocateDirect (
			// (# of coordinate values * 4 bytes per float)
			        squareCoords.Length * 4);
			bb.Order (ByteOrder.NativeOrder ());
			vertexBuffer = bb.AsFloatBuffer ();
			vertexBuffer.Put (squareCoords);
			vertexBuffer.Position (0);

			// initialize byte buffer for the draw list
			ByteBuffer dlb = ByteBuffer.AllocateDirect (
			// (# of coordinate values * 2 bytes per short)
			        drawOrder.Length * 2);
			dlb.Order (ByteOrder.NativeOrder ());
			drawListBuffer = dlb.AsShortBuffer ();
			drawListBuffer.Put (drawOrder);
			drawListBuffer.Position (0);

			// prepare shaders and OpenGL program
			int vertexShader = MyGLRenderer.LoadShader (GLES20.GlVertexShader,
			                                           vertexShaderCode);
			int fragmentShader = MyGLRenderer.LoadShader (GLES20.GlFragmentShader,
			                                             fragmentShaderCode);

			mProgram = GLES20.GlCreateProgram ();             // create empty OpenGL Program
			GLES20.GlAttachShader (mProgram, vertexShader);   // add the vertex shader to program
			GLES20.GlAttachShader (mProgram, fragmentShader); // add the fragment shader to program
			GLES20.GlLinkProgram (mProgram);                  // create OpenGL program executables
		}
Пример #8
0
        protected internal virtual void UpdateVertices()
        {
            verticesBuffer.Position(0);

            var Right  = Width - marginRight;
            var Bottom = Height - marginBottom;

            Quad.Fill(vertices, 0, marginLeft, 0, marginTop, outterF.Left, innerF.Left, outterF.Top, innerF.Top);
            verticesBuffer.Put(vertices);
            Quad.Fill(vertices, marginLeft, Right, 0, marginTop, innerF.Left, innerF.Right, outterF.Top, innerF.Top);
            verticesBuffer.Put(vertices);
            Quad.Fill(vertices, Right, Width, 0, marginTop, innerF.Right, outterF.Right, outterF.Top, innerF.Top);
            verticesBuffer.Put(vertices);

            Quad.Fill(vertices, 0, marginLeft, marginTop, Bottom, outterF.Left, innerF.Left, innerF.Top, innerF.Bottom);
            verticesBuffer.Put(vertices);
            Quad.Fill(vertices, marginLeft, Right, marginTop, Bottom, innerF.Left, innerF.Right, innerF.Top, innerF.Bottom);
            verticesBuffer.Put(vertices);
            Quad.Fill(vertices, Right, Width, marginTop, Bottom, innerF.Right, outterF.Right, innerF.Top, innerF.Bottom);
            verticesBuffer.Put(vertices);

            Quad.Fill(vertices, 0, marginLeft, Bottom, Height, outterF.Left, innerF.Left, innerF.Bottom, outterF.Bottom);
            verticesBuffer.Put(vertices);
            Quad.Fill(vertices, marginLeft, Right, Bottom, Height, innerF.Left, innerF.Right, innerF.Bottom, outterF.Bottom);
            verticesBuffer.Put(vertices);
            Quad.Fill(vertices, Right, Width, Bottom, Height, innerF.Right, outterF.Right, innerF.Bottom, outterF.Bottom);
            verticesBuffer.Put(vertices);
        }
		public Triangle ()
		{
			// initialize vertex byte buffer for shape coordinates
			ByteBuffer bb = ByteBuffer.AllocateDirect (
	                // (number of coordinate values * 4 bytes per float)
				                triangleCoords.Length * 4);
			// use the device hardware's native byte order
			bb.Order (ByteOrder.NativeOrder ());

			// create a floating point buffer from the ByteBuffer
			vertexBuffer = bb.AsFloatBuffer ();
			// add the coordinates to the FloatBuffer
			vertexBuffer.Put (triangleCoords);
			// set the buffer to read the first coordinate
			vertexBuffer.Position (0);

			// prepare shaders and OpenGL program
			int vertexShader = MyGLRenderer.LoadShader (GLES30.GlVertexShader,
				                   vertexShaderCode);
			int fragmentShader = MyGLRenderer.LoadShader (GLES30.GlFragmentShader,
				                     fragmentShaderCode);

			mProgram = GLES30.GlCreateProgram ();             // create empty OpenGL Program
			GLES30.GlAttachShader (mProgram, vertexShader);   // add the vertex shader to program
			GLES30.GlAttachShader (mProgram, fragmentShader); // add the fragment shader to program
			GLES30.GlLinkProgram (mProgram);                  // create OpenGL program executables
		}
Пример #10
0
        public CameraFrustum()
        {
            // Reset the model matrix to the identity
            Matrix.SetIdentityM(ModelMatrix, 0);

            // Load the vertices into a vertex buffer
            ByteBuffer byteBuf = ByteBuffer.AllocateDirect(mVertices.Length * 4);

            byteBuf.Order(ByteOrder.NativeOrder());
            mVertexBuffer = byteBuf.AsFloatBuffer();
            mVertexBuffer.Put(mVertices);
            mVertexBuffer.Position(0);

            // Load the colors into a color buffer
            ByteBuffer cByteBuff = ByteBuffer.AllocateDirect(mColors.Length * 4);

            cByteBuff.Order(ByteOrder.NativeOrder());
            mColorBuffer = cByteBuff.AsFloatBuffer();
            mColorBuffer.Put(mColors);
            mColorBuffer.Position(0);

            // Load the vertex and fragment shaders, then link the program
            int vertexShader = RenderUtils.loadShader(GLES20.GlVertexShader, sVertexShaderCode);
            int fragShader   = RenderUtils.loadShader(GLES20.GlFragmentShader, sFragmentShaderCode);

            mProgram = GLES20.GlCreateProgram();
            GLES20.GlAttachShader(mProgram, vertexShader);
            GLES20.GlAttachShader(mProgram, fragShader);
            GLES20.GlLinkProgram(mProgram);
        }
Пример #11
0
        public Square()
        {
            // initialize vertex byte buffer for shape coordinates
            ByteBuffer bb = ByteBuffer.AllocateDirect(
                // (# of coordinate values * 4 bytes per float)
                squareCoords.Length * 4);

            bb.Order(ByteOrder.NativeOrder());
            vertexBuffer = bb.AsFloatBuffer();
            vertexBuffer.Put(squareCoords);
            vertexBuffer.Position(0);

            // initialize byte buffer for the draw list
            ByteBuffer dlb = ByteBuffer.AllocateDirect(
                // (# of coordinate values * 2 bytes per short)
                drawOrder.Length * 2);

            dlb.Order(ByteOrder.NativeOrder());
            drawListBuffer = dlb.AsShortBuffer();
            drawListBuffer.Put(drawOrder);
            drawListBuffer.Position(0);

            // prepare shaders and OpenGL program
            int vertexShader = MyGLRenderer.LoadShader(GLES20.GlVertexShader,
                                                       vertexShaderCode);
            int fragmentShader = MyGLRenderer.LoadShader(GLES20.GlFragmentShader,
                                                         fragmentShaderCode);

            mProgram = GLES20.GlCreateProgram();                          // create empty OpenGL Program
            GLES20.GlAttachShader(mProgram, vertexShader);                // add the vertex shader to program
            GLES20.GlAttachShader(mProgram, fragmentShader);              // add the fragment shader to program
            GLES20.GlLinkProgram(mProgram);                               // create OpenGL program executables
        }
        /**
         * Allocates and initializes OpenGL resources needed by the background renderer.  Must be
         * called on the OpenGL thread, typically in
         * {@link GLSurfaceView.Renderer#onSurfaceCreated(GL10, EGLConfig)}.
         *
         * @param context Needed to access shader source.
         */
        public void CreateOnGlThread(Context context)
        {
            // Generate the background texture.
            var textures = new int[1];

            //GLES20 = OpenGL ES 2.0
            //Gibt eine bestimmte Anzahl an freien Texturnamen zurück.
            GLES20.GlGenTextures(1, textures, 0);

            TextureId = textures[0];
            GLES20.GlBindTexture(mTextureTarget, TextureId);
            GLES20.GlTexParameteri(mTextureTarget, GLES20.GlTextureWrapS, GLES20.GlClampToEdge);
            GLES20.GlTexParameteri(mTextureTarget, GLES20.GlTextureWrapT, GLES20.GlClampToEdge);
            GLES20.GlTexParameteri(mTextureTarget, GLES20.GlTextureMinFilter, GLES20.GlNearest);
            GLES20.GlTexParameteri(mTextureTarget, GLES20.GlTextureMagFilter, GLES20.GlNearest);

            int numVertices = 4;

            if (numVertices != QUAD_COORDS.Length / COORDS_PER_VERTEX)
            {
                throw new Exception("Unexpected number of vertices in BackgroundRenderer.");
            }

            var bbVertices = ByteBuffer.AllocateDirect(QUAD_COORDS.Length * FLOAT_SIZE);

            bbVertices.Order(ByteOrder.NativeOrder());
            mQuadVertices = bbVertices.AsFloatBuffer();
            mQuadVertices.Put(QUAD_COORDS);
            mQuadVertices.Position(0);

            var bbTexCoords = ByteBuffer.AllocateDirect(numVertices * TEXCOORDS_PER_VERTEX * FLOAT_SIZE);

            bbTexCoords.Order(ByteOrder.NativeOrder());
            mQuadTexCoord = bbTexCoords.AsFloatBuffer();
            mQuadTexCoord.Put(QUAD_TEXCOORDS);
            mQuadTexCoord.Position(0);

            var bbTexCoordsTransformed = ByteBuffer.AllocateDirect(numVertices * TEXCOORDS_PER_VERTEX * FLOAT_SIZE);

            bbTexCoordsTransformed.Order(ByteOrder.NativeOrder());
            mQuadTexCoordTransformed = bbTexCoordsTransformed.AsFloatBuffer();

            int vertexShader = ShaderUtil.LoadGLShader(TAG, context,
                                                       GLES20.GlVertexShader, Resource.Raw.screenquad_vertex);
            int fragmentShader = ShaderUtil.LoadGLShader(TAG, context,
                                                         GLES20.GlFragmentShader, Resource.Raw.screenquad_fragment_oes);

            mQuadProgram = GLES20.GlCreateProgram();
            GLES20.GlAttachShader(mQuadProgram, vertexShader);
            GLES20.GlAttachShader(mQuadProgram, fragmentShader);
            GLES20.GlLinkProgram(mQuadProgram);
            GLES20.GlUseProgram(mQuadProgram);

            ShaderUtil.CheckGLError(TAG, "Program creation");

            mQuadPositionParam = GLES20.GlGetAttribLocation(mQuadProgram, "a_Position");
            mQuadTexCoordParam = GLES20.GlGetAttribLocation(mQuadProgram, "a_TexCoord");

            ShaderUtil.CheckGLError(TAG, "Program parameters");
        }
Пример #13
0
            public Sky(bool dayTime)
                : base(0, 0, 1, 1)
            {
                _texture = new Gradient(dayTime ? Day : Night);

                var vertices = new float[16];

                _verticesBuffer = Quad.Create();

                vertices[2]  = 0.25f;
                vertices[6]  = 0.25f;
                vertices[10] = 0.75f;
                vertices[14] = 0.75f;

                vertices[3]  = 0;
                vertices[7]  = 1;
                vertices[11] = 1;
                vertices[15] = 0;


                vertices[0] = 0;
                vertices[1] = 0;

                vertices[4] = 1;
                vertices[5] = 0;

                vertices[8] = 1;
                vertices[9] = 1;

                vertices[12] = 0;
                vertices[13] = 1;

                _verticesBuffer.Position(0);
                _verticesBuffer.Put(vertices);
            }
Пример #14
0
        /**
         * Sets up the drawing object data for use in an OpenGL ES context.
         */
        public Triangle()
        {
            // initialize vertex byte buffer for shape coordinates
            ByteBuffer bb = ByteBuffer.AllocateDirect(
                // (number of coordinate values * 4 bytes per float)
                triangleCoords.Length * 4);

            // use the device hardware's native byte order
            bb.Order(ByteOrder.NativeOrder());

            // create a floating point buffer from the ByteBuffer
            vertexBuffer = bb.AsFloatBuffer();
            // add the coordinates to the FloatBuffer
            vertexBuffer.Put(triangleCoords);
            // set the buffer to read the first coordinate
            vertexBuffer.Position(0);

            // prepare shaders and OpenGL program
            int vertexShader   = MainRenderer.loadShader(GLES20.GlVertexShader, vertexShaderCode);
            int fragmentShader = MainRenderer.loadShader(GLES20.GlFragmentShader, fragmentShaderCode);

            mProgram = GLES20.GlCreateProgram();             // create empty OpenGL Program
            GLES20.GlAttachShader(mProgram, vertexShader);   // add the vertex shader to program
            GLES20.GlAttachShader(mProgram, fragmentShader); // add the fragment shader to program
            GLES20.GlLinkProgram(mProgram);                  // create OpenGL program executables
        }
Пример #15
0
        /// <summary>
        /// Obtain Texture buffer.
        /// </summary>
        /// <param name="obj">Texture list from .obj file</param>
        /// <param name="dimensions">Dimension of Texture</param>
        /// <returns>FloatBuffer</returns>
        public static FloatBuffer GetTexturesFloatBuffer(IList <Texture> obj, int dimensions)
        {
            FloatBuffer buffer = CreateDirectFloatBuffer(obj.Count * dimensions);

            GetTextures(obj, buffer);
            buffer.Position(0);
            return(buffer);
        }
Пример #16
0
        /// <summary>
        /// Obtain Vertices buffer.
        /// </summary>
        /// <param name="obj">Vertex list from .obj file</param>
        /// <returns>FloatBuffer</returns>
        public static FloatBuffer GetVerticesFloatBuffer(IList <Vertex> obj)
        {
            FloatBuffer buffer = CreateDirectFloatBuffer(obj.Count * 3);

            GetVertices(obj, buffer);
            buffer.Position(0);
            return(buffer);
        }
Пример #17
0
        /// <summary>
        /// Obtain Normal buffer.
        /// </summary>
        /// <param name="obj">Normal list from .obj file</param>
        /// <returns>FloatBuffer</returns>
        public static FloatBuffer GetNormalsFloatBuffer(IList <Normal> obj)
        {
            FloatBuffer buffer = CreateDirectFloatBuffer(obj.Count * 3);

            GetNormals(obj, buffer);
            buffer.Position(0);
            return(buffer);
        }
Пример #18
0
        public virtual void updateTrajectory(float[] translation)
        {
            mVertexBuffer.Position(mTrajectoryCount * 3);
            if (((mTrajectoryCount + 1) * 3) >= MAX_VERTICES)
            {
                Log.Warn(TAG, "Clearing float buffer");
                resetPath();
            }
            float dx = 0, dy = 0, dz = 0;

            try
            {
                dx = mVertexBuffer.Get(mVertexBuffer.Position() - 3) - translation[0];
                dy = mVertexBuffer.Get(mVertexBuffer.Position() - 2) - translation[2];
                dz = mVertexBuffer.Get(mVertexBuffer.Position() - 1) - (-translation[1]);
            }
            catch (System.IndexOutOfRangeException)
            {
                mVertexBuffer.Put(new float[] { translation[0], translation[2], -translation[1] });
                mTrajectoryCount++;
            }
            float distance = (float)Math.Sqrt(dx * dx + dy * dy + dz * dz);

            if (distance > MIN_DISTANCE_CHECK)
            {
                mVertexBuffer.Put(new float[] { translation[0], translation[2], -translation[1] });
                mTrajectoryCount++;
            }
        }
Пример #19
0
        public override void Present(float delta)
        {
            IGL10 gl = _glGraphics.GL10;

            gl.GlViewport(0, 0, _glGraphics.Width, _glGraphics.Height);
            gl.GlClear(GL10.GlColorBufferBit);
            gl.GlMatrixMode(GL10.GlProjection);
            gl.GlLoadIdentity();
            gl.GlOrthof(0, 540, 0, 960, 1, -1);
            //gl.GlColor4f (1,0,0,1);
            gl.GlEnableClientState(GL10.GlVertexArray);
            gl.GlEnableClientState(GL10.GlColorArray);
            _vertices.Position(0);
            gl.GlVertexPointer(2, GL10.GlFloat, _vertexSize, _vertices);
            _vertices.Position(2);
            gl.GlColorPointer(4, GL10.GlFloat, _vertexSize, _vertices);
            gl.GlDrawArrays(GL10.GlTriangles, 0, 3);
            gl.GlDrawArrays(GL10.GlTriangles, 0, 3);
        }
Пример #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);
            }
Пример #21
0
        private void DrawTriangle(FloatBuffer aTriangleBuffer)
        {
            // Pass in the position information.
            aTriangleBuffer.Position(mPositionOffset);

            GLES20.GlVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GlFloat, false, mStrideBytes, aTriangleBuffer);
            GLES20.GlEnableVertexAttribArray(mPositionHandle);

            //Pass in the color information

            aTriangleBuffer.Position(mColorOffset);
            GLES20.GlVertexAttribPointer(mColorHandle, mColorDataSize, GLES20.GlFloat, false, mStrideBytes, aTriangleBuffer);
            GLES20.GlEnableVertexAttribArray(mColorHandle);

            Matrix.MultiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);

            Matrix.MultiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);

            GLES20.GlUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
            GLES20.GlDrawArrays(GLES20.GlTriangles, 0, 3);
        }
Пример #22
0
 public MainRenderer(MainView view)
 {
     mView = view;
     float[] vtmp = { 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f };
     float[] ttmp = { 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f };
     pVertex = ByteBuffer.AllocateDirect(8 * 4).Order(ByteOrder.NativeOrder()).AsFloatBuffer();
     pVertex.Put(vtmp);
     pVertex.Position(0);
     pTexCoord = ByteBuffer.AllocateDirect(8 * 4).Order(ByteOrder.NativeOrder()).AsFloatBuffer();
     pTexCoord.Put(ttmp);
     pTexCoord.Position(0);
 }
Пример #23
0
 public MainRenderer(MainView view)
 {
     mView = view;
     float[] vtmp = { 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f };
     float[] ttmp = { 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f };
     pVertex = ByteBuffer.AllocateDirect(8 * 4).Order(ByteOrder.NativeOrder()).AsFloatBuffer();
     pVertex.Put(vtmp);
     pVertex.Position(0);
     pTexCoord = ByteBuffer.AllocateDirect(8 * 4).Order(ByteOrder.NativeOrder()).AsFloatBuffer();
     pTexCoord.Put(ttmp);
     pTexCoord.Position(0);
 }
Пример #24
0
        protected internal virtual void UpdateVertices()
        {
            var y1 = _cellH * updated.Top;
            var y2 = y1 + _cellH;

            for (var i = updated.Top; i < updated.Bottom; i++)
            {
                var x1 = _cellW * updated.Left;
                var x2 = x1 + _cellW;

                var pos = i * mapWidth + updated.Left;
                quads.Position(16 * pos);

                for (var j = updated.Left; j < updated.Right; j++)
                {
                    var uv = tileset.Get(data[pos++]);

                    vertices[0] = x1;
                    vertices[1] = y1;

                    vertices[2] = uv.Left;
                    vertices[3] = uv.Top;

                    vertices[4] = x2;
                    vertices[5] = y1;

                    vertices[6] = uv.Right;
                    vertices[7] = uv.Top;

                    vertices[8] = x2;
                    vertices[9] = y2;

                    vertices[10] = uv.Right;
                    vertices[11] = uv.Bottom;

                    vertices[12] = x1;
                    vertices[13] = y2;

                    vertices[14] = uv.Left;
                    vertices[15] = uv.Bottom;

                    quads.Put(vertices);

                    x1  = x2;
                    x2 += _cellW;
                }

                y1  = y2;
                y2 += _cellH;
            }

            updated.SetEmpty();
        }
Пример #25
0
        public override void Present(float deltaTime)
        {
            IGL10 gl = _glGraphics.GL10;

            gl.GlViewport(0, 0, _glGraphics.Width, _glGraphics.Height);
            gl.GlClear(GL10.GlColorBufferBit);
            gl.GlMatrixMode(GL10.GlProjection);
            gl.GlLoadIdentity();
            gl.GlOrthof(0, 540, 0, 960, 1, -1);
            gl.GlEnable(GL10.GlTexture2d);

            _texture.BindTexture();

            gl.GlEnableClientState(GL10.GlVertexArray);
            gl.GlEnableClientState(GL10.GlTextureCoordArray);
            _vertices.Position(0);
            gl.GlVertexPointer(2, GL10.GlFloat, _vertexSize, _vertices);
            _vertices.Position(2);
            gl.GlTexCoordPointer(2, GL10.GlFloat, _vertexSize, _vertices);
            gl.GlDrawElements(GL10.GlTriangles, 6, GL10.GlUnsignedShort, _indices);
        }
Пример #26
0
        public void Bind()
        {
            IGL10 gl = _glGraphics.GL10;

            gl.GlEnableClientState(GL10.GlVertexArray);
            _vertices.Position(0);
            gl.GlVertexPointer(2, GL10.GlFloat, _vertexSize, _vertices);

            if (_hasColor)
            {
                gl.GlEnableClientState(GL10.GlColorArray);
                _vertices.Position(2);
                gl.GlColorPointer(4, GL10.GlFloat, _vertexSize, _vertices);
            }

            if (_hasTexCoords)
            {
                gl.GlEnableClientState(GL10.GlTextureCoordArray);
                _vertices.Position(_hasColor?6:2);
                gl.GlTexCoordPointer(2, GL10.GlFloat, _vertexSize, _vertices);
            }
        }
Пример #27
0
            public void OnDrawFrame(Javax.Microedition.Khronos.Opengles.IGL10 glUnused)
            {
                if (_updateSurface)
                {
                    _surfaceTexture.UpdateTexImage();
                    _surfaceTexture.GetTransformMatrix(_STMatrix);
                    _updateSurface = false;
                }

                GLES20.GlUseProgram(0);
                GLES20.GlUseProgram(_glProgram);
                GLES20.GlActiveTexture(GLES20.GlTexture2);
                var tWidth  = _width;
                var tHeight = _height;

                funnyGhostEffectBuffer = ByteBuffer.AllocateDirect(tWidth * tHeight * 4);
                funnyGhostEffectBuffer.Order(ByteOrder.NativeOrder());
                funnyGhostEffectBuffer.Position(0);

                // Note that it is read in GlReadPixels in a different pixel order than top-left to lower-right, so it adds a reversed+mirror effect
                // when passed to TexImage2D to convert to texture.
                GLES20.GlReadPixels(0, 0, tWidth - 1, tHeight - 1, GLES20.GlRgba, GLES20.GlUnsignedByte, funnyGhostEffectBuffer);
                updateTargetTexture(tWidth, tHeight);
                GLES20.GlBindTexture(GLES20.GlTexture2d, _otherTextureId);
                GLES20.GlUniform1i(_otherTextureUniform, 2);

                GLES20.GlUseProgram(0);
                GLES20.GlUseProgram(_glProgram);
                GLES20.GlActiveTexture(GLES20.GlTexture1);
                GLES20.GlBindTexture(GLES11Ext.GlTextureExternalOes, _OESTextureId);
                GLES20.GlUniform1i(_OESTextureUniform, 1);

                _triangleVertices.Position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
                GLES20.GlVertexAttribPointer(_aPositionHandle, 3, GLES20.GlFloat, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, _triangleVertices);
                GLES20.GlEnableVertexAttribArray(_aPositionHandle);

                _textureVertices.Position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
                GLES20.GlVertexAttribPointer(_aTextureCoord, 2, GLES20.GlFloat, false, TEXTURE_VERTICES_DATA_STRIDE_BYTES, _textureVertices);
                GLES20.GlEnableVertexAttribArray(_aTextureCoord);

                Android.Opengl.Matrix.SetIdentityM(_MVPMatrix, 0);
                GLES20.GlUniformMatrix4fv(_uMVPMatrixHandle, 1, false, _MVPMatrix, 0);
                GLES20.GlUniformMatrix4fv(_uSTMatrixHandle, 1, false, _STMatrix, 0);

                GLES20.GlDrawArrays(GLES20.GlTriangleStrip, 0, 4);

                GLES20.GlFinish();
            }
Пример #28
0
        public void OnDrawFrame(IGL10 gl)
        {
            // Our vertices.
            float[] vertices =
            {
                -1.5f,  1.5f, 0.0f,                 // 0, Top Left
                -1.5f, -1.5f, 0.0f,                 // 1, Bottom Left
                1.5f,   1.5f, 0.0f,                 // 3, Top Right
                1.5f,  -1.5f, 0.0f,                 // 2, Bottom Right
            };

            // a float is 4 bytes, therefore we multiply the number if
            // vertices with 4.
            ByteBuffer vbb = ByteBuffer.AllocateDirect(vertices.Length * 4);

            vbb.Order(ByteOrder.NativeOrder());
            FloatBuffer vertexBuffer = vbb.AsFloatBuffer();

            vertexBuffer.Put(vertices);
            vertexBuffer.Position(0);

            // The order we like to connect them.
            byte[] colors =
            {
                (byte)0.0, (byte)255, (byte)0.0, (byte)255,
                (byte)0.0, (byte)255, (byte)0.0, (byte)255,
                (byte)0.0, (byte)255, (byte)0.0, (byte)255,
                (byte)0.0, (byte)255, (byte)0.0, (byte)255
            };

            // a float is 4 bytes, therefore we multiply the number if
            // vertices with 4.
            ByteBuffer cbb = ByteBuffer.AllocateDirect(colors.Length * 4);

            cbb.Order(ByteOrder.NativeOrder());
            cbb.Put(colors);
            cbb.Position(0);

            gl.GlVertexPointer(3, GL10.GlFloat, 0, vertexBuffer);
            gl.GlEnableClientState(GL10.GlVertexArray);
            gl.GlColorPointer(4, GL10.GlUnsignedByte, 0, cbb);
            gl.GlEnableClientState(GL10.GlColorArray);

            gl.GlDrawArrays(GL10.GlTriangleStrip, 0, 4);
        }
        private void SetupTriangle()
        {
            rect = new RectF(10, 200, 100, 10);

            /*rect.Left = 10;
            *  rect.Right = 100;
            *  rect.Bottom = 100;
            *  rect.Top = 200;*/

            // We have to create the vertices.

            /*vertices = new float[]
             * {
             *  10.0f, 200f, 0.0f,
             *  10.0f, 100f, 0.0f,
             *  100f, 100f, 0.0f,
             *  100f, 200f, 0.0f,
             * };*/
            vertices = new float[]
            {
                rect.Left, rect.Top, 0.0f,
                rect.Left, rect.Bottom, 0.0f,
                rect.Right, rect.Bottom, 0.0f,
                rect.Right, rect.Top, 0.0f,
            };


            indices = new short[] { 0, 1, 2, 0, 2, 3 }; // The order of vertexrendering.

            // The vertex buffer.
            ByteBuffer byteBuffer = ByteBuffer.AllocateDirect(vertices.Length * 4);

            byteBuffer.Order(ByteOrder.NativeOrder());
            vertexBuffer = byteBuffer.AsFloatBuffer();
            vertexBuffer.Put(vertices);
            vertexBuffer.Position(0);

            // initialize byte buffer for the draw list
            ByteBuffer byteBuffer2 = ByteBuffer.AllocateDirect(indices.Length * 2);

            byteBuffer2.Order(ByteOrder.NativeOrder());
            drawListBuffer = byteBuffer2.AsShortBuffer();
            drawListBuffer.Put(indices);
            drawListBuffer.Position(0);
        }
Пример #30
0
      public Cube()
      {
         ByteBuffer byteBuf = ByteBuffer.AllocateDirect(vertices.Length * 4);
         byteBuf.Order(ByteOrder.NativeOrder());
         mVertexBuffer = byteBuf.AsFloatBuffer();
         mVertexBuffer.Put(vertices);
         mVertexBuffer.Position(0);

         byteBuf = ByteBuffer.AllocateDirect(colors.Length * 4);
         byteBuf.Order(ByteOrder.NativeOrder());
         mColorBuffer = byteBuf.AsFloatBuffer();
         mColorBuffer.Put(colors);
         mColorBuffer.Position(0);

         mIndexBuffer = ByteBuffer.AllocateDirect(indices.Length);
         mIndexBuffer.Put(indices);
         mIndexBuffer.Position(0);
      }
        private void SetupImage()
        {
            // Create our UV coordinates.
            uvs = new float[] {
                0.0f, 0.0f,
                0.0f, 1.0f,
                1.0f, 1.0f,
                1.0f, 0.0f
            };

            // The texture buffer
            ByteBuffer byteBuffer = ByteBuffer.AllocateDirect(uvs.Length * 4);

            byteBuffer.Order(ByteOrder.NativeOrder());
            uvBuffer = byteBuffer.AsFloatBuffer();
            uvBuffer.Put(uvs);
            uvBuffer.Position(0);

            // Generate Textures, if more needed, alter these numbers.
            int[] textureIds = new int[1];
            GLES20.GlGenTextures(1, textureIds, 0);

            // Retrieve our image from resources.
            Bitmap bitmap = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.plant07);

            // Bind texture to texturename
            GLES20.GlActiveTexture(GLES20.GlTexture0);
            GLES20.GlBindTexture(GLES20.GlTexture2d, textureIds[0]);

            // Set filtering
            GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMinFilter, GLES20.GlLinear);
            GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMagFilter, GLES20.GlLinear);

            // Set wrapping mode
            GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapS, GLES20.GlClampToEdge);
            GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapT, GLES20.GlClampToEdge);

            // Load the bitmap into the bound texture.
            GLUtils.TexImage2D(GLES20.GlTexture2d, 0, bitmap, 0);

            // We are done using the bitmap so we should recycle it.
            bitmap.Recycle();
            bitmap.Dispose();
        }
Пример #32
0
        /// <summary>
        /// Adds a basic series of triangles to render.
        /// </summary>
        /// <param name="corners">Triangle data.</param>
        /// <param name="argb">The ARGB colors.</param>
        public void AddTriangles(float[] corners, int argb)
        {
            // a float is 4 bytes, therefore we multiply the number if
            // vertices with 4.
            ByteBuffer vbb = ByteBuffer.AllocateDirect(corners.Length * 4);

            vbb.Order(ByteOrder.NativeOrder());
            FloatBuffer vertexBuffer = vbb.AsFloatBuffer();

            vertexBuffer.Put(corners);
            vertexBuffer.Position(0);

            // The order we like to connect them.
            SimpleColor color = new SimpleColor()
            {
                Value = argb
            };
            int count = corners.Length / 3;

            byte[] colors = new byte[count * 4];
            for (int idx = 0; idx < count; idx++)
            {
                colors [idx * 4]     = (byte)color.R;
                colors [idx * 4 + 1] = (byte)color.G;
                colors [idx * 4 + 2] = (byte)color.B;
                colors [idx * 4 + 3] = (byte)color.A;
            }

            // a float is 4 bytes, therefore we multiply the number if
            // vertices with 4.
            ByteBuffer cbb = ByteBuffer.AllocateDirect(colors.Length);

            cbb.Order(ByteOrder.NativeOrder());
            cbb.Put(colors);
            cbb.Position(0);

            _triangles.Add(new TriangleProcessed()
            {
                Vertices = vertexBuffer,
                Colors   = cbb,
                Count    = corners.Length / 3
            });
        }
Пример #33
0
        public Cube()
        {
            ByteBuffer byteBuf = ByteBuffer.AllocateDirect(vertices.Length * 4);

            byteBuf.Order(ByteOrder.NativeOrder());
            mVertexBuffer = byteBuf.AsFloatBuffer();
            mVertexBuffer.Put(vertices);
            mVertexBuffer.Position(0);

            byteBuf = ByteBuffer.AllocateDirect(colors.Length * 4);
            byteBuf.Order(ByteOrder.NativeOrder());
            mColorBuffer = byteBuf.AsFloatBuffer();
            mColorBuffer.Put(colors);
            mColorBuffer.Position(0);

            mIndexBuffer = ByteBuffer.AllocateDirect(indices.Length);
            mIndexBuffer.Put(indices);
            mIndexBuffer.Position(0);
        }
Пример #34
0
        public override void draw(float[] viewMatrix, float[] projectionMatrix)
        {
            GLES20.GlUseProgram(mProgram);
            mVertexBuffer.Position(0);

            // Compose the model, view, and projection matrices into a single m-v-p
            // matrix
            updateMvpMatrix(viewMatrix, projectionMatrix);

            // Load vertex attribute data
            mPosHandle = GLES20.GlGetAttribLocation(mProgram, "vPosition");
            GLES20.GlVertexAttribPointer(mPosHandle, COORDS_PER_VERTEX, GLES20.GlFloat, false, 0, mVertexBuffer);
            GLES20.GlEnableVertexAttribArray(mPosHandle);

            // Draw the Grid
            mMVPMatrixHandle = GLES20.GlGetUniformLocation(mProgram, "uMVPMatrix");
            GLES20.GlUniformMatrix4fv(mMVPMatrixHandle, 1, false, MvpMatrix, 0);
            GLES20.GlLineWidth(1);
            GLES20.GlDrawArrays(GLES20.GlLines, 0, (GRID_RANGE_M * 2 + 1) * 4);
        }
        /**
        * Creates the buffers we use to store information about the 3D world.
        *
        * OpenGL doesn't use Java arrays, but rather needs data in a format it can understand.
        * Hence we use ByteBuffers.
        */
        public void OnSurfaceCreated (Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            Android.Util.Log.Info (TAG, "onSurfaceCreated");

            GLES20.GlClearColor (0.1f, 0.1f, 0.1f, 0.5f); // Dark background so text shows up well.

            var bbVertices = ByteBuffer.AllocateDirect (WorldLayoutData.CUBE_COORDS.Length * 4);
            bbVertices.Order (ByteOrder.NativeOrder ());
            cubeVertices = bbVertices.AsFloatBuffer ();
            cubeVertices.Put (WorldLayoutData.CUBE_COORDS);
            cubeVertices.Position (0);

            var bbColors = ByteBuffer.AllocateDirect (WorldLayoutData.CUBE_COLORS.Length * 4);
            bbColors.Order (ByteOrder.NativeOrder ());
            cubeColors = bbColors.AsFloatBuffer ();
            cubeColors.Put (WorldLayoutData.CUBE_COLORS);
            cubeColors.Position (0);

            var bbFoundColors = ByteBuffer.AllocateDirect (WorldLayoutData.CUBE_FOUND_COLORS.Length * 4);
            bbFoundColors.Order (ByteOrder.NativeOrder ());
            cubeFoundColors = bbFoundColors.AsFloatBuffer ();
            cubeFoundColors.Put (WorldLayoutData.CUBE_FOUND_COLORS);
            cubeFoundColors.Position (0);

            var bbNormals = ByteBuffer.AllocateDirect (WorldLayoutData.CUBE_NORMALS.Length * 4);
            bbNormals.Order (ByteOrder.NativeOrder ());
            cubeNormals = bbNormals.AsFloatBuffer ();
            cubeNormals.Put (WorldLayoutData.CUBE_NORMALS);
            cubeNormals.Position (0);

            // make a floor
            var bbFloorVertices = ByteBuffer.AllocateDirect (WorldLayoutData.FLOOR_COORDS.Length * 4);
            bbFloorVertices.Order (ByteOrder.NativeOrder ());
            floorVertices = bbFloorVertices.AsFloatBuffer ();
            floorVertices.Put (WorldLayoutData.FLOOR_COORDS);
            floorVertices.Position (0);

            var bbFloorNormals = ByteBuffer.AllocateDirect (WorldLayoutData.FLOOR_NORMALS.Length * 4);
            bbFloorNormals.Order (ByteOrder.NativeOrder ());
            floorNormals = bbFloorNormals.AsFloatBuffer ();
            floorNormals.Put (WorldLayoutData.FLOOR_NORMALS);
            floorNormals.Position (0);

            var bbFloorColors = ByteBuffer.AllocateDirect (WorldLayoutData.FLOOR_COLORS.Length * 4);
            bbFloorColors.Order (ByteOrder.NativeOrder ());
            floorColors = bbFloorColors.AsFloatBuffer ();
            floorColors.Put (WorldLayoutData.FLOOR_COLORS);
            floorColors.Position (0);

            int vertexShader = loadGLShader (GLES20.GlVertexShader, Resource.Raw.light_vertex);
            int gridShader = loadGLShader (GLES20.GlFragmentShader, Resource.Raw.grid_fragment);
            int passthroughShader = loadGLShader (GLES20.GlFragmentShader, Resource.Raw.passthrough_fragment);

            cubeProgram = GLES20.GlCreateProgram ();
            GLES20.GlAttachShader (cubeProgram, vertexShader);
            GLES20.GlAttachShader (cubeProgram, passthroughShader);
            GLES20.GlLinkProgram (cubeProgram);
            GLES20.GlUseProgram (cubeProgram);

            CheckGLError ("Cube program");

            cubePositionParam = GLES20.GlGetAttribLocation (cubeProgram, "a_Position");
            cubeNormalParam = GLES20.GlGetAttribLocation (cubeProgram, "a_Normal");
            cubeColorParam = GLES20.GlGetAttribLocation (cubeProgram, "a_Color");

            cubeModelParam = GLES20.GlGetUniformLocation (cubeProgram, "u_Model");
            cubeModelViewParam = GLES20.GlGetUniformLocation (cubeProgram, "u_MVMatrix");
            cubeModelViewProjectionParam = GLES20.GlGetUniformLocation (cubeProgram, "u_MVP");
            cubeLightPosParam = GLES20.GlGetUniformLocation (cubeProgram, "u_LightPos");

            CheckGLError ("Cube program params");

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

            CheckGLError ("Floor program");

            floorModelParam = GLES20.GlGetUniformLocation (floorProgram, "u_Model");
            floorModelViewParam = GLES20.GlGetUniformLocation (floorProgram, "u_MVMatrix");
            floorModelViewProjectionParam = GLES20.GlGetUniformLocation (floorProgram, "u_MVP");
            floorLightPosParam = GLES20.GlGetUniformLocation (floorProgram, "u_LightPos");

            floorPositionParam = GLES20.GlGetAttribLocation (floorProgram, "a_Position");
            floorNormalParam = GLES20.GlGetAttribLocation (floorProgram, "a_Normal");
            floorColorParam = GLES20.GlGetAttribLocation (floorProgram, "a_Color");

            CheckGLError ("Floor program params");

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

            // Avoid any delays during start-up due to decoding of sound files.
            System.Threading.Tasks.Task.Run (() => {
                // Start spatial audio playback of SOUND_FILE at the model postion. The returned
                //soundId handle is stored and allows for repositioning the sound object whenever
                // the cube position changes.
                gvrAudioEngine.PreloadSoundFile (SOUND_FILE);
                soundId = gvrAudioEngine.CreateSoundObject (SOUND_FILE);
                gvrAudioEngine.SetSoundObjectPosition (
                    soundId, modelPosition [0], modelPosition [1], modelPosition [2]);
                gvrAudioEngine.PlaySound (soundId, true /* looped playback */);
            });

            UpdateModelPosition ();

            CheckGLError ("onSurfaceCreated");
        }