/**
         * Draw the cube.
         * We've set all of our transformation matrices. Now we simply pass them into the shader.
         */
        public void DrawCube()
        {
            GLES20.GlUseProgram(cubeProgram);

            GLES20.GlUniform3fv(cubeLightPosParam, 1, lightPosInEyeSpace, 0);

            // Set the Model in the shader, used to calculate lighting
            GLES20.GlUniformMatrix4fv(cubeModelParam, 1, false, modelCube, 0);

            // Set the ModelView in the shader, used to calculate lighting
            GLES20.GlUniformMatrix4fv(cubeModelViewParam, 1, false, modelView, 0);

            // Set the position of the cube
            GLES20.GlVertexAttribPointer(
                cubePositionParam, COORDS_PER_VERTEX, GLES20.GlFloat, false, 0, cubeVertices);

            // Set the ModelViewProjection matrix in the shader.
            GLES20.GlUniformMatrix4fv(cubeModelViewProjectionParam, 1, false, modelViewProjection, 0);

            // Set the normal positions of the cube, again for shading
            GLES20.GlVertexAttribPointer(cubeNormalParam, 3, GLES20.GlFloat, false, 0, cubeNormals);
            GLES20.GlVertexAttribPointer(cubeColorParam, 4, GLES20.GlFloat, false, 0,
                                         IsLookingAtObject() ? cubeFoundColors : cubeColors);

            // Enable vertex arrays
            GLES20.GlEnableVertexAttribArray(cubePositionParam);
            GLES20.GlEnableVertexAttribArray(cubeNormalParam);
            GLES20.GlEnableVertexAttribArray(cubeColorParam);

            GLES20.GlDrawArrays(GLES20.GlTriangles, 0, 36);
            CheckGLError("Drawing cube");
        }
Пример #2
0
        public void Draw()
        {
            // Add program to OpenGL environment
            GLES20.GlUseProgram(mProgram);

            // get handle to vertex shader's vPosition member
            mPositionHandle = GLES20.GlGetAttribLocation(mProgram, "vPosition");

            // Enable a handle to the triangle vertices
            GLES20.GlEnableVertexAttribArray(mPositionHandle);

            // Prepare the triangle coordinate data
            GLES20.GlVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,
                                         GLES20.GL_FLOAT, false,
                                         vertexStride, vertexBuffer);

            // get handle to fragment shader's vColor member
            mColorHandle = GLES20.GlGetUniformLocation(mProgram, "vColor");

            // Set color for drawing the triangle
            GLES20.GlUniform4fv(mColorHandle, 1, color, 0);

            // Draw the triangle
            GLES20.GlDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);

            // Disable vertex array
            GLES20.GlDisableVertexAttribArray(mPositionHandle);
        }
        /// <summary>
        /// Render the hand bounding box.
        /// </summary>
        private void DrawHandBox()
        {
            ShaderUtil.CheckGlError(TAG, "Draw hand box start.");
            GLES20.GlUseProgram(mProgram);
            GLES20.GlEnableVertexAttribArray(mPosition);
            GLES20.GlEnableVertexAttribArray(mColor);
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVbo);
            GLES20.GlVertexAttribPointer(
                mPosition, COORDINATE_DIMENSION, GLES20.GlFloat, false, BYTES_PER_POINT, 0);
            GLES20.GlUniform4f(mColor, 1.0f, 0.0f, 0.0f, 1.0f);

            GLES20.GlUniformMatrix4fv(mModelViewProjectionMatrix, 1, false, mMVPMatrix, 0);

            // Set the size of the rendering vertex.
            GLES20.GlUniform1f(mPointSize, 50.0f);

            // Set the width of a rendering stroke.
            GLES20.GlLineWidth(18.0f);
            GLES20.GlDrawArrays(GLES20.GlLineLoop, 0, mNumPoints);
            GLES20.GlDisableVertexAttribArray(mPosition);
            GLES20.GlDisableVertexAttribArray(mColor);
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0);

            ShaderUtil.CheckGlError(TAG, "Draw hand box end.");
        }
