title: Zoom in/out in OpenGL ES
body: <p>I want to learn how to perform zooming in and zooming out. This is a simple example of a 2D triangle that rotates. Could you tell me how can I add zoom in and zoom out functionality to this simple example?</p>
  
  <p>Should I use <code>gl.glScalef</code>? How? </p>
  
  <pre><code>public class GLrenderer implements Renderer {
      public GLqueue tri;
      private float angle = 0;
  
      public GLrenderer() {
          tri = new GLqueue();
      }
  
      @Override
      public void onSurfaceCreated(GL10 gl, EGLConfig eglConfig) {
          // TODO Auto-generated method stub
          gl.glDisable(GL10.GL_DITHER);
          gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
          gl.glClearColor(.0f, .0f, .0f, 0f);
          gl.glClearDepthf(1f);
      }
  
      @Override
      public void onDrawFrame(GL10 gl) {
          // TODO Auto-generated method stub
          gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_COLOR_BUFFER_BIT);
          gl.glMatrixMode(GL10.GL_MODELVIEW);
          gl.glLoadIdentity();
          gl.glTranslatef(0, 0, -10);
          gl.glPushMatrix();
          gl.glRotatef(angle, 0, 0, 1);
          tri.draw(gl);
          gl.glPopMatrix();
          angle++;
      }
  
      @Override
      public void onSurfaceChanged(GL10 gl, int width, int height) {
          // TODO Auto-generated method stub
          gl.glViewport(0, 0, width, height);
          float ratio = (float) width / height;
          gl.glMatrixMode(GL10.GL_PROJECTION);
          gl.glLoadIdentity();
          gl.glFrustumf(-ratio, ratio, -1, 1, 1, 25);
      }
  }
  </code></pre>
  
  <p>This is my activity class, and <code>onTouch</code> event is added to that. What should I add so that when I touch the screen the zoom works?</p>
  
  <pre><code>GLSurfaceView OurSurface;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      OurSurface = new GLSurfaceView(this);
      OurSurface.setRenderer(new GLrenderer());
      setContentView(OurSurface);
  }
  
  @Override
  public boolean onTouchEvent(MotionEvent event) {
      int action = event.getAction();
      switch (action) {
          case (MotionEvent.ACTION_DOWN): // Touch screen pressed
              break;
          case (MotionEvent.ACTION_UP): // Touch screen touch ended
              break;
          case (MotionEvent.ACTION_MOVE): // Contact has moved across screen
              break;
          case (MotionEvent.ACTION_CANCEL): // Touch event cancelled
              break;
      }
      return super.onTouchEvent(event);
  }
  
  @Override
  protected void onPause() {
      // TODO Auto-generated method stub
      super.onPause();
      OurSurface.onPause();
  }
  
  @Override
  protected void onResume() {
      // TODO Auto-generated method stub
      super.onResume();
      OurSurface.onResume();
  }
  
  @Override
  public boolean onTouch(View v, MotionEvent event) {
      // TODO Auto-generated method stub
      return false;
  }
  </code></pre>