public  void onDrawFrame(GL10 gl)
 {
     // define the color we want to be displayed as the "clipping wall"
     gl.glClearColor(_red, _green, _blue, 1.0f);
     // clear the color buffer to show the ClearColor we called above...
     gl.glClear(GL10_GL_COLOR_BUFFER_BIT);
 }
 public void onSurfaceCreated(GL10 gl, EGLConfig config)
 {
     // preparation
     gl.glEnableClientState(GL10_GL_VERTEX_ARRAY);
     gl.glEnableClientState(GL10_GL_COLOR_ARRAY);
     initTriangle();
 }
            public void onSurfaceChanged(GL10 gl, int w, int h)
            {
                _width = w;
                _height = h;

                gl.glViewport(0, 0, w, h);
            }
			public override void onSurfaceCreated(GL10 gl, EGLConfig config)
			{
				gl.glClearColor(0, 0, 0, 1);
				GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

				int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
				int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

				mProgram = GLES20.glCreateProgram(); // create empty OpenGL ES
				// Program
				GLES20.glAttachShader(mProgram, vertexShader); // add the vertex
				// shader to program
				GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment
				// shader to
				// program
				GLES20.glLinkProgram(mProgram);

				int positionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
				int textureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord");

				GLES20.glVertexAttribPointer(positionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, COORDS_PER_VERTEX * 4, mVertexBuffer);

				GLES20.glEnableVertexAttribArray(positionHandle);

				GLES20.glVertexAttribPointer(textureHandle, TEXTURECOORDS_PER_VERTEX, GLES20.GL_FLOAT, false, TEXTURECOORDS_PER_VERTEX * 4, mTextureBuffer);

				GLES20.glEnableVertexAttribArray(textureHandle);

				GLES20.glUseProgram(mProgram);
				int i = GLES20.glGetUniformLocation(mProgram, "Ytex");
				GLES20.glUniform1i(i, 0); // Bind Ytex to texture unit 0

				i = GLES20.glGetUniformLocation(mProgram, "Utex");
				GLES20.glUniform1i(i, 1); // Bind Utex to texture unit 1

				i = GLES20.glGetUniformLocation(mProgram, "Vtex");
				GLES20.glUniform1i(i, 2); // Bind Vtex to texture unit 2

				mTextureWidth = 0;
				mTextureHeight = 0;
			}
            public void onDrawFrame(GL10 gl)
            {
                // define the color we want to be displayed as the "clipping wall"
                gl.glClearColor(_red, _green, _blue, 1.0f);

                // reset the matrix - good to fix the rotation to a static angle
                gl.glLoadIdentity();

                // clear the color buffer to show the ClearColor we called above...
                gl.glClear(GL10_GL_COLOR_BUFFER_BIT);

                // set rotation for the non-static triangle
                gl.glRotatef(_angle, 0f, 1f, 0f);

                gl.glColor4f(0.5f, 0f, 0f, 0.5f);
                gl.glVertexPointer(3, GL10_GL_FLOAT, 0, _vertexBuffer);
                gl.glDrawElements(GL10_GL_TRIANGLES, _nrOfVertices, GL10_GL_UNSIGNED_SHORT, _indexBuffer);

                // gl.glColor4f(0.5f, 0f, 0f, 0.5f);
                gl.glVertexPointer(3, GL10_GL_FLOAT, 0, _vertexBuffer);
                gl.glColorPointer(4, GL10_GL_FLOAT, 0, _colorBuffer);
                gl.glDrawElements(GL10_GL_TRIANGLES, _nrOfVertices, GL10_GL_UNSIGNED_SHORT, _indexBuffer);
            }
 public void onSurfaceChanged(GL10 arg0, int arg1, int arg2)
 {
     if (onresize != null)
         onresize(arg1, arg2);
 }
            public void onDrawFrame(GL10 gl)
            {
                // clear the color buffer and the depth buffer
                gl.glClear(GL10_GL_COLOR_BUFFER_BIT | GL10_GL_DEPTH_BUFFER_BIT);

                gl.glVertexPointer(3, GL10_GL_FLOAT, 0, _vertexBuffer);
                gl.glColorPointer(4, GL10_GL_FLOAT, 0, _colorBuffer);

                for (int i = 1; i <= 10; i++)
                {
                    gl.glLoadIdentity();
                    gl.glTranslatef(0.0f, -1f, -1.0f + -1.5f * i);
                    // set rotation
                    gl.glRotatef(_xAngle, 1f, 0f, 0f);
                    gl.glRotatef(_yAngle, 0f, 1f, 0f);
                    gl.glDrawElements(GL10_GL_TRIANGLES, _nrOfVertices, GL10_GL_UNSIGNED_SHORT, _indexBuffer);
                }
            }