Пример #4
0
        /// <summary>
        /// Draw hand skeleton connection line.
        /// </summary>
        /// <param name="projectionMatrix">Projection matrix(4 * 4).</param>
        private void DrawHandSkeletonLine(float[] projectionMatrix)
        {
            ShaderUtil.CheckGlError(TAG, "Draw hand skeleton line start.");
            GLES20.GlUseProgram(mProgram);
            GLES20.GlEnableVertexAttribArray(mPosition);
            GLES20.GlEnableVertexAttribArray(mColor);
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVbo);

            // Set the width of the drawn line
            GLES20.GlLineWidth(18.0f);

            // Represented each point by 4D coordinates in the shader.
            GLES20.GlVertexAttribPointer(
                mPosition, 4, GLES20.GlFloat, false, BYTES_PER_POINT, 0);
            GLES20.GlUniform4f(mColor, 0.0f, 0.0f, 0.0f, 1.0f);
            GLES20.GlUniformMatrix4fv(mModelViewProjectionMatrix, 1, false, projectionMatrix, 0);

            GLES20.GlUniform1f(mPointSize, JOINT_POINT_SIZE);

            GLES20.GlDrawArrays(GLES20.GlLines, 0, mPointsNum);
            GLES20.GlDisableVertexAttribArray(mPosition);
            GLES20.GlDisableVertexAttribArray(mColor);
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0);

            ShaderUtil.CheckGlError(TAG, "Draw hand skeleton line end.");
        }
 /**
  * Renders fill screen quad using given GLES id/name.
  */
 private void renderQuad(int aPosition)
 {
     GLES20.GlVertexAttribPointer(aPosition, 2, GLES20.GlFloat, false, 0,
                                  _fullQuadVertices);
     GLES20.GlEnableVertexAttribArray(aPosition);
     GLES20.GlDrawArrays(GLES20.GlTriangleStrip, 0, 4);
 }
        private void DrawSkeletonLine(float coordinate, float[] projectionMatrix)
        {
            ShaderUtil.CheckGlError(TAG, "Draw skeleton line start.");
            GLES20.GlUseProgram(mProgram);
            GLES20.GlEnableVertexAttribArray(mPosition);
            GLES20.GlEnableVertexAttribArray(mColor);
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVbo);

            // Set the width of the rendered skeleton line.
            GLES20.GlLineWidth(18.0f);

            // The size of the vertex attribute is 4, and each vertex has four coordinate components.
            GLES20.GlVertexAttribPointer(
                mPosition, 4, GLES20.GlFloat, false, BYTES_PER_POINT, 0);
            GLES20.GlUniform4f(mColor, 1.0f, 0.0f, 0.0f, 1.0f);
            GLES20.GlUniformMatrix4fv(mProjectionMatrix, 1, false, projectionMatrix, 0);

            // Set the size of the points.
            GLES20.GlUniform1f(mPointSize, 100.0f);
            GLES20.GlUniform1f(mCoordinateSystem, coordinate);

            GLES20.GlDrawArrays(GLES20.GlLines, 0, mNumPoints);
            GLES20.GlDisableVertexAttribArray(mPosition);
            GLES20.GlDisableVertexAttribArray(mColor);
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0);

            ShaderUtil.CheckGlError(TAG, "Draw skeleton line end.");
        }
Пример #7
0
        /**
         * Renders the point cloud.
         *
         * @param pose the current point cloud pose, from {@link Frame#getPointCloudPose()}.
         * @param cameraView the camera view matrix for this frame, typically from
         *     {@link Frame#getViewMatrix(float[], int)}.
         * @param cameraPerspective the camera projection matrix for this frame, typically from
         *     {@link Session#getProjectionMatrix(float[], int, float, float)}.
         */
        public void Draw(Pose pose, float[] cameraView, float[] cameraPerspective)
        {
            float[] modelMatrix = new float[16];
            pose.ToMatrix(modelMatrix, 0);

            float[] modelView           = new float[16];
            float[] modelViewProjection = new float[16];
            Matrix.MultiplyMM(modelView, 0, cameraView, 0, modelMatrix, 0);
            Matrix.MultiplyMM(modelViewProjection, 0, cameraPerspective, 0, modelView, 0);

            ShaderUtil.CheckGLError(TAG, "Before draw");

            GLES20.GlUseProgram(mProgramName);
            GLES20.GlEnableVertexAttribArray(mPositionAttribute);
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVbo);
            GLES20.GlVertexAttribPointer(
                mPositionAttribute, 4, GLES20.GlFloat, false, BYTES_PER_POINT, 0);
            GLES20.GlUniform4f(mColorUniform, 31.0f / 255.0f, 188.0f / 255.0f, 210.0f / 255.0f, 1.0f);
            GLES20.GlUniformMatrix4fv(mModelViewProjectionUniform, 1, false, modelViewProjection, 0);
            GLES20.GlUniform1f(mPointSizeUniform, 5.0f);

            GLES20.GlDrawArrays(GLES20.GlPoints, 0, mNumPoints);
            GLES20.GlDisableVertexAttribArray(mPositionAttribute);
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0);

            ShaderUtil.CheckGLError(TAG, "Draw");
        }
Пример #8
0
        public void Draw(Frame frame)
        {
            if (frame.HasDisplayGeometryChanged)//.IsDisplayRotationChanged)
            {
                frame.TransformDisplayUvCoords(mQuadTexCoord, mQuadTexCoordTransformed);
            }

            GLES20.GlDisable(GLES20.GlDepthTest);
            GLES20.GlDepthMask(false);

            GLES20.GlBindTexture(GLES11Ext.GlTextureExternalOes, TextureId);

            GLES20.GlUseProgram(mQuadProgram);

            GLES20.GlVertexAttribPointer(
                mQuadPositionParam, COORDS_PER_VERTEX, GLES20.GlFloat, false, 0, mQuadVertices);

            GLES20.GlVertexAttribPointer(mQuadTexCoordParam, TEXCOORDS_PER_VERTEX,
                                         GLES20.GlFloat, false, 0, mQuadTexCoordTransformed);

            GLES20.GlEnableVertexAttribArray(mQuadPositionParam);
            GLES20.GlEnableVertexAttribArray(mQuadTexCoordParam);

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

            // Disable vertex arrays
            GLES20.GlDisableVertexAttribArray(mQuadPositionParam);
            GLES20.GlDisableVertexAttribArray(mQuadTexCoordParam);

            // Restore the depth state for further drawing.
            GLES20.GlDepthMask(true);
            GLES20.GlEnable(GLES20.GlDepthTest);

            ShaderUtil.CheckGLError(TAG, "Draw");
        }
