public void draw(GL10 gl) {
   glFrontFace(GL_CCW);
   glVertexPointer(3, GL_FLOAT, 0, mFVertexBuffer);
   glEnable(GL_TEXTURE_2D);
   glTexCoordPointer(2, GL_FLOAT, 0, mTexBuffer);
   glDrawElements(GL_TRIANGLE_STRIP, VERTS, GL_UNSIGNED_SHORT, mIndexBuffer);
 }
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    /*
     * By default, OpenGL enables features that improve quality
     * but reduce performance. One might want to tweak that
     * especially on software renderer.
     */
    glDisable(GL_DITHER);

    /*
     * Some one-time OpenGL initialization can be made here
     * probably based on features of this particular context
     */
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);

    glClearColor(.5f, .5f, .5f, 1);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_TEXTURE_2D);

    /*
     * Create our texture. This has to be done each time the
     * surface is created.
     */

    int[] textures = new int[1];
    glGenTextures(1, textures, 0);

    mTextureID = textures[0];
    glBindTexture(GL_TEXTURE_2D, mTextureID);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    mTextureLoader.load(gl);
  }
Example #3
0
  /**
   * Draws a frame where the content of the electron beam is collapsing inwards upon itself
   * vertically with red / green / blue channels dispersing and eventually merging down to a single
   * horizontal line.
   *
   * @param stretch The stretch factor. 0.0 is no collapse, 1.0 is full collapse.
   */
  private void drawVStretch(float stretch) {
    // compute interpolation scale factors for each color channel
    final float ar = scurve(stretch, 7.5f);
    final float ag = scurve(stretch, 8.0f);
    final float ab = scurve(stretch, 8.5f);
    if (DEBUG) {
      Slog.d(TAG, "drawVStretch: stretch=" + stretch + ", ar=" + ar + ", ag=" + ag + ", ab=" + ab);
    }

    // set blending
    GLES10.glBlendFunc(GLES10.GL_ONE, GLES10.GL_ONE);
    GLES10.glEnable(GLES10.GL_BLEND);

    // bind vertex buffer
    GLES10.glVertexPointer(2, GLES10.GL_FLOAT, 0, mVertexBuffer);
    GLES10.glEnableClientState(GLES10.GL_VERTEX_ARRAY);

    // set-up texturing
    GLES10.glDisable(GLES10.GL_TEXTURE_2D);
    GLES10.glEnable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);

    // bind texture and set blending for drawing planes
    GLES10.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTexNames[0]);
    GLES10.glTexEnvx(
        GLES10.GL_TEXTURE_ENV,
        GLES10.GL_TEXTURE_ENV_MODE,
        mMode == MODE_WARM_UP ? GLES10.GL_MODULATE : GLES10.GL_REPLACE);
    GLES10.glTexParameterx(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_MAG_FILTER, GLES10.GL_LINEAR);
    GLES10.glTexParameterx(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_MIN_FILTER, GLES10.GL_LINEAR);
    GLES10.glTexParameterx(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_WRAP_S, GLES10.GL_CLAMP_TO_EDGE);
    GLES10.glTexParameterx(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_WRAP_T, GLES10.GL_CLAMP_TO_EDGE);
    GLES10.glEnable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
    GLES10.glTexCoordPointer(2, GLES10.GL_FLOAT, 0, mTexCoordBuffer);
    GLES10.glEnableClientState(GLES10.GL_TEXTURE_COORD_ARRAY);

    // draw the red plane
    setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ar, mSwapNeeded);
    GLES10.glColorMask(true, false, false, true);
    GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);

    // draw the green plane
    setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ag, mSwapNeeded);
    GLES10.glColorMask(false, true, false, true);
    GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);

    // draw the blue plane
    setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ab, mSwapNeeded);
    GLES10.glColorMask(false, false, true, true);
    GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);

    // clean up after drawing planes
    GLES10.glDisable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
    GLES10.glDisableClientState(GLES10.GL_TEXTURE_COORD_ARRAY);
    GLES10.glColorMask(true, true, true, true);

    // draw the white highlight (we use the last vertices)
    if (mMode == MODE_COOL_DOWN) {
      GLES10.glColor4f(ag, ag, ag, 1.0f);
      GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);
    }

    // clean up
    GLES10.glDisableClientState(GLES10.GL_VERTEX_ARRAY);
    GLES10.glDisable(GLES10.GL_BLEND);
  }