Пример #1
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);
        }
      }
    }
  }
Пример #2
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);
  }