Exemple #1
0
 public void destroy() {
   if (mTextureHandles != null) {
     GLES20.glDeleteTextures(mTextureHandles.length, mTextureHandles, 0);
     GLUtil.checkGlError("Destroy picture");
     mTextureHandles = null;
   }
 }
Exemple #2
0
  public void draw(float[] mvpMatrix, float alpha) {
    if (!mHasContent) {
      return;
    }

    // Add program to OpenGL ES environment
    GLES20.glUseProgram(sProgramHandle);

    // Apply the projection and view transformation
    GLES20.glUniformMatrix4fv(sUniformMVPMatrixHandle, 1, false, mvpMatrix, 0);
    GLUtil.checkGlError("glUniformMatrix4fv");

    // Set up vertex buffer
    GLES20.glEnableVertexAttribArray(sAttribPositionHandle);
    GLES20.glVertexAttribPointer(
        sAttribPositionHandle,
        COORDS_PER_VERTEX,
        GLES20.GL_FLOAT,
        false,
        VERTEX_STRIDE_BYTES,
        mVertexBuffer);

    // Set up texture stuff
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glUniform1i(sUniformTextureHandle, 0);
    GLES20.glVertexAttribPointer(
        sAttribTextureCoordsHandle,
        COORDS_PER_TEXTURE_VERTEX,
        GLES20.GL_FLOAT,
        false,
        TEXTURE_VERTEX_STRIDE_BYTES,
        mTextureCoordsBuffer);
    GLES20.glEnableVertexAttribArray(sAttribTextureCoordsHandle);

    // Set the alpha
    GLES20.glUniform1f(sUniformAlphaHandle, alpha);

    // Draw tiles
    for (int y = 0; y < mRows; y++) {
      for (int x = 0; x < mCols; x++) {
        // Pass in the vertex information
        mVertices[0] =
            mVertices[3] = mVertices[9] = Math.min(-1 + 2f * x * mTileSize / mWidth, 1); // left
        mVertices[1] =
            mVertices[10] =
                mVertices[16] = Math.min(-1 + 2f * (y + 1) * mTileSize / mHeight, 1); // top
        mVertices[6] =
            mVertices[12] =
                mVertices[15] = Math.min(-1 + 2f * (x + 1) * mTileSize / mWidth, 1); // right
        mVertices[4] =
            mVertices[7] = mVertices[13] = Math.min(-1 + 2f * y * mTileSize / mHeight, 1); // bottom
        mVertexBuffer.put(mVertices);
        mVertexBuffer.position(0);

        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureHandles[y * mCols + x]);
        GLUtil.checkGlError("glBindTexture");

        // Draw the two triangles
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mVertices.length / COORDS_PER_VERTEX);
      }
    }

    GLES20.glDisableVertexAttribArray(sAttribPositionHandle);
    GLES20.glDisableVertexAttribArray(sAttribTextureCoordsHandle);
  }