public void OnDrawFrame(Javax.Microedition.Khronos.Opengles.IGL10 gl)
        {
            // Draw background color
            GLES30.GlClear((int)GLES30.GlColorBufferBit);

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

            // Calculate the projection and view transformation
            Matrix.MultiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);

            // Draw square
            mSquare.Draw(mMVPMatrix);

            // Create a rotation for the triangle
            // long time = SystemClock.UptimeMillis() % 4000L;
            // float angle = 0.090f * ((int) time);
            Matrix.SetRotateM(mRotationMatrix, 0, Angle, 0, 0, -1.0f);

            // Combine the rotation matrix with the projection and camera view
            Matrix.MultiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);

            // Draw triangle
            mTriangle.Draw(mMVPMatrix);
        }
		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
		}
Exemple #3
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(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
        }
        public void OnSurfaceCreated(Javax.Microedition.Khronos.Opengles.IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            // Set the background frame color
            GLES30.GlClearColor(0.0f, 0.0f, 0.0f, 1.0f);

            mTriangle = new Triangle();
            mSquare   = new Square();
        }
        /**
         * Utility method for debugging OpenGL calls. Provide the name of the call
         * just after making it:
         *
         * <pre>
         * mColorHandle = GLES30.glGetUniformLocation(mProgram, "vColor");
         * MyGLRenderer.checkGlError("glGetUniformLocation");</pre>
         *
         * If the operation is not successful, the check throws an error.
         *
         * @param glOperation - Name of the OpenGL call to check.
         */
        public static void CheckGlError(string glOperation)
        {
            int error;

            while ((error = GLES30.GlGetError()) != GLES30.GlNoError)
            {
                Log.Error(TAG, glOperation + ": glError " + error);
                throw new RuntimeException(glOperation + ": glError " + error);
            }
        }
        public static int LoadShader(int type, string shaderCode)
        {
            // create a vertex shader type (GLES30.GL_VERTEX_SHADER)
            // or a fragment shader type (GLES30.GL_FRAGMENT_SHADER)
            int shader = GLES30.GlCreateShader(type);

            // add the source code to the shader and compile it
            GLES30.GlShaderSource(shader, shaderCode);
            GLES30.GlCompileShader(shader);

            return(shader);
        }
        public void OnSurfaceChanged(Javax.Microedition.Khronos.Opengles.IGL10 gl, int width, int height)
        {
            // Adjust the viewport based on geometry changes,
            // such as screen rotation
            GLES30.GlViewport(0, 0, width, height);

            float ratio = (float)width / height;

            // this projection matrix is applied to object coordinates
            // in the onDrawFrame() method
            Matrix.FrustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7);
        }
Exemple #8
0
        //
        // FNA3D_GetMaxMultiSampleCount
        //

        public static int FNA3D_GetMaxMultiSampleCount(IntPtr device, SurfaceFormat format,
                                                       int preferredMultiSampleCount)
        {
            return(0);

            #if false
            for (int i = 0; i < 21; i++)
            {
                GLES30.glGetInternalformativ(GLES20.GL_RENDERBUFFER,
                                             SurfaceFormatToTextureInternalFormat[i],
                                             GLES20.GL_SAMPLES, 1, count, 0);
            }
            if (GLES20.glGetError() == 0 && count[0] < preferredMultiSampleCount)
            {
                preferredMultiSampleCount = count[0];
            }
            #endif
        }
Exemple #9
0
        public void Draw(float[] mvpMatrix)
        {
            // Add program to OpenGL environment
            GLES30.GlUseProgram(mProgram);

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

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

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

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

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

            // get handle to shape's transformation matrix
            mMVPMatrixHandle = GLES30.GlGetUniformLocation(mProgram, "uMVPMatrix");
            MyGLRenderer.CheckGlError("glGetUniformLocation");

            // Apply the projection and view transformation
            GLES30.GlUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
            MyGLRenderer.CheckGlError("glUniformMatrix4fv");

            // Draw the square
            GLES30.GlDrawElements(GLES30.GlTriangles, drawOrder.Length,
                                  GLES30.GlUnsignedShort, drawListBuffer);

            // Disable vertex array
            GLES30.GlDisableVertexAttribArray(mPositionHandle);
        }
Exemple #10
0
        //
        // FNA3D_DrawIndexedPrimitives
        //

        public static void FNA3D_DrawIndexedPrimitives(IntPtr device, PrimitiveType primitiveType,
                                                       int baseVertex, int minVertexIndex,
                                                       int numVertices, int startIndex,
                                                       int primitiveCount, IntPtr indices,
                                                       IndexElementSize indexElementSize)
        {
            int elementSize, elementType;

            if (indexElementSize == IndexElementSize.SixteenBits)
            {
                elementSize = 2;
                elementType = GLES20.GL_UNSIGNED_SHORT;
            }
            else if (indexElementSize == IndexElementSize.ThirtyTwoBits)
            {
                elementSize = 4;
                elementType = GLES20.GL_UNSIGNED_INT;
            }
            else
            {
                throw new ArgumentException("invalid IndexElementSize");
            }

            int drawMode       = PrimitiveTypeToDrawMode[(int)primitiveType];
            int maxVertexIndex = minVertexIndex + numVertices - 1;
            int indexOffset    = startIndex * elementSize;

            primitiveCount = PrimitiveCount(primitiveType, primitiveCount);

            Renderer.Get(device).Send(false, () =>
            {
                GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, (int)indices);
                GLES30.glDrawRangeElements(drawMode, minVertexIndex, maxVertexIndex,
                                           primitiveCount, elementType, indexOffset);
            });
        }