public void drawMesh( BasicTexture tex, int x, int y, int xyBuffer, int uvBuffer, int indexBuffer, int indexCount) { float alpha = mAlpha; if (!bindTexture(tex)) return; mGLState.setBlendEnabled(mBlendEnabled && (!tex.isOpaque() || alpha < OPAQUE_ALPHA)); mGLState.setTextureAlpha(alpha); // Reset the texture matrix. We will set our own texture coordinates // below. setTextureCoords(0, 0, 1, 1); saveTransform(); translate(x, y); mGL.glLoadMatrixf(mMatrixValues, 0); mGL.glBindBuffer(GL11.GL_ARRAY_BUFFER, xyBuffer); mGL.glVertexPointer(2, GL11.GL_FLOAT, 0, 0); mGL.glBindBuffer(GL11.GL_ARRAY_BUFFER, uvBuffer); mGL.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0); mGL.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indexBuffer); mGL.glDrawElements(GL11.GL_TRIANGLE_STRIP, indexCount, GL11.GL_UNSIGNED_BYTE, 0); mGL.glBindBuffer(GL11.GL_ARRAY_BUFFER, mBoxCoords); mGL.glVertexPointer(2, GL11.GL_FLOAT, 0, 0); mGL.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0); restoreTransform(); mCountDrawMesh++; }
public void drawTexture( BasicTexture texture, float[] mTextureTransform, int x, int y, int w, int h) { mGLState.setBlendEnabled(mBlendEnabled && (!texture.isOpaque() || mAlpha < OPAQUE_ALPHA)); if (!bindTexture(texture)) return; setTextureCoords(mTextureTransform); mGLState.setTextureAlpha(mAlpha); textureRect(x, y, w, h); }
private void drawTexture(BasicTexture texture, int x, int y, int width, int height, float alpha) { if (width <= 0 || height <= 0) return; mGLState.setBlendEnabled(mBlendEnabled && (!texture.isOpaque() || alpha < OPAQUE_ALPHA)); if (!bindTexture(texture)) return; mGLState.setTextureAlpha(alpha); drawBoundTexture(texture, x, y, width, height); }
public void drawTexture(BasicTexture texture, RectF source, RectF target) { if (target.width() <= 0 || target.height() <= 0) return; // Copy the input to avoid changing it. mDrawTextureSourceRect.set(source); mDrawTextureTargetRect.set(target); source = mDrawTextureSourceRect; target = mDrawTextureTargetRect; mGLState.setBlendEnabled(mBlendEnabled && (!texture.isOpaque() || mAlpha < OPAQUE_ALPHA)); if (!bindTexture(texture)) return; convertCoordinate(source, target, texture); setTextureCoords(source); mGLState.setTextureAlpha(mAlpha); textureRect(target.left, target.top, target.width(), target.height()); }
private void drawMixed( BasicTexture from, int toColor, float ratio, int x, int y, int width, int height, float alpha) { // change from 0 to 0.01f to prevent getting divided by zero below if (ratio <= 0.01f) { drawTexture(from, x, y, width, height, alpha); return; } else if (ratio >= 1) { fillRect(x, y, width, height, toColor); return; } mGLState.setBlendEnabled( mBlendEnabled && (!from.isOpaque() || !Utils.isOpaque(toColor) || alpha < OPAQUE_ALPHA)); final GL11 gl = mGL; if (!bindTexture(from)) return; // // The formula we want: // alpha * ((1 - ratio) * from + ratio * to) // // The formula that GL supports is in the form of: // combo * from + (1 - combo) * to * scale // // So, we have combo = alpha * (1 - ratio) // and scale = alpha * ratio / (1 - combo) // float combo = alpha * (1 - ratio); float scale = alpha * ratio / (1 - combo); // Interpolate the RGB and alpha values between both textures. mGLState.setTexEnvMode(GL11.GL_COMBINE); // Specify the interpolation factor via the alpha component of // GL_TEXTURE_ENV_COLORs. // RGB component are get from toColor and will used as SRC1 float colorScale = scale * (toColor >>> 24) / (0xff * 0xff); setTextureColor( ((toColor >>> 16) & 0xff) * colorScale, ((toColor >>> 8) & 0xff) * colorScale, (toColor & 0xff) * colorScale, combo); gl.glTexEnvfv(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_COLOR, mTextureColor, 0); gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_COMBINE_RGB, GL11.GL_INTERPOLATE); gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_COMBINE_ALPHA, GL11.GL_INTERPOLATE); gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_SRC1_RGB, GL11.GL_CONSTANT); gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_OPERAND1_RGB, GL11.GL_SRC_COLOR); gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_SRC1_ALPHA, GL11.GL_CONSTANT); gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_OPERAND1_ALPHA, GL11.GL_SRC_ALPHA); // Wire up the interpolation factor for RGB. gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_SRC2_RGB, GL11.GL_CONSTANT); gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_OPERAND2_RGB, GL11.GL_SRC_ALPHA); // Wire up the interpolation factor for alpha. gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_SRC2_ALPHA, GL11.GL_CONSTANT); gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_OPERAND2_ALPHA, GL11.GL_SRC_ALPHA); drawBoundTexture(from, x, y, width, height); mGLState.setTexEnvMode(GL11.GL_REPLACE); }