Пример #1
0
 private void drawBoundTexture(BasicTexture texture, int x, int y, int width, int height) {
   // Test whether it has been rotated or flipped, if so, glDrawTexiOES
   // won't work
   if (isMatrixRotatedOrFlipped(mMatrixValues)) {
     if (texture.hasBorder()) {
       setTextureCoords(
           1.0f / texture.getTextureWidth(),
           1.0f / texture.getTextureHeight(),
           (texture.getWidth() - 1.0f) / texture.getTextureWidth(),
           (texture.getHeight() - 1.0f) / texture.getTextureHeight());
     } else {
       setTextureCoords(
           0,
           0,
           (float) texture.getWidth() / texture.getTextureWidth(),
           (float) texture.getHeight() / texture.getTextureHeight());
     }
     textureRect(x, y, width, height);
   } else {
     // draw the rect from bottom-left to top-right
     float points[] = mapPoints(mMatrixValues, x, y + height, x + width, y);
     x = (int) (points[0] + 0.5f);
     y = (int) (points[1] + 0.5f);
     width = (int) (points[2] + 0.5f) - x;
     height = (int) (points[3] + 0.5f) - y;
     if (width > 0 && height > 0) {
       ((GL11Ext) mGL).glDrawTexiOES(x, y, 0, width, height);
       mCountTextureOES++;
     }
   }
 }
Пример #2
0
  /**
   * Draw the bitmap at a given x,y position, expressed in pixels, with the lower-left-hand-corner
   * of the view being (0,0).
   *
   * @param gl A pointer to the OpenGL context
   * @param x The number of pixels to offset this drawable's origin in the x-axis.
   * @param y The number of pixels to offset this drawable's origin in the y-axis
   * @param scaleX The horizontal scale factor between the bitmap resolution and the display
   *     resolution.
   * @param scaleY The vertical scale factor between the bitmap resolution and the display
   *     resolution.
   */
  @Override
  public void draw(float x, float y, float scaleX, float scaleY) {
    GL10 gl = OpenGLSystem.getGL();
    final Texture texture = mTexture;

    if (gl != null && texture != null) {
      assert texture.loaded;

      final float snappedX = (int) x;
      final float snappedY = (int) y;

      final float opacity = mOpacity;
      final float width = mWidth;
      final float height = mHeight;
      final float viewWidth = mViewWidth;
      final float viewHeight = mViewHeight;

      boolean cull = false;
      if (viewWidth > 0) {
        if (snappedX + width < 0.0f
            || snappedX > viewWidth
            || snappedY + height < 0.0f
            || snappedY > viewHeight
            || opacity == 0.0f
            || !texture.loaded) {
          cull = true;
        }
      }
      if (!cull) {
        OpenGLSystem.bindTexture(GL10.GL_TEXTURE_2D, texture.name);

        // This is necessary because we could be drawing the same texture with different
        // crop (say, flipped horizontally) on the same frame.
        OpenGLSystem.setTextureCrop(mCrop);

        if (opacity < 1.0f) {
          gl.glColor4f(opacity, opacity, opacity, opacity);
        }

        ((GL11Ext) gl)
            .glDrawTexfOES(
                snappedX * scaleX,
                snappedY * scaleY,
                getPriority(),
                width * scaleX,
                height * scaleY);

        if (opacity < 1.0f) {
          gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
        }
      }
    }
  }
Пример #3
0
  @Override
  public void draw(GL10 gl) {
    if (mTileBank.mTexture != null) {
      if (mTileBank.mTexture.mHWTextureID > -1) {
        if (mTileBank != null) {
          int TW = (int) (mTileBank.mTileWidth * mScale);
          int TH = (int) (mTileBank.mTileHeight * mScale);
          int ttdX = (mWidth / TW) + 1;
          int ttdY = (mHeight / TH) + 1;

          gl.glBindTexture(GL10.GL_TEXTURE_2D, mTileBank.mTexture.mHWTextureID);
          gl.glColor4f(mRed, mGreen, mBlue, mAlpha);

          for (int y = 0; y < ttdY; y++) {
            int py = y * TH - (((int) (mTop * mScale)) % TH);

            mTextureIV[3] = -mTileBank.mTileHeight; // (int) (-H/mScale); // Hcr
            for (int x = 0; x < ttdX; x++) {
              int tile = getTile(x + (int) (mLeft * mScale / TW), y + (int) (mTop * mScale / TH));
              int px = x * TW - (((int) (mLeft * mScale)) % TW);

              if ((tile >= 0) && (tile < mTileBank.mTilesCount)) {
                mTextureIV[0] =
                    (tile % mTileBank.mTilesColumns)
                        * (mTileBank.mTileWidth); // +(dx/mScale));// Ucr
                mTextureIV[1] =
                    (tile / mTileBank.mTilesColumns) * (mTileBank.mTileHeight)
                        + mTileBank.mTileHeight; // -(dy/mScale));// Vcr
                mTextureIV[2] = mTileBank.mTileWidth; // (int) (W/mScale); // Wcr
                ((GL11) gl)
                    .glTexParameteriv(
                        GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, mTextureIV, 0);
                ((GL11Ext) gl)
                    .glDrawTexfOES(
                        mPosition.mX + px,
                        AngleSurfaceView.roHeight - (mPosition.mY + py + TH),
                        mZ,
                        TW,
                        TH);
              }
            }
          }
        }
      } else mTileBank.mTexture.linkToGL(gl);
    }
    super.draw(gl);
  }
Пример #4
0
  public void drawTexture(BasicTexture texture, int x, int y, int width, int height, float alpha) {

    if (!mTexture2DEnabled) {
      mGL.glEnable(GL11.GL_TEXTURE_2D);
      mTexture2DEnabled = true;
    }

    if (!texture.bind(this, mGL)) {
      throw new RuntimeException("cannot bind" + texture.toString());
    }
    if (width <= 0 || height <= 0) return;

    Matrix matrix = mTransformation.getMatrix();
    matrix.getValues(mMatrixValues);

    // Test whether it has been rotated or flipped, if so, glDrawTexiOES
    // won't work
    if (isMatrixRotatedOrFlipped(mMatrixValues)) {
      putRectangle(
          0,
          0,
          (texture.mWidth - 0.5f) / texture.mTextureWidth,
          (texture.mHeight - 0.5f) / texture.mTextureHeight,
          mUvBuffer,
          mUvPointer);
      setAlphaValue(alpha);
      drawRect(x, y, width, height, mMatrixValues);
    } else {
      // draw the rect from bottom-left to top-right
      float points[] = mapPoints(matrix, x, y + height, x + width, y);
      x = (int) points[0];
      y = (int) points[1];
      width = (int) points[2] - x;
      height = (int) points[3] - y;
      if (width > 0 && height > 0) {
        setAlphaValue(alpha);
        ((GL11Ext) mGL).glDrawTexiOES(x, y, 0, width, height);
      }
    }
  }