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 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 ();
		}
Esempio n. 3
0
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            gl.GlClearColor(0.0f, 0.0f, 0.0f, 0.5f);

            gl.GlClearDepthf(1.0f);
            gl.GlEnable(IGL10Constants.GL_DEPTH_TEST);
            gl.GlDepthFunc(IGL10Constants.GL_LEQUAL);

            gl.GlHint(IGL10Constants.GL_PERSPECTIVE_CORRECTION_HINT,
                      IGL10Constants.GL_NICEST);
        }
		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);
		}
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            /*
             * By default, OpenGL enables features that improve quality
             * but reduce performance. One might want to tweak that
             * especially on software renderer.
             */
            gl.GlDisable (GL10.GlDither);

            /*
             * Some one-time OpenGL initialization can be made here
             * probably based on features of this particular context
             */
            gl.GlHint (GL10.GlPerspectiveCorrectionHint, GL10.GlFastest);

            if (mTranslucentBackground)
                gl.GlClearColor (0,0,0,0);
            else
                gl.GlClearColor (1,1,1,1);

            // FIXME: Mono.Android.dll misses this constant. Filed as #3531.
            gl.GlEnable(2884);//GL10.GlCullFace);
            gl.GlShadeModel(GL10.GlSmooth);
            gl.GlEnable(GL10.GlDepthTest);
        }
		public void OnSurfaceCreated (IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config) 
		{
			nativeInit (IntPtr.Zero);
		}
Esempio n. 7
0
 public Canvas(Javax.Microedition.Khronos.Opengles.IGL gl)
     : base(IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
 {
     throw new NotSupportedException ("The Canvas(Javax.Microedition.Khronos.Opengles.IGL) constructor is not supported on API-11+.");
 }
        /**
        * 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");
        }
        public void OnSurfaceCreated(Javax.Microedition.Khronos.Opengles.IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            // Set the background frame color
            GLES20.GlClearColor(0.0f, 0.0f, 0.0f, 1.0f);

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

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

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

            hProgram = loadShader(vss, fss);

            mTriangle = new Triangle();
        }
        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);
        }
        public void OnSurfaceChanged(Javax.Microedition.Khronos.Opengles.IGL10 gl, int width, int height)
        {
            // Adjust the viewport based on geometry changes,
            // such as screen rotation
            GLES20.GlViewport(0, 0, width, height);

            float ratio = (float)width / height;

            // this projection matrix is applied to object coordinates
            // in the onDrawFrame() method
            Android.Opengl.Matrix.FrustumM(mProjectionMatrix, 0, -ratio, ratio, -1, 1, 3, 7);

            GLES20.GlViewport(0, 0, width, height);
            if (mCamera != null)
            {
                Android.Hardware.Camera.Parameters p = mCamera.GetParameters();
                System.Collections.Generic.IList<Android.Hardware.Camera.Size> sizes = p.SupportedPreviewSizes;
                p.SetPreviewSize(sizes[0].Width, sizes[0].Height);
                mCamera.SetParameters(p);
                //mCamera.SetPreviewDisplay(holder);
                mCamera.StartPreview();
            }
        }
Esempio n. 12
0
 public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
 {
     // Set the background frame color
      // ������Ӱƽ��
      gl.GlShadeModel(GL10.GlSmooth);
      // ��ɫ����
      gl.GlClearColor(0.5f, 0.6f, 0.6f, 1.0f);
      // ������Ȼ���
      gl.GlClearDepthf(1.0f);
      // ������Ȳ���
      gl.GlEnable(GL10.GlDepthTest);
      // ������Ȳ��Ե�����
      gl.GlDepthFunc(GL10.GlLequal);
      // ����ϵͳ��͸�ӽ�������
      gl.GlHint(GL10.GlPerspectiveCorrectionHint, GL10.GlNicest);
 }
Esempio n. 13
0
		void IRenderer.OnDrawFrame (Javax.Microedition.Khronos.Opengles.IGL10 gl) {
			EventBase e;

			if (this.IsPaused) {
				while (_queue.TryPeek (out e)) {
					if (e is Resume) {
						this.IsPaused = false;
						return;
					} else
						_queue.TryDequeue (out e);
				}
				Thread.Sleep (_minFrameTicks);
				return;
			}

			var ticks = Environment.TickCount;
			var diffTicks = ticks - _lastTicks;
			if (diffTicks <= 0)
				return;

			if (diffTicks < _minFrameTicks) {
				Thread.Sleep (_minFrameTicks - diffTicks);
				ticks = Environment.TickCount;
				diffTicks = ticks - _lastTicks;
			}

			_lastTicks = ticks;

			_event.Time = (double)ticks / 1000.0;
			_event.DeltaTime = (float)diffTicks / 1000f;
			while (_queue.TryDequeue (out e)) {
				_event.Enqueue (e);
				if (e is Pause)
					this.IsPaused = true;
			}

			if (this.Update != null)
				this.Update (this, _event);
			if (this.Render != null)
				this.Render (this, _event);
		}
Esempio n. 14
0
		void IRenderer.OnSurfaceChanged (Javax.Microedition.Khronos.Opengles.IGL10 gl, int width, int height) {
			_size = new Vector2 (width, height);
			_queue.Enqueue (new Resize (_size));
			GL.Viewport (0, 0, width, height);
		}
Esempio n. 15
0
		void IRenderer.OnSurfaceCreated (Javax.Microedition.Khronos.Opengles.IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config) {
			_lastTicks = Environment.TickCount;
			_queue.Enqueue (new Start (this.Size));
		}
Esempio n. 16
0
		public void OnSurfaceCreated (Javax.Microedition.Khronos.Egl.EGLConfig config)
		{
			Log.Info (Tag, "onSurfaceCreated");
			game.Initialize ();
		}