乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      OpenGL ES Tutorial for Android – Part I – Setting up the view

       aaie_ 2012-08-25

      I'm going to write a couple of tutorials on using OpenGL ES on Android phones. The theory of OpenGL ES is the same on different devices so it should be quite easy to convert them to another platform.

      I can't always remember where I found particular info so I might not always be able to give you the right reference. If you feel that I have borrowed stuff from you but have forgotten to add you as a reference, please e-mail me.

      In the code examples I will have two different links for each function. The actual function will be linked to the android documentation and after that I will also link the OpenGL documentations. Like this:

      gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);  // OpenGL docs.

      So, let's start.

      In this tutorial I will show you how to set up your OpenGL ES view that’s always a good place to start.

      Setting up an OpenGL ES View

      Setting up a OpenGL view has never been hard and on Android it is still easy. There really are only two things you need to get started.

      GLSurfaceView

      GLSurfaceView is a API class in Android 1.5 that helps you write OpenGL ES applications.

      • Providing the glue code to connect OpenGL ES to the View system.
      • Providing the glue code to make OpenGL ES work with the Activity life-cycle.
      • Making it easy to choose an appropriate frame buffer pixel format.
      • Creating and managing a separate rendering thread to enable smooth animation.
      • Providing easy-to-use debugging tools for tracing OpenGL ES API calls and checking for errors.

      If you want to get going fast with your OpenGL ES application this is where you should start.

      The only function you need to call on is:

      public void  setRenderer(GLSurfaceView.Renderer renderer)

      Read more at: GLSurfaceView

      GLSurfaceView.Renderer

      GLSurfaceView.Renderer is a generic render interface. In your implementation of this renderer you should put all your calls to render a frame.
      There are three functions to implement:

      // Called when the surface is created or recreated.
      public void onSurfaceCreated(GL10 gl, EGLConfig config)
      
      // Called to draw the current frame.
      public void onDrawFrame(GL10 gl)
      
      // Called when the surface changed size.
      public void onSurfaceChanged(GL10 gl, int width, int height)
      

      onSurfaceCreated

      Here it's a good thing to setup things that you don't change so often in the rendering cycle. Stuff like what color to clear the screen with, enabling z-buffer and so on.

      onDrawFrame

      Here is where the actual drawing take place.

      onSurfaceChanged

      If your device supports flipping between landscape and portrait you will get a call to this function when it happens. What you do here is setting upp the new ratio.
      Read more at: GLSurfaceView.Renderer

      Putting it together

      First we create our activity, we keep it clean and simple.

      package se.jayway.opengl.tutorial;
      
      import android.app.Activity;
      import android.opengl.GLSurfaceView;
      import android.os.Bundle;
      
      public class TutorialPartI extends Activity {
          /** Called when the activity is first created. */
          @Override
          public void onCreate(Bundle savedInstanceState) {
          	super.onCreate(savedInstanceState);
       		GLSurfaceView view = new GLSurfaceView(this);
         		view.setRenderer(new OpenGLRenderer());
         		setContentView(view);
          }
      }
      

      Our renderer takes little bit more work to setup, look at it and I will explain the code a bit more.

      package se.jayway.opengl.tutorial;
      
      import javax.microedition.khronos.egl.EGLConfig;
      import javax.microedition.khronos.opengles.GL10;
      
      import android.opengl.GLU;
      import android.opengl.GLSurfaceView.Renderer;
      
      public class OpenGLRenderer implements Renderer {
      	/*
      	 * (non-Javadoc)
      	 *
      	 * @see
      	 * android.opengl.GLSurfaceView.Renderer#onSurfaceCreated(javax.
               * microedition.khronos.opengles.GL10, javax.microedition.khronos.
               * egl.EGLConfig)
      	 */
      	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
      		// Set the background color to black ( rgba ).
      		gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);  // OpenGL docs.
      		// Enable Smooth Shading, default not really needed.
      		gl.glShadeModel(GL10.GL_SMOOTH);// OpenGL docs.
      		// Depth buffer setup.
      		gl.glClearDepthf(1.0f);// OpenGL docs.
      		// Enables depth testing.
      		gl.glEnable(GL10.GL_DEPTH_TEST);// OpenGL docs.
      		// The type of depth testing to do.
      		gl.glDepthFunc(GL10.GL_LEQUAL);// OpenGL docs.
      		// Really nice perspective calculations.
      		gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, // OpenGL docs.
                                GL10.GL_NICEST);
      	}
      
      	/*
      	 * (non-Javadoc)
      	 *
      	 * @see
      	 * android.opengl.GLSurfaceView.Renderer#onDrawFrame(javax.
               * microedition.khronos.opengles.GL10)
      	 */
      	public void onDrawFrame(GL10 gl) {
      		// Clears the screen and depth buffer.
      		gl.glClear(GL10.GL_COLOR_BUFFER_BIT | // OpenGL docs.
                                 GL10.GL_DEPTH_BUFFER_BIT);
      	}
      
      	/*
      	 * (non-Javadoc)
      	 *
      	 * @see
      	 * android.opengl.GLSurfaceView.Renderer#onSurfaceChanged(javax.
               * microedition.khronos.opengles.GL10, int, int)
      	 */
      	public void onSurfaceChanged(GL10 gl, int width, int height) {
      		// Sets the current view port to the new size.
      		gl.glViewport(0, 0, width, height);// OpenGL docs.
      		// Select the projection matrix
      		gl.glMatrixMode(GL10.GL_PROJECTION);// OpenGL docs.
      		// Reset the projection matrix
      		gl.glLoadIdentity();// OpenGL docs.
      		// Calculate the aspect ratio of the window
      		GLU.gluPerspective(gl, 45.0f,
                                         (float) width / (float) height,
                                         0.1f, 100.0f);
      		// Select the modelview matrix
      		gl.glMatrixMode(GL10.GL_MODELVIEW);// OpenGL docs.
      		// Reset the modelview matrix
      		gl.glLoadIdentity();// OpenGL docs.
      	}
      }
      

      Fullscreen

      Just add this lines in the OpenGLDemo class and you will get fullscreen.

          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              this.requestWindowFeature(Window.FEATURE_NO_TITLE); // (NEW)
              getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                  WindowManager.LayoutParams.FLAG_FULLSCREEN); // (NEW)
              ... // Previous code.
          }
      

      This is pretty much all you need to get your view up and running. If you compile and run it you will see a nice black screen.

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多