Example #8
0
 protected void applyTranslation(GL10 pGL)
 {
     pGL.GlTranslatef(this.mX, this.mY, 0);
 }
 public void onSurfaceChanged(GL10 gl, int w, int h)
 {
     gl.glViewport(0, 0, w, h);
 }
 public  void onSurfaceCreated(GL10 gl, EGLConfig config)
 {
     // Do nothing special.
 }
			public override void onDrawFrame(GL10 gl)
			{
				mFrameLock.@lock();
				if (mCurrentFrame != null && !mVideoDisabled)
				{
					GLES20.glUseProgram(mProgram);

					if (mTextureWidth != mCurrentFrame.Width || mTextureHeight != mCurrentFrame.Height)
					{
						setupTextures(mCurrentFrame);
					}
					updateTextures(mCurrentFrame);

					Matrix.setIdentityM(mScaleMatrix, 0);
					float scaleX = 1.0f, scaleY = 1.0f;
					float ratio = (float) mCurrentFrame.Width / mCurrentFrame.Height;
					float vratio = (float) mViewportWidth / mViewportHeight;

					if (mVideoFitEnabled)
					{
						if (ratio > vratio)
						{
							scaleY = vratio / ratio;
						}
						else
						{
							scaleX = ratio / vratio;
						}
					}
					else
					{
						if (ratio < vratio)
						{
							scaleY = vratio / ratio;
						}
						else
						{
							scaleX = ratio / vratio;
						}
					}

					Matrix.scaleM(mScaleMatrix, 0, scaleX * (mCurrentFrame.MirroredX ? - 1.0f : 1.0f), scaleY, 1);

					int mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
					GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mScaleMatrix, 0);

					GLES20.glDrawElements(GLES20.GL_TRIANGLES, mVertexIndex.Length, GLES20.GL_UNSIGNED_SHORT, mDrawListBuffer);
				}
				else
				{
					//black frame when video is disabled
					gl.glClearColor(0, 0, 0, 1);
					GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
				}
				mFrameLock.unlock();
			}
            public void onDrawFrame(GL10 gl)
            {
                // define the color we want to be displayed as the "clipping wall"
                gl.glClearColor(_red, _green, _blue, 1.0f);

                // clear the color buffer to show the ClearColor we called above...
                gl.glClear(GL10_GL_COLOR_BUFFER_BIT);


                // set rotation
                gl.glRotatef(_angle, 0f, 1f, 0f);


                // set the color of our element
                gl.glColor4f(0.5f, 0f, 0f, 0.5f);

                // define the vertices we want to draw
                gl.glVertexPointer(3, GL10_GL_FLOAT, 0, _vertexBuffer);

                // finally draw the vertices
                gl.glDrawElements(GL10_GL_TRIANGLES, _nrOfVertices, GL10_GL_UNSIGNED_SHORT, _indexBuffer);
            }
			public virtual void onDrawFrame(GL10 gl)
			{
				gl.glClearColor((float) 0.5, (float) 0.5, (float) 0.5, (float) 1.0);
				gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
			}
 public virtual void onSurfaceCreated(GL10 gl, EGLConfig config)
 {
 }
			public virtual void onSurfaceCreated(GL10 gl, EGLConfig config)
			{
			}
			public virtual void onSurfaceChanged(GL10 gl, int width, int height)
			{
				gl.glViewport(0, 0, width, height);

			}
