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++; } } }
// This function changes the source coordinate to the texture coordinates. // It also clips the source and target coordinates if it is beyond the // bound of the texture. private void convertCoordinate(RectF source, RectF target, BasicTexture texture) { int width = texture.getWidth(); int height = texture.getHeight(); int texWidth = texture.getTextureWidth(); int texHeight = texture.getTextureHeight(); // Convert to texture coordinates source.left /= texWidth; source.right /= texWidth; source.top /= texHeight; source.bottom /= texHeight; // Clip if the rendering range is beyond the bound of the texture. float xBound = (float) width / texWidth; if (source.right > xBound) { target.right = target.left + target.width() * (xBound - source.left) / source.width(); source.right = xBound; } float yBound = (float) height / texHeight; if (source.bottom > yBound) { target.bottom = target.top + target.height() * (yBound - source.top) / source.height(); source.bottom = yBound; } }