Пример #9
0
        public virtual void draw()
        {
            try
            {
                //  if (levelScale) Matrix.ScaleM(mModelMatrix, 0, GlobalVar.levelScale, GlobalVar.levelScale, GlobalVar.levelScale);

                ShaderCompiller shader = ShaderManager.getShader(shaderName);

                GLES20.GlUseProgram(shader.program);


                int size = 4; // data count 2 for vec2 4 for vec4
                int b    = 0;
                int c    = 0;

                GLES20.GlEnableVertexAttribArray(ShaderManager.getShader(shaderName).attrib_vertex);
                GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOManager.getVBO(fileName)[0]);
                GLES20.GlVertexAttribPointer(ShaderManager.getShader(shaderName).attrib_vertex, size, GLES20.GlFloat, false, b, c);

                GLES20.GlEnableVertexAttribArray(ShaderManager.getShader(shaderName).normal);
                GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOManager.getVBO(fileName)[2]);
                GLES20.GlVertexAttribPointer(ShaderManager.getShader(shaderName).normal, size, GLES20.GlFloat, false, b, c);

                GLES20.GlUniform3f(ShaderManager.getShader(shaderName).lightPos, render.eyeX, render.eyeY, render.eyeZ);

                GLES20.GlUniformMatrix4fv(ShaderManager.getShader(shaderName).mMVMatrixHandle, 1, false, render._mViewMatrix, 0); //MV Matrix
                                                                                                                                  //Matrix.SetIdentityM(mMVPMatrix, 0);
                float[] mModetView = new float[16];
                Matrix.MultiplyMM(mModetView, 0, render._mViewMatrix, 0, mModelMatrix, 0);

                Matrix.MultiplyMM(mMVPMatrix, 0, render.mProjectionMatrix, 0, mModetView, 0);
                GLES20.GlUniformMatrix4fv(ShaderManager.getShader(shaderName).mMVPMatrixHandle, 1, false, mMVPMatrix, 0); //MVP Matrix

                if (textureResID != -1)
                {
                    GLES20.GlEnableVertexAttribArray(ShaderManager.getShader(shaderName).mTextureCoordinateHandle);
                    GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOManager.getVBO(fileName)[1]);
                    int bsize = 2;
                    GLES20.GlVertexAttribPointer(ShaderManager.getShader(shaderName).mTextureCoordinateHandle, bsize, GLES20.GlFloat, false, b, c);

                    GLES20.GlActiveTexture(GLES20.GlTexture0);
                    GLES20.GlBindTexture(GLES20.GlTexture2d, TextureManager.getTextureHandle(context, textureResID));
                    GLES20.GlUniform1i(ShaderManager.getShader(shaderName).mTextureUniformHandle, 0);


                    GLES20.GlActiveTexture(GLES20.GlTexture1);
                    GLES20.GlBindTexture(GLES20.GlTexture2d, TextureManager.getTextureHandle(context, texture2ResID));
                    GLES20.GlUniform1i(ShaderManager.getShader(shaderName).mTextureUniformHandleF, 1);

                    GLES20.GlActiveTexture(GLES20.GlTexture2);
                    GLES20.GlBindTexture(GLES20.GlTexture2d, TextureManager.getTextureHandle(context, texture3ResID));
                    GLES20.GlUniform1i(ShaderManager.getShader(shaderName).mTextureUniformHandleS, 2);
                }

                GLES20.GlDrawArrays(GLES20.GlTriangles, 0, VBOManager.getSize(fileName));

                GLES20.GlUseProgram(0);
            }
            catch { }
        }
Пример #10
0
        public void OnDrawFrame(Javax.Microedition.Khronos.Opengles.IGL10 gl)
        {
            float[] scratch = new float[16];

            // Draw background color
            GLES20.GlClear(GLES20.GlColorBufferBit);

            //synchronized (this) {
            if (mUpdateST)
            {
                mSTexture.UpdateTexImage();
                mUpdateST = false;
            }
            //}

            GLES20.GlUseProgram(hProgram);

            int ph  = GLES20.GlGetAttribLocation(hProgram, "vPosition");
            int tch = GLES20.GlGetAttribLocation(hProgram, "vTexCoord");
            int th  = GLES20.GlGetUniformLocation(hProgram, "sTexture");

            GLES20.GlActiveTexture(GLES20.GlTexture0);
            GLES20.GlBindTexture(GLES11Ext.GlTextureExternalOes, hTex[0]);
            GLES20.GlUniform1i(th, 0);

            GLES20.GlVertexAttribPointer(ph, 2, GLES20.GlFloat, false, 4 * 2, pVertex);
            GLES20.GlVertexAttribPointer(tch, 2, GLES20.GlFloat, false, 4 * 2, pTexCoord);
            GLES20.GlEnableVertexAttribArray(ph);
            GLES20.GlEnableVertexAttribArray(tch);

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


            // Set the camera position (View matrix)
            Android.Opengl.Matrix.SetLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

            // Calculate the projection and view transformation
            Android.Opengl.Matrix.MultiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);


            // Create a rotation for the triangle

            // Use the following code to generate constant rotation.
            // Leave this code out when using TouchEvents.
            // long time = SystemClock.uptimeMillis() % 4000L;
            // float angle = 0.090f * ((int) time);

            Android.Opengl.Matrix.SetRotateM(mRotationMatrix, 0, mAngle, 0, 0, 1.0f);

            // Combine the rotation matrix with the projection and camera view
            // Note that the mMVPMatrix factor *must be first* in order
            // for the matrix multiplication product to be correct.
            Android.Opengl.Matrix.MultiplyMM(scratch, 0, mMVPMatrix, 0, mRotationMatrix, 0);

            // Draw triangle
            mTriangle.draw(scratch);
        }