Example #17
0
 public void onSurfaceChanged(GL10 gl, int w, int h)
 {
     gl.glViewport(0, 0, w, h);
 }
 public void onSurfaceCreated(GL10 gl, EGLConfig config)
 {
     // Do nothing special.
 }
            public void onSurfaceCreated(GL10 gl, EGLConfig config)
            {
                // preparation
                // enable the differentiation of which side may be visible 
                gl.glEnable(GL10_GL_CULL_FACE);
                // which is the front? the one which is drawn counter clockwise
                gl.glFrontFace(GL10_GL_CCW);
                // which one should NOT be drawn
                gl.glCullFace(GL10_GL_BACK);

                gl.glEnableClientState(GL10_GL_VERTEX_ARRAY);
                gl.glEnableClientState(GL10_GL_COLOR_ARRAY);

                initTriangle();
            }
 public void onSurfaceCreated(GL10 arg0, globalandroid::javax.microedition.khronos.egl.EGLConfig arg1)
 {
     gl = new WebGLRenderingContext();
     if (onsurface != null)
         onsurface(gl);
 }
            public void onSurfaceCreated(GL10 glUnused, javax.microedition.khronos.egl.EGLConfig config)
            {
                // Set the background clear color to black.
                gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);

                // Use culling to remove back faces.
                gl.enable(gl.CULL_FACE);

                // Enable depth testing
                gl.enable(gl.DEPTH_TEST);

                // Position the eye in front of the origin.
                float eyeX = 0.0f;
                float eyeY = 0.0f;
                float eyeZ = -0.5f;

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

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

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

                mPerVertexProgramHandle = gl.createProgram(
                    new Shaders.TriangleVertexShader(),
                    new Shaders.TriangleFragmentShader()
                );

                gl.bindAttribLocation(mPerVertexProgramHandle, 0, "a_Position");
                gl.bindAttribLocation(mPerVertexProgramHandle, 1, "a_Color");
                gl.bindAttribLocation(mPerVertexProgramHandle, 2, "a_Normal");

                gl.linkProgram(mPerVertexProgramHandle);

                // Define a simple shader program for our point.

                mPointProgramHandle = gl.createProgram(
                    new Shaders.pointVertexShader(),
                    new Shaders.pointFragmentShader()
                );

                gl.bindAttribLocation(mPointProgramHandle, 0, "a_Position");

                gl.linkProgram(mPointProgramHandle);


            }
			public override void onSurfaceChanged(GL10 gl, int width, int height)
			{
				GLES20.glViewport(0, 0, width, height);
				mViewportWidth = width;
				mViewportHeight = height;
			}
            public void onDrawFrame(GL10 glUnused)
            {
                gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

                // Do a complete rotation every 10 seconds.
                long time = SystemClock.uptimeMillis() % 10000L;
                float angleInDegrees = (360.0f / 10000.0f) * ((int)time);

                // Set our per-vertex lighting program.
                gl.useProgram(mPerVertexProgramHandle);

                // Set program handles for cube drawing.
                mMVPMatrixHandle = gl.getUniformLocation(mPerVertexProgramHandle, "u_MVPMatrix");
                mMVMatrixHandle = gl.getUniformLocation(mPerVertexProgramHandle, "u_MVMatrix");
                mLightPosHandle = gl.getUniformLocation(mPerVertexProgramHandle, "u_LightPos");

                mPositionHandle = gl.getAttribLocation(mPerVertexProgramHandle, "a_Position");
                mColorHandle = gl.getAttribLocation(mPerVertexProgramHandle, "a_Color");
                mNormalHandle = gl.getAttribLocation(mPerVertexProgramHandle, "a_Normal");

                // Calculate position of the light. Rotate and then push into the distance.
                Matrix.setIdentityM(mLightModelMatrix, 0);
                Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -5.0f);
                Matrix.rotateM(mLightModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
                Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, 2.0f);

                Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
                Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);

                #region drawCube 
                Action drawCube =
                    delegate
                    {
                        // Pass in the position information
                        mCubePositions.position(0);

                        opengl.glVertexAttribPointer(mPositionHandle, mPositionDataSize, (int)gl.FLOAT, false,
                                0, mCubePositions);

                        gl.enableVertexAttribArray((uint)mPositionHandle);

                        // Pass in the color information
                        mCubeColors.position(0);
                        opengl.glVertexAttribPointer(mColorHandle, mColorDataSize, (int)gl.FLOAT, false,
                                0, mCubeColors);

                        gl.enableVertexAttribArray((uint)mColorHandle);

                        // Pass in the normal information
                        mCubeNormals.position(0);
                        opengl.glVertexAttribPointer(mNormalHandle, mNormalDataSize, (int)gl.FLOAT, false,
                                0, mCubeNormals);

                        gl.enableVertexAttribArray((uint)mNormalHandle);

                        // This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix
                        // (which currently contains model * view).
                        Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);

                        // Pass in the modelview matrix.
                        gl.uniformMatrix4fv(mMVMatrixHandle, false, mMVPMatrix);

                        // This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix
                        // (which now contains model * view * projection).
                        Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);

                        // Pass in the combined matrix.
                        gl.uniformMatrix4fv(mMVPMatrixHandle, false, mMVPMatrix);

                        // Pass in the light position in eye space.        
                        gl.uniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);

                        // Draw the cube.
                        gl.drawArrays(gl.TRIANGLES, 0, 36);
                    };
                #endregion


                // Draw some cubes.        
                Matrix.setIdentityM(mModelMatrix, 0);
                Matrix.translateM(mModelMatrix, 0, 4.0f, 0.0f, -7.0f);
                Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);
                drawCube();

                Matrix.setIdentityM(mModelMatrix, 0);
                Matrix.translateM(mModelMatrix, 0, -4.0f, 0.0f, -7.0f);
                Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
                drawCube();

                Matrix.setIdentityM(mModelMatrix, 0);
                Matrix.translateM(mModelMatrix, 0, 0.0f, 4.0f, -7.0f);
                Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
                drawCube();

                Matrix.setIdentityM(mModelMatrix, 0);
                Matrix.translateM(mModelMatrix, 0, 0.0f, -4.0f, -7.0f);
                drawCube();

                Matrix.setIdentityM(mModelMatrix, 0);
                Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -5.0f);
                Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 0.0f);
                drawCube();

                #region drawLight
                Action drawLight =
                    delegate
                    {
                        var pointMVPMatrixHandle = gl.getUniformLocation(mPointProgramHandle, "u_MVPMatrix");
                        var pointPositionHandle = gl.getAttribLocation(mPointProgramHandle, "a_Position");

                        // Pass in the position.
                        gl.vertexAttrib3f((uint)pointPositionHandle, mLightPosInModelSpace[0], mLightPosInModelSpace[1], mLightPosInModelSpace[2]);

                        // Since we are not using a buffer object, disable vertex arrays for this attribute.
                        gl.disableVertexAttribArray((uint)pointPositionHandle);

                        // Pass in the transformation matrix.
                        Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mLightModelMatrix, 0);
                        Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
                        
                        gl.uniformMatrix4fv(pointMVPMatrixHandle, false, mMVPMatrix);

                        // Draw the point.
                        gl.drawArrays(gl.POINTS, 0, 1);
                    };
                #endregion

                // Draw a point to indicate the light.
                gl.useProgram(mPointProgramHandle);
                drawLight();
            }
