Пример #1
0
  /**
   * Draws an animation frame showing the electron beam activated at the specified level.
   *
   * @param level The electron beam level.
   * @return True if successful.
   */
  public boolean draw(float level) {
    if (DEBUG) {
      Slog.d(TAG, "drawFrame: level=" + level);
    }

    if (!mPrepared) {
      return false;
    }

    if (mMode == MODE_FADE) {
      return showSurface(1.0f - level);
    }

    if (!attachEglContext()) {
      return false;
    }

    try {
      // Clear frame to solid black.
      GLES10.glClearColor(0f, 0f, 0f, 1f);
      GLES10.glClear(GLES10.GL_COLOR_BUFFER_BIT);

      if (mElectronBeamMode == 1 || (mElectronBeamMode == 2 && mIsLandscape)) {
        // Draw the frame vertical.
        if (level < VSTRETCH_DURATION) {
          drawHStretch(1.0f - (level / VSTRETCH_DURATION));
        } else {
          drawVStretch(1.0f - ((level - VSTRETCH_DURATION) / HSTRETCH_DURATION));
        }
      } else {
        // Draw the frame horizontal.
        if (level < HSTRETCH_DURATION) {
          drawHStretch(1.0f - (level / HSTRETCH_DURATION));
        } else {
          drawVStretch(1.0f - ((level - HSTRETCH_DURATION) / VSTRETCH_DURATION));
        }
      }

      if (checkGlErrors("drawFrame")) {
        return false;
      }

      EGL14.eglSwapBuffers(mEglDisplay, mEglSurface);
    } finally {
      detachEglContext();
    }
    return showSurface(1.0f);
  }
  public void onDrawFrame(GL10 gl) {
    /*
     * By default, OpenGL enables features that improve quality
     * but reduce performance. One might want to tweak that
     * especially on software renderer.
     */
    glDisable(GL_DITHER);

    glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    /*
     * Usually, the first thing one might want to do is to clear
     * the screen. The most efficient way of doing this is to use
     * glClear().
     */

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    /*
     * Now we're ready to draw some 3D objects
     */

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, mTextureID);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    long time = SystemClock.uptimeMillis() % 4000L;
    float angle = 0.090f * ((int) time);

    glRotatef(angle, 0, 0, 1.0f);

    mTriangle.draw(gl);
  }