Пример #11
0
        public void OnDrawFrame(IGL10 gl)
        {
            GLES20.GlClear(GLES20.GlColorBufferBit | GLES20.GlDepthBufferBit);

            // Draw the triangle facing straight on.
            angleInDegrees += 0.2f;
            //Prepare model transformation matrix
            float[] mModelMatrix = new float[16];
            Matrix.SetIdentityM(mModelMatrix, 0);
            Matrix.RotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);

            //Draw with VBO
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOBuffers[0]);
            GLES20.GlEnableVertexAttribArray(mPositionHandle);
            GLES20.GlVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GlFloat, false, 0, 0);

            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOBuffers[1]);
            GLES20.GlEnableVertexAttribArray(mColorHandle);
            GLES20.GlVertexAttribPointer(mColorHandle, mColorDataSize, GLES20.GlFloat, false, 0, 0);

            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOBuffers[2]);
            GLES20.GlEnableVertexAttribArray(mTextureCoordHandle);
            GLES20.GlVertexAttribPointer(mTextureCoordHandle, 2, GLES20.GlFloat, false, 0, 0);

            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOBuffers[3]);
            GLES20.GlEnableVertexAttribArray(mNormalHandle);
            GLES20.GlVertexAttribPointer(mNormalHandle, 3, GLES20.GlFloat, false, 0, 0);

            GLES20.GlActiveTexture(GLES20.GlTexture0);
            GLES20.GlBindTexture(GLES20.GlTexture2d, textureHandle[0]);
            GLES20.GlUniform1i(mTextureHandle, 0);

            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0);
            //END OF Draw with VBO

            //light position
            // GLES20.GlUniform3f(mLightPos, 0.0f, 0.0f, angleInDegrees);
            GLES20.GlUniform3f(mLightPos, 0.0f, 0.0f, 0.0f);

            // 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 * 12); //Cube has 12 triagle faces each face has 3 coord
        }
Пример #12
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);
                }
            }
        }
        /// <summary>
        /// Draw face geometrical features. This method is called on each frame.
        /// </summary>
        private void DrawFaceGeometry()
        {
            ShaderUtil.CheckGlError(TAG, "Before draw.");
            Log.Debug(TAG, "Draw face geometry: mPointsNum: " + mPointsNum + " mTrianglesNum: " + mTrianglesNum);

            GLES20.GlActiveTexture(GLES20.GlTexture0);
            GLES20.GlBindTexture(GLES20.GlTexture2d, mTextureName);
            GLES20.GlUniform1i(mTextureUniform, 0);
            ShaderUtil.CheckGlError(TAG, "Init texture.");

            GLES20.GlEnable(GLES20.GlDepthTest);
            GLES20.GlEnable(GL_CULL_FACE_CONSTANT);

            // Draw point.
            GLES20.GlUseProgram(mProgram);
            ShaderUtil.CheckGlError(TAG, "Draw point.");
            GLES20.GlEnableVertexAttribArray(mPositionAttribute);
            GLES20.GlEnableVertexAttribArray(mTextureCoordAttribute);
            GLES20.GlEnableVertexAttribArray(mColorUniform);
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVerticeId);
            GLES20.GlVertexAttribPointer(mPositionAttribute, POSITION_COMPONENTS_NUMBER, GLES20.GlFloat, false,
                                         BYTES_PER_POINT, 0);
            GLES20.GlVertexAttribPointer(mTextureCoordAttribute, TEXCOORD_COMPONENTS_NUMBER, GLES20.GlFloat, false,
                                         BYTES_PER_COORD, 0);
            GLES20.GlUniform4f(mColorUniform, 1.0f, 0.0f, 0.0f, 1.0f);
            GLES20.GlUniformMatrix4fv(mModelViewProjectionUniform, 1, false, mModelViewProjections, 0);
            GLES20.GlUniform1f(mPointSizeUniform, 5.0f); // Set the size of Point to 5.
            GLES20.GlDrawArrays(GLES20.GlPoints, 0, mPointsNum);
            GLES20.GlDisableVertexAttribArray(mColorUniform);
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0);
            ShaderUtil.CheckGlError(TAG, "Draw point.");

            // Draw triangles.
            GLES20.GlEnableVertexAttribArray(mColorUniform);

            // Clear the color and use the texture color to draw triangles.
            GLES20.GlUniform4f(mColorUniform, 0.0f, 0.0f, 0.0f, 0.0f);
            GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, mTriangleId);

            // The number of input triangle points
            GLES20.GlDrawElements(GLES20.GlTriangles, mTrianglesNum * 3, GLES20.GlUnsignedInt, 0);
            GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, 0);
            GLES20.GlDisableVertexAttribArray(mColorUniform);
            ShaderUtil.CheckGlError(TAG, "Draw triangles.");

            GLES20.GlDisableVertexAttribArray(mTextureCoordAttribute);
            GLES20.GlDisableVertexAttribArray(mPositionAttribute);
            GLES20.GlBindTexture(GLES20.GlTexture2d, 0);

            GLES20.GlDisable(GLES20.GlDepthTest);
            GLES20.GlDisable(GL_CULL_FACE_CONSTANT);
            ShaderUtil.CheckGlError(TAG, "Draw after.");
        }