Example #24
0
 public virtual /* override */ /* final */ /* sealed */ void OnDraw(/* final */ GL10 pGL, /* final */ Camera pCamera)
 {
     if (this.mVisible)
     {
         this.OnManagedDraw(pGL, pCamera);
     }
 }
        // all setup and data loading goes here
        public void onSurfaceCreated(GL10 arg0, EGLConfig arg1)
        {
            var shaderProgram = gl.createProgram();


            var vs = gl.createShader( new Shaders.GeometryVertexShader() );
            var fs = gl.createShader(  new Shaders.GeometryVertexShader() );


            gl.attachShader(shaderProgram, vs);
            gl.attachShader(shaderProgram, fs);


            gl.linkProgram(shaderProgram);

            
            gl.useProgram(shaderProgram);
            positionAttribLocation = gl.getAttribLocation(shaderProgram, "position");

            // setup geometry
            float[] verticesData = 
            { 
                0.0f, 0.5f, 0.0f, 
                -0.5f, -0.5f, 0.0f, 
                0.5f,  -0.5f, 0.0f 
            };

            vertices = ByteBuffer
                    .allocateDirect(verticesData.Length * 4)
                    .order(ByteOrder.nativeOrder()).asFloatBuffer();
            vertices.put(verticesData).position(0);
        }
Example #26
0
 protected abstract void OnManagedDraw(/* final */ GL10 pGL, /* final */ Camera pCamera);
Example #27
0
        //public synchronized void update(final GL10 pGL) {
        public void Update(GL10 pGL)
        {
            lock (_methodLock)
            {
                //final ArrayList<Letter> lettersPendingToBeDrawnToTexture = this.mLettersPendingToBeDrawnToTexture;
                List<Letter> lettersPendingToBeDrawnToTexture = this.mLettersPendingToBeDrawnToTexture;
                if (lettersPendingToBeDrawnToTexture.Count > 0)
                {
                    int hardwareTextureID = this.mTexture.GetHardwareTextureID();

                    float textureWidth = this.mTextureWidth;
                    float textureHeight = this.mTextureHeight;

                    for (int i = lettersPendingToBeDrawnToTexture.Count - 1; i >= 0; i--)
                    {
                        Letter letter = lettersPendingToBeDrawnToTexture[i];
                        Bitmap bitmap = this.GetLetterBitmap(letter.mCharacter);

                        GLHelper.BindTexture(pGL, hardwareTextureID);
                        GLUtils.TexSubImage2D(GL10Consts.GlTexture2d, 0, (int)(letter.mTextureX * textureWidth), (int)(letter.mTextureY * textureHeight), bitmap);

                        bitmap.Recycle();
                    }
                    lettersPendingToBeDrawnToTexture.Clear();
                    //System.gc();
                    // TODO: Verify if this is a good match: System.gc() -> Dispose() ... leaving it to standard GC at present
                }
            }
        }
 public virtual void onSurfaceChanged(GL10 gl, int width, int height)
 {
     gl.glViewport(0, 0, width, height);
 }
			public void onDrawFrame(GL10 glUnused)
			{
				if (mBlending)
				{
					gl.clear(gl.COLOR_BUFFER_BIT);
				}
				else
				{
					gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
				}

				// Do a complete rotation every 10 seconds.
				long time = SystemClock.uptimeMillis() % 10000L;
				float angleInDegrees = (360.0f / 10000.0f) * ((int)time);

				// Set our program
				gl.useProgram(mProgramHandle);

				// Set program handles for cube drawing.
				mMVPMatrixHandle = gl.getUniformLocation(mProgramHandle, "u_MVPMatrix");
				mPositionHandle = gl.getAttribLocation(mProgramHandle, "a_Position");
				mColorHandle = gl.getAttribLocation(mProgramHandle, "a_Color");

				#region drawCube
				Action drawCube =
					delegate
					{
						// Pass in the position information
						mCubePositions.position(0);


						GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, (int)gl.FLOAT, false,
								0, mCubePositions);

						gl.enableVertexAttribArray((uint)mPositionHandle);

						// Pass in the color information
						mCubeColors.position(0);
						GLES20.glVertexAttribPointer(mColorHandle, mColorDataSize, (int)gl.FLOAT, false,
								0, mCubeColors);

						gl.enableVertexAttribArray((uint)mColorHandle);

						// This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix
						// (which currently contains model * view).
						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).
						Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);

						// Pass in the combined matrix.
						gl.uniformMatrix4fv(mMVPMatrixHandle, false, mMVPMatrix);

						// Draw the cube.
						gl.drawArrays(gl.TRIANGLES, 0, 36);
					};
				#endregion

				// Draw some cubes.        
				Matrix.setIdentityM(mModelMatrix, 0);
				Matrix.translateM(mModelMatrix, 0, 4.0f, 0.0f, -7.0f);
				Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);
				drawCube();

				Matrix.setIdentityM(mModelMatrix, 0);
				Matrix.translateM(mModelMatrix, 0, -4.0f, 0.0f, -7.0f);
				Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
				drawCube();

				Matrix.setIdentityM(mModelMatrix, 0);
				Matrix.translateM(mModelMatrix, 0, 0.0f, 4.0f, -7.0f);
				Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
				drawCube();

				Matrix.setIdentityM(mModelMatrix, 0);
				Matrix.translateM(mModelMatrix, 0, 0.0f, -4.0f, -7.0f);
				drawCube();

				Matrix.setIdentityM(mModelMatrix, 0);
				Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -5.0f);
				Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 0.0f);
				drawCube();
			}
            public void onSurfaceChanged(GL10 glUnused, int width, int height)
            {
                // Set the OpenGL viewport to the same size as the surface.
                gl.viewport(0, 0, width, height);

                // Create a new perspective projection matrix. The height will stay the same
                // while the width will vary as per aspect ratio.
                float ratio = (float)width / height;
                float left = -ratio;
                float right = ratio;
                float bottom = -1.0f;
                float top = 1.0f;
                float near = 1.0f;
                float far = 10.0f;

                Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
            }
 public virtual void onDrawFrame(GL10 gl)
 {
     gl.glClearColor((float)0.5, (float)0.5, (float)0.5, (float)1.0);
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
 }
        public void onDrawFrame(GL10 arg0)
        {
            //measure performance
            ++mFrameCount;
            if (mFrameCount % 50 == 0)
            {
                long now = java.lang.System.nanoTime();
                double msPerFrame = (now - mStartTimeNS) / 1e6 / mFrameCount;
                //Log.i("NeHe", "ms per frame: " + msPerFrame +
                //       " (fps: " + (1000 / msPerFrame) + ")");
                mFrameCount = 0;
                mStartTimeNS = now;
            }

            //draw
            gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
            gl.clear(opengl.GL_COLOR_BUFFER_BIT);

            opengl.glBindBuffer(opengl.GL_ARRAY_BUFFER, vertexVBO);
            gl.vertexAttribPointer(0, 3, opengl.GL_FLOAT, false, 0, vertices);
            gl.enableVertexAttribArray(0);

            gl.drawArrays(opengl.GL_TRIANGLES, 0, 3);
        }
            public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
            {
                // Set the background clear color to black.
                gl.clearColor(1.0f, 1.0f, 1.0f, 0.0f);

                // Use culling to remove back faces.
                opengl.glEnable(opengl.GL_CULL_FACE);

                // Enable depth testing
                opengl.glEnable(opengl.GL_DEPTH_TEST);

                // Enable texture mapping
                opengl.glEnable(opengl.GL_TEXTURE_2D);

                // Position the eye in front of the origin.
                float eyeX = 0.0f;
                float eyeY = 0.0f;
                float eyeZ = -0.5f;

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

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

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


                mProgramHandle = gl.createAndLinkProgram(
                    new Shaders.per_pixelVertexShader(),
                    new Shaders.per_pixelFragmentShader(),
                    "a_Position",
                    "a_Color",
                    "a_Normal",
                    "a_TexCoordinate"
                );

                // Define a simple shader program for our point.


                mPointProgramHandle = gl.createAndLinkProgram(
                    new Shaders.per_pixelVertexShader(),
                    new Shaders.per_pixelFragmentShader(),
                      "a_Position"
                );

                // Load the texture
                mTextureDataHandle = TextureHelper.loadTexture(mActivityContext, R.drawable.jsc_24bit);
                mTextureDataHandle2 = TextureHelper.loadTexture(mActivityContext, R.drawable.jsc_black);
            }
        // resizing or reorienting the screen has happened,
        // adjust projection matrices
        public void onSurfaceChanged(GL10 arg0, int arg1, int arg2)
        {

        }
            public void onDrawFrame(GL10 glUnused)
            {
                if (_width < _height)
                    gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
                else
                    gl.clearColor(1.0f, 1.0f, 1.0f, 0.0f);

                gl.clear(opengl.GL_COLOR_BUFFER_BIT | opengl.GL_DEPTH_BUFFER_BIT);

                // Do a complete rotation every 10 seconds.
                long time = SystemClock.uptimeMillis() % 20000L;
                float angleInDegrees = (360.0f / 20000.0f) * ((int)time);

                // Set our per-vertex lighting program.
                gl.useProgram(mProgramHandle);

                // Set program handles for cube drawing.
                mMVPMatrixHandle = gl.getUniformLocation(mProgramHandle, "u_MVPMatrix");
                mMVMatrixHandle = gl.getUniformLocation(mProgramHandle, "u_MVMatrix");
                mLightPosHandle = gl.getUniformLocation(mProgramHandle, "u_LightPos");
                mTextureUniformHandle = gl.getUniformLocation(mProgramHandle, "u_Texture");

                mPositionHandle = gl.getAttribLocation(mProgramHandle, "a_Position");
                mColorHandle = gl.getAttribLocation(mProgramHandle, "a_Color");
                mNormalHandle = gl.getAttribLocation(mProgramHandle, "a_Normal");
                mTextureCoordinateHandle = gl.getAttribLocation(mProgramHandle, "a_TexCoordinate");

                // Set the active texture unit to texture unit 0.
                opengl.glActiveTexture(opengl.GL_TEXTURE0);

                // Bind the texture to this unit.
                if (_width < _height)
                    opengl.glBindTexture(opengl.GL_TEXTURE_2D, mTextureDataHandle2);
                else
                    opengl.glBindTexture(opengl.GL_TEXTURE_2D, mTextureDataHandle);

                // Tell the texture uniform sampler to use this texture in the shader by binding to texture unit 0.
                gl.uniform1i(mTextureUniformHandle, 0);

                // Calculate position of the light. Rotate and then push into the distance.
                Matrix.setIdentityM(mLightModelMatrix, 0);
                Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -5.0f);
                Matrix.rotateM(mLightModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
                Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, 2.0f);

                Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
                Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);

                // Draw some cubes.        

                //#region cube on right
                //Matrix.setIdentityM(mModelMatrix, 0);
                //Matrix.translateM(mModelMatrix, 0, 4.0f, 0.0f, -7.0f);
                //Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);
                //drawCube();
                //#endregion


                Matrix.setIdentityM(mModelMatrix, 0);
                //Matrix.translateM(mModelMatrix, 0, -4.0f, 0.0f, -7.0f);
                Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -4.0f);
                Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, -1.0f, 0.0f);
                drawCube();

                //Matrix.setIdentityM(mModelMatrix, 0);
                //Matrix.translateM(mModelMatrix, 0, 0.0f, 4.0f, -7.0f);
                //Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
                //drawCube();

                //Matrix.setIdentityM(mModelMatrix, 0);
                //Matrix.translateM(mModelMatrix, 0, 0.0f, -4.0f, -7.0f);
                //drawCube();

                //Matrix.setIdentityM(mModelMatrix, 0);
                //Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -5.0f);
                //Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 0.0f);
                //drawCube();

                // Draw a point to indicate the light.
                //gl.useProgram(mPointProgramHandle);
                //drawLight();
            }
            public void onSurfaceCreated(GL10 gl, EGLConfig config)
            {
                gl.glMatrixMode(GL10_GL_PROJECTION);
                float size = .01f * (float)java.lang.Math.tan(java.lang.Math.toRadians(45.0) / 2);
                float ratio = _width / _height;
                // perspective:
                gl.glFrustumf(-size, size, -size / ratio, size / ratio, 0.01f, 100.0f);
                // orthographic:
                //gl.glOrthof(-1, 1, -1 / ratio, 1 / ratio, 0.01f, 100.0f);
                gl.glViewport(0, 0, (int)_width, (int)_height);
                gl.glMatrixMode(GL10_GL_MODELVIEW);
                gl.glEnable(GL10_GL_DEPTH_TEST);

                // define the color we want to be displayed as the "clipping wall"
                gl.glClearColor(0f, 0f, 0f, 1.0f);

                // enable the differentiation of which side may be visible 
                gl.glEnable(GL10_GL_CULL_FACE);
                // which is the front? the one which is drawn counter clockwise
                gl.glFrontFace(GL10_GL_CCW);
                // which one should NOT be drawn
                gl.glCullFace(GL10_GL_BACK);

                gl.glEnableClientState(GL10_GL_VERTEX_ARRAY);
                gl.glEnableClientState(GL10_GL_COLOR_ARRAY);

                initTriangle();
            }
            public void onSurfaceCreated(GL10 glUnused, javax.microedition.khronos.egl.EGLConfig config)
            {
                // Set the background clear color to black.
                gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);

                // Use culling to remove back faces.
                gl.enable(gl.CULL_FACE);

                // Enable depth testing
                gl.enable(gl.DEPTH_TEST);

                // Enable texture mapping
                gl.enable(gl.TEXTURE_2D);

                // Position the eye in front of the origin.
                float eyeX = 0.0f;
                float eyeY = 0.0f;
                float eyeZ = -0.5f;

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

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

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


             


                mProgramHandle = gl.createProgram(
                      new Shaders.per_pixelVertexShader(),
                      new Shaders.per_pixelFragmentShader()
                  );

                gl.bindAttribLocation(mProgramHandle, 0, "a_Position");
                gl.bindAttribLocation(mProgramHandle, 1, "a_Color");
                gl.bindAttribLocation(mProgramHandle, 2, "a_Normal");
                gl.bindAttribLocation(mProgramHandle, 3, "a_TexCoordinate");

                gl.linkProgram(mProgramHandle);

                // Define a simple shader program for our point.

                mPointProgramHandle = gl.createProgram(
                    new Shaders.pointVertexShader(),
                    new Shaders.pointFragmentShader()
                );

                gl.bindAttribLocation(mPointProgramHandle, 0, "a_Position");

                gl.linkProgram(mPointProgramHandle);


                #region loadTexture
                Func<android.graphics.Bitmap, WebGLTexture> loadTexture = (bitmap) =>
               {
                   var textureHandle = gl.createTexture();

                   // Bind to the texture in OpenGL
                   gl.bindTexture(gl.TEXTURE_2D, textureHandle);

                   // Set filtering
                   gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, (int)gl.NEAREST);
                   gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, (int)gl.NEAREST);

                   // Load the bitmap into the bound texture.
                   //gl.texImage2D(
                   GLUtils.texImage2D((int)gl.TEXTURE_2D, 0, bitmap, 0);

                   // Recycle the bitmap, since its data has been loaded into OpenGL.
                   bitmap.recycle();


                   return textureHandle;
               };
                #endregion

                #region openFileFromAssets
                Func<string, InputStream> openFileFromAssets = (string spath) =>
                {
                    InputStream value = null;
                    try
                    {
                        value = this.mActivityContext.getResources().getAssets().open(spath);
                    }
                    catch
                    {

                    }
                    return value;

                };
                #endregion


                // Read in the resource
                var bumpy_bricks_public_domain = android.graphics.BitmapFactory.decodeStream(
                    openFileFromAssets("bumpy_bricks_public_domain.jpg")
                );

                // Load the texture
                mTextureDataHandle = loadTexture(
                    bumpy_bricks_public_domain
                );

                gl.generateMipmap(gl.TEXTURE_2D);

            }
 public void onDrawFrame(GL10 value)
 {
     if (onframe != null)
         onframe();
 }
Example #39
0
        // ===========================================================
        // Methods
        // ===========================================================

        protected void doDraw(GL10 pGL, Camera pCamera)
        {
        }