Beispiel #1
0
  public void drawNinePatch(NinePatchTexture tex, int x, int y, int width, int height) {

    NinePatchChunk chunk = tex.getNinePatchChunk();

    // The code should be easily extended to handle the general cases by
    // allocating more space for buffers. But let's just handle the only
    // use case.
    if (chunk.mDivX.length != 2 || chunk.mDivY.length != 2) {
      throw new RuntimeException("unsupported nine patch");
    }
    if (!tex.bind(this, mGL)) {
      throw new RuntimeException("cannot bind" + tex.toString());
    }
    if (width <= 0 || height <= 0) return;

    int divX[] = mNinePatchX;
    int divY[] = mNinePatchY;
    float divU[] = mNinePatchU;
    float divV[] = mNinePatchV;

    int nx = stretch(divX, divU, chunk.mDivX, tex.getWidth(), width);
    int ny = stretch(divY, divV, chunk.mDivY, tex.getHeight(), height);

    setAlphaValue(mTransformation.getAlpha());
    Matrix matrix = mTransformation.getMatrix();
    matrix.getValues(mMatrixValues);
    GL11 gl = mGL;
    gl.glPushMatrix();
    gl.glMultMatrixf(toGLMatrix(mMatrixValues), 0);
    gl.glTranslatef(x, y, 0);
    drawMesh(divX, divY, divU, divV, nx, ny);
    gl.glPopMatrix();
  }
Beispiel #2
0
 private void drawRect(int x, int y, int width, int height, float matrix[]) {
   GL11 gl = mGL;
   gl.glPushMatrix();
   gl.glMultMatrixf(toGLMatrix(matrix), 0);
   putRectangle(x, y, width, height, mXyBuffer, mXyPointer);
   gl.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 4);
   gl.glPopMatrix();
 }
    @Override
    public void onDrawFrame(GL10 gl) {
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
      GL11 gl11 = (GL11) gl;

      gl.glMatrixMode(GL10.GL_PROJECTION);
      gl.glLoadIdentity();

      // perspective
      GLU.gluPerspective(gl11, 45, aspect, 0.01f, 100f);
      GLU.gluLookAt(
          gl,
          (float) (Math.cos(angle) * eyeDistance),
          0,
          (float) (Math.sin(angle) * eyeDistance),
          0,
          0,
          0.0f,
          0.0f,
          1.0f,
          0.0f);

      gl.glMatrixMode(GL10.GL_MODELVIEW);
      gl.glLoadIdentity();

      // set render status
      gl.glEnable(GL10.GL_TEXTURE_2D);
      gl.glEnable(GL10.GL_ALPHA_TEST);
      gl.glAlphaFunc(GL10.GL_EQUAL, 1.0f);
      // gl.glColor4f(1, 1, 1, 1);

      // bind
      gl.glBindTexture(GL10.GL_TEXTURE_2D, texture);
      vbo.bind(gl11);

      // left
      gl11.glPushMatrix();
      {
        gl11.glTranslatef(-1, 0, 0);
        ibo.draw(gl11);
      }
      gl11.glPopMatrix();

      // right
      gl11.glPushMatrix();
      {
        gl11.glTranslatef(1, 0, 0);
        ibo.draw(gl11);
      }
      gl11.glPopMatrix();

      // up
      gl11.glPushMatrix();
      {
        gl11.glTranslatef(0, -1, 0);
        ibo.draw(gl11);
      }
      gl11.glPopMatrix();

      // down
      gl11.glPushMatrix();
      {
        gl11.glTranslatef(0, 1, 0);
        ibo.draw(gl11);
      }
      gl11.glPopMatrix();

      // unbind
      vbo.unbind(gl11);
      gl.glDisable(GL10.GL_TEXTURE_2D);

      angle += (float) (1f / 180f * Math.PI);
    }