Пример #14
0
        // Draw |textures| using |vertices| (X,Y coordinates).
        private void drawRectangle(int[] textures, FloatBuffer vertices)
        {
            for (int i = 0; i < 3; ++i)
            {
                GLES20.GlActiveTexture(GLES20.GlTexture0 + i);
                GLES20.GlBindTexture(GLES20.GlTexture2d, textures[i]);
            }

            GLES20.GlVertexAttribPointer(posLocation, 2, GLES20.GlFloat, false, 0, vertices);
            GLES20.GlEnableVertexAttribArray(posLocation);

            GLES20.GlDrawArrays(GLES20.GlTriangleStrip, 0, 4);
            checkNoGLES2Error();
        }
Пример #15
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();
            }
Пример #16
0
        /**
         * Draws the AR background image.  The image will be drawn such that virtual content rendered
         * with the matrices provided by {@link Frame#getViewMatrix(float[], int)} and
         * {@link Session#getProjectionMatrix(float[], int, float, float)} will accurately follow
         * static physical objects.  This must be called <b>before</b> drawing virtual content.
         *
         * @param frame The last {@code Frame} returned by {@link Session#update()}.
         */
        public void Draw(Frame frame)
        {
            // If display rotation changed (also includes view size change), we need to re-query the uv
            // coordinates for the screen rect, as they may have changed as well.
            if (frame.HasDisplayGeometryChanged)
            {
                frame.TransformDisplayUvCoords(mQuadTexCoord, mQuadTexCoordTransformed);
            }

            // No need to test or write depth, the screen quad has arbitrary depth, and is expected
            // to be drawn first.
            GLES20.GlDisable(GLES20.GlDepthTest);
            GLES20.GlDepthMask(false);

            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);

            GLES20.GlUseProgram(mQuadProgram);

            // Set the vertex positions.
            GLES20.GlVertexAttribPointer(
                mQuadPositionParam, COORDS_PER_VERTEX, GLES20.GlFloat, false, 0, mQuadVertices);

            // Set the texture coordinates.
            GLES20.GlVertexAttribPointer(mQuadTexCoordParam, TEXCOORDS_PER_VERTEX,
                                         GLES20.GlFloat, false, 0, mQuadTexCoordTransformed);

            // Enable vertex arrays
            GLES20.GlEnableVertexAttribArray(mQuadPositionParam);
            GLES20.GlEnableVertexAttribArray(mQuadTexCoordParam);

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

            // Disable vertex arrays
            GLES20.GlDisableVertexAttribArray(mQuadPositionParam);
            GLES20.GlDisableVertexAttribArray(mQuadTexCoordParam);

            // Restore the depth state for further drawing.
            GLES20.GlDepthMask(true);
            GLES20.GlEnable(GLES20.GlDepthTest);



            ShaderUtil.CheckGLError(TAG, "Draw");
        }
Пример #17
0
        public void DrawFloor(float[] perspective)
        {
            // This is the floor!
            GLES20.GlUniform1f(isFloorParam, 1f);

            // Set ModelView, MVP, position, normals, and color
            GLES20.GlUniformMatrix4fv(modelParam, 1, false, modelFloor, 0);
            GLES20.GlUniformMatrix4fv(modelViewParam, 1, false, modelView, 0);
            GLES20.GlUniformMatrix4fv(modelViewProjectionParam, 1, false, modelViewProjection, 0);
            GLES20.GlVertexAttribPointer(positionParam, CoordsPerVertex, GLES20.GlFloat,
                                         false, 0, floorVertices);
            GLES20.GlVertexAttribPointer(normalParam, 3, GLES20.GlFloat, false, 0, floorNormals);
            GLES20.GlVertexAttribPointer(colorParam, 4, GLES20.GlFloat, false, 0, floorColors);
            GLES20.GlDrawArrays(GLES20.GlTriangles, 0, 6);

            CheckGlError("drawing floor");
        }
Пример #18
0
        public void DrawCube()
        {
            // This is not the floor!
            GLES20.GlUniform1f(isFloorParam, 0f);

            // Set the Model in the shader, used to calculate lighting
            GLES20.GlUniformMatrix4fv(modelParam, 1, false, modelCube, 0);

            // Set the ModelView in the shader, used to calculate lighting
            GLES20.GlUniformMatrix4fv(modelViewParam, 1, false, modelView, 0);

            // Set the position of the cube
            GLES20.GlVertexAttribPointer(positionParam, CoordsPerVertex, GLES20.GlFloat,
                                         false, 0, cubeVertices);

            // Set the ModelViewProjection matrix in the shader.
            GLES20.GlUniformMatrix4fv(modelViewProjectionParam, 1, false, modelViewProjection, 0);

            // Set the normal positions of the cube, again for shading
            GLES20.GlVertexAttribPointer(normalParam, 3, GLES20.GlFloat,
                                         false, 0, cubeNormals);

            // Set the texture coordinates
            GLES20.GlVertexAttribPointer(texCoordParam, 2, GLES20.GlFloat, false, 0, cubeTextureCoords);

            GLES20.GlActiveTexture(GLES20.GlTexture0);

            if (IsLookingAtObject)
            {
                GLES20.GlVertexAttribPointer(colorParam, 4, GLES20.GlFloat, false,
                                             0, cubeFoundColors);
                GLES20.GlBindTexture(GLES20.GlTexture2d, monkeyFound);
            }
            else
            {
                GLES20.GlVertexAttribPointer(colorParam, 4, GLES20.GlFloat, false,
                                             0, cubeColors);
                GLES20.GlBindTexture(GLES20.GlTexture2d, monkeyNotFound);
            }

            GLES20.GlUniform1i(texture, 0);

            GLES20.GlDrawArrays(GLES20.GlTriangles, 0, 36);
            CheckGlError("Drawing cube");
        }
        /// <summary>
        /// Render each frame.
        /// This method is called when Android.Opengl.GLSurfaceView.IRenderer's OnDrawFrame.
        /// </summary>
        /// <param name="frame">ARFrame</param>
        public void OnDrawFrame(ARFrame frame)
        {
            ShaderUtil.CheckGlError(TAG, "On draw frame start.");
            if (frame == null)
            {
                return;
            }
            if (frame.HasDisplayGeometryChanged)
            {
                frame.TransformDisplayUvCoords(mTexBuffer, mTexTransformedBuffer);
            }
            Clear();

            GLES20.GlDisable(GLES20.GlDepthTest);
            GLES20.GlDepthMask(false);

            GLES20.GlUseProgram(mProgram);

            // Set the texture ID.
            GLES20.GlBindTexture(GLES11Ext.GlTextureExternalOes, mExternalTextureId);

            // Set the projection matrix.
            GLES20.GlUniformMatrix4fv(mMatrix, 1, false, mProjectionMatrix, 0);

            GLES20.GlUniformMatrix4fv(mCoordMatrix, 1, false, coordMatrixs, 0);

            // Set the vertex.
            GLES20.GlEnableVertexAttribArray(mPosition);
            GLES20.GlVertexAttribPointer(mPosition, 2, GLES20.GlFloat, false, 0, mVerBuffer);

            // Set the texture coordinates.
            GLES20.GlEnableVertexAttribArray(mCoord);
            GLES20.GlVertexAttribPointer(mCoord, 2, GLES20.GlFloat, false, 0, mTexTransformedBuffer);

            // Number of vertices.
            GLES20.GlDrawArrays(GLES20.GlTriangleStrip, 0, 4);
            GLES20.GlDisableVertexAttribArray(mPosition);
            GLES20.GlDisableVertexAttribArray(mCoord);

            GLES20.GlDepthMask(true);
            GLES20.GlEnable(GLES20.GlDepthTest);
            ShaderUtil.CheckGlError(TAG, "On draw frame end.");
        }
Пример #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);
            }
        }
Пример #22
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);
        }
        /**
         * Draw the floor.
         * This feeds in data for the floor into the shader. Note that this doesn't feed in data about
         * position of the light, so if we rewrite our code to draw the floor first, the lighting might
         * look strange.
         */
        public void DrawFloor()
        {
            GLES20.GlUseProgram(floorProgram);

            // Set ModelView, MVP, position, normals, and color.
            GLES20.GlUniform3fv(floorLightPosParam, 1, lightPosInEyeSpace, 0);
            GLES20.GlUniformMatrix4fv(floorModelParam, 1, false, modelFloor, 0);
            GLES20.GlUniformMatrix4fv(floorModelViewParam, 1, false, modelView, 0);
            GLES20.GlUniformMatrix4fv(floorModelViewProjectionParam, 1, false, modelViewProjection, 0);
            GLES20.GlVertexAttribPointer(
                floorPositionParam, COORDS_PER_VERTEX, GLES20.GlFloat, false, 0, floorVertices);
            GLES20.GlVertexAttribPointer(floorNormalParam, 3, GLES20.GlFloat, false, 0, floorNormals);
            GLES20.GlVertexAttribPointer(floorColorParam, 4, GLES20.GlFloat, false, 0, floorColors);

            GLES20.GlEnableVertexAttribArray(floorPositionParam);
            GLES20.GlEnableVertexAttribArray(floorNormalParam);
            GLES20.GlEnableVertexAttribArray(floorColorParam);

            GLES20.GlDrawArrays(GLES20.GlTriangles, 0, 24);

            CheckGLError("drawing floor");
        }
Пример #24
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);

            mMVPMatrixHandle = GLES20.GlGetUniformLocation(mProgram, "uMVPMatrix");
            GLES20.GlUniformMatrix4fv(mMVPMatrixHandle, 1, false, MvpMatrix, 0);

            mColorHandle = GLES20.GlGetUniformLocation(mProgram, "aColor");
            GLES20.GlUniform4f(mColorHandle, mColor[0], mColor[1], mColor[2], mColor[3]);
            GLES20.GlLineWidth(mLineWidth);
            GLES20.GlDrawArrays(GLES20.GlLineStrip, 0, mTrajectoryCount);
        }
Пример #25
0
        /**
         * Encapsulates the OpenGL ES instructions for drawing this shape.
         *
         * @param mvpMatrix - The Model View Project matrix in which to draw
         * this shape.
         */
        public void draw(float[] mvpMatrix)
        {
            // Add program to OpenGL environment
            GLES20.GlUseProgram(mProgram);

            // get handle to vertex shader's vPosition member
            mPositionHandle = GLES20.GlGetAttribLocation(mProgram, "vPosition");

            // Enable a handle to the triangle vertices
            GLES20.GlEnableVertexAttribArray(mPositionHandle);

            // Prepare the triangle coordinate data
            GLES20.GlVertexAttribPointer(
                mPositionHandle, COORDS_PER_VERTEX,
                GLES20.GlFloat, false,
                vertexStride, vertexBuffer);

            // get handle to fragment shader's vColor member
            mColorHandle = GLES20.GlGetUniformLocation(mProgram, "vColor");

            // Set color for drawing the triangle
            GLES20.GlUniform4fv(mColorHandle, 1, color, 0);

            // get handle to shape's transformation matrix
            mMVPMatrixHandle = GLES20.GlGetUniformLocation(mProgram, "uMVPMatrix");
            MainRenderer.checkGlError("glGetUniformLocation");

            // Apply the projection and view transformation
            GLES20.GlUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
            MainRenderer.checkGlError("glUniformMatrix4fv");

            // Draw the triangle
            GLES20.GlDrawArrays(GLES20.GlTriangles, 0, vertexCount);

            // Disable vertex array
            GLES20.GlDisableVertexAttribArray(mPositionHandle);
        }
        /// <summary>
        /// Draw hand skeleton points.
        /// </summary>
        /// <param name="projectionMatrix">Projection matrix.</param>
        private void DrawHandSkeletons(float[] projectionMatrix)
        {
            ShaderUtil.CheckGlError(TAG, "Draw hand skeletons start.");
            GLES20.GlUseProgram(mProgram);
            GLES20.GlEnableVertexAttribArray(mPosition);
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVbo);

            // The size of the vertex attribute is 4, and each vertex has four coordinate components
            GLES20.GlVertexAttribPointer(
                mPosition, 4, GLES20.GlFloat, false, BYTES_PER_POINT, 0);

            // Set the color of the skeleton points to blue.
            GLES20.GlUniform4f(mColor, 0.0f, 0.0f, 1.0f, 1.0f);
            GLES20.GlUniformMatrix4fv(mModelViewProjectionMatrix, 1, false, projectionMatrix, 0);

            // Set the size of the skeleton points.
            GLES20.GlUniform1f(mPointSize, 30.0f);

            GLES20.GlDrawArrays(GLES20.GlPoints, 0, mNumPoints);
            GLES20.GlDisableVertexAttribArray(mPosition);
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0);

            ShaderUtil.CheckGlError(TAG, "Draw hand skeletons end.");
        }
Пример #27
0
	public void drawFrame() {	
		checkGlError("onDrawFrame start");
		mSurfaceTexture.GetTransformMatrix(mSTMatrix);

		//GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
		//GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

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

		GLES20.GlActiveTexture(GLES20.GlTexture0);
		GLES20.GlBindTexture(GLES11Ext.GlTextureExternalOes, 0);
		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.GlFinish();
	}
Пример #28
0
        public void OnDrawFrame(IGL10 gl)
        {
            GLES20.GlClear(GLES20.GlColorBufferBit | GLES20.GlDepthBufferBit);

            // Pass in the edge 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];

            // This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix
            // (which now contains model * view * projection).
            float[] _mMVPMatrix = new float[16];

            //Model matrix
            float[] mModelMatrix = new float[16];

            //move world forward by z
            globalWorldPosition += 0.01f; //the number value is world move speed
            //if END OF THE WORLD - reset world Z move position to ZERO and relocate ALL trees (Matrix is HAPPY NOW)
            if (globalWorldPosition > worldSpace)
            {
                globalWorldPosition = 0; //reset world move forward to start
                InitTree();              //reset trees positions
            }

            //Enumerate and draw all trees
            for (int i = 0; i < treeCount; i++)
            {
                //Draw top of tree
                Matrix.SetIdentityM(mModelMatrix, 0);
                //translate top of tree to tree postion and move to global Z (world move) coord
                Matrix.TranslateM(mModelMatrix, 0, treePostions[i, 0], 0, globalWorldPosition + treePostions[i, 1]); //tree to X <-> Z world position
                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);

                //Draw middle of tree
                Matrix.SetIdentityM(mModelMatrix, 0);
                //translate by middle section of current tree and move down by Y
                Matrix.TranslateM(mModelMatrix, 0, treePostions[i, 0], -0.5f, globalWorldPosition + treePostions[i, 1]); //move tree with all world forward by Z
                //scale middle sction
                Matrix.ScaleM(mModelMatrix, 0, 1.5f, 1.5f, 1.5f);
                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);

                //Draw bottom section of tree
                Matrix.SetIdentityM(mModelMatrix, 0);
                //translate by buttom section of current tree and move down by Y
                Matrix.TranslateM(mModelMatrix, 0, treePostions[i, 0], -1.0f, globalWorldPosition + treePostions[i, 1]); //move tree with all world forward by Z
                //scal bottom section
                Matrix.ScaleM(mModelMatrix, 0, 1.8f, 1.8f, 1.8f);
                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);
                //-> Draw next tree -->
            }
        }
Пример #29
0
        public void OnDrawFrame(IGL10 gl)
        {
            GLES20.GlClear(GLES20.GlColorBufferBit | GLES20.GlDepthBufferBit);

            // Draw the triangle facing straight on.
            angleInDegrees  += 1.0f;
            angleInDegrees2 -= 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);
            //  Console.WriteLine(System.DateTime.Now.Ticks / System.TimeSpan.TicksPerMillisecond - milliseconds);


            if (kofi <= 0)
            {
            }
            else
            {
                kofi -= 0.001f;
            }



            Matrix.SetIdentityM(mModelMatrix, 0);
            Matrix.ScaleM(mModelMatrix, 0, 0.4f + kofi, 0.4f + kofi, 0.4f + kofi);
            Matrix.TranslateM(mModelMatrix, 0, 0.0f + kofi, 0.0f + kofi, 0.0f + kofi);
            Matrix.RotateM(mModelMatrix, 0, angleInDegrees2, 0, 0.0001F, 0);
            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);

            Matrix.SetIdentityM(mModelMatrix, 0);
            Matrix.ScaleM(mModelMatrix, 0, 0.4f - kofi, 0.4f - kofi, 0.4f - kofi);
            Matrix.TranslateM(mModelMatrix, 0, 0.0f - kofi, 0.0f - kofi, 0.0f - kofi);
            Matrix.RotateM(mModelMatrix, 0, angleInDegrees2 + 90, 0, 0.0001F, 0);
            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);



            Matrix.SetIdentityM(mModelMatrix, 0);
            Matrix.ScaleM(mModelMatrix, 0, 0.53f - kofi, 0.53f - kofi, 0.53f - kofi);
            Matrix.TranslateM(mModelMatrix, 0, 0.0f - kofi, -0.73f - kofi, 0.0f - kofi);
            Matrix.RotateM(mModelMatrix, 0, angleInDegrees, 0, 0.0001F, 0);
            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);


            Matrix.SetIdentityM(mModelMatrix, 0);
            Matrix.ScaleM(mModelMatrix, 0, 0.53f + kofi, 0.53f + kofi, 0.53f + kofi);
            Matrix.TranslateM(mModelMatrix, 0, 0.0f + kofi, -0.73f + kofi, 0.0f + kofi);
            Matrix.RotateM(mModelMatrix, 0, angleInDegrees + 90, 0, 0.0001F, 0);
            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);


            Matrix.SetIdentityM(mModelMatrix, 0);
            Matrix.ScaleM(mModelMatrix, 0, 0.66f + kofi, 0.66f + kofi, 0.66f + kofi);
            Matrix.TranslateM(mModelMatrix, 0, 0.0f + kofi, -1.32f + kofi, 0.0f + kofi);
            Matrix.RotateM(mModelMatrix, 0, angleInDegrees2, 0, 0.0001F, 0);
            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);

            Matrix.SetIdentityM(mModelMatrix, 0);
            Matrix.ScaleM(mModelMatrix, 0, 0.66f - kofi, 0.66f - kofi, 0.66f - kofi);
            Matrix.TranslateM(mModelMatrix, 0, 0.0f - kofi, -1.32f - kofi, 0.0f - kofi);
            Matrix.RotateM(mModelMatrix, 0, angleInDegrees2 + 90, 0, 0.0001F, 0);
            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);
        }
Пример #30
0
        /// <summary>
        /// This method is called from Renderer when OpenGL ready to draw scene
        /// The code of this method show "standard" OpenGL object drawing routine with using transformation matrix
        /// </summary>
        /// <param name="gl">IGL10 access object pointer from orign OpenGL.OnDraw(IGL10 gl)</param>
        /// <param name="mViewMatrix">Camere View matrix</param>
        /// <param name="mProjectionMatrix">Camera Projection matrix</param>
        public virtual void DrawFrame()
        {
            float[] mModelMatrix = new float[16];
            Matrix.SetIdentityM(mModelMatrix, 0);
            Matrix.ScaleM(mModelMatrix, 0, scale, scale, scale);
            Matrix.RotateM(mModelMatrix, 0, angleX, 1, ay, az);
            Matrix.RotateM(mModelMatrix, 0, angleY, ax, 1, az);
            Matrix.TranslateM(mModelMatrix, 0, x, y, z);

            // Tell OpenGL to use this program when rendering.

            GLES20.GlUseProgram(shader.programHandle);

            //Draw with VBO
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, vertexVBO.handle);
            GLES20.GlEnableVertexAttribArray(shader.mPositionHandle);
            GLES20.GlVertexAttribPointer(shader.mPositionHandle, mPositionDataSize, GLES20.GlFloat, false, 0, 0);

            if (textureVBO.handle != -1)
            {
                GLES20.GlBindBuffer(GLES20.GlArrayBuffer, textureVBO.handle);
                GLES20.GlEnableVertexAttribArray(shader.mTextureCoordHandle);
                GLES20.GlVertexAttribPointer(shader.mTextureCoordHandle, 2, GLES20.GlFloat, false, 0, 0);
            }

            if (normalVBO.handle != -1)
            {
                GLES20.GlBindBuffer(GLES20.GlArrayBuffer, normalVBO.handle);
                GLES20.GlEnableVertexAttribArray(shader.mNormalHandle);
                GLES20.GlVertexAttribPointer(shader.mNormalHandle, 3, GLES20.GlFloat, false, 0, 0);
            }

            if (texture.handle != -1)
            {
                GLES20.GlActiveTexture(GLES20.GlTexture0);
                GLES20.GlBindTexture(GLES20.GlTexture2d, texture.handle);
                GLES20.GlUniform1i(shader.mTextureHandle, 0);
            }

            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0);
            //END OF Draw with VBO

            //light position
            GLES20.GlUniform4f(shader.mLightPos, lx, ly, lz, lw);

            // 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, renderer.camera.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, renderer.camera.mProjectionMatrix, 0, mMVPMatrix, 0);

            GLES20.GlUniformMatrix4fv(shader.mMVPMatrixHandle, 1, false, _mMVPMatrix, 0);
            GLES20.GlDrawArrays(GLES20.GlTriangles, 0, vertexVBO.objectSize); //Cube has 12 triagle faces each face has 3 coord


            GLES20.GlUseProgram(0);
        }