Code example for Matrix

Methods: postScale, postTranslate, preRotate, reset

0
		paint.setTypeface(Typeface.MONOSPACE);
		paint.setFakeBoldText(true);
		paint.setColor(0xFF2040A0);
		paint.setTextSize(32);
		setTextureText("world ", paint, mTextureIds[0], mMatrixBackground);
		mMatrixBackground.postScale(8, 8f * height / width);
		mMatrixBackground.preRotate(-35);
 
		// Generate foreground texture. 
		paint.setColor(0xFFA05030);
		paint.setTextSize(128);
		setTextureText("hello", paint, mTextureIds[1], mMatrixForeground);
		mMatrixForeground.postScale(1f, (float) height / width);
	} 
 
	@Override 
	public void onSurfaceCreated(GL10 unused, EGLConfig config) {
		// Check if shader compiler is supported. 
		GLES20.glGetBooleanv(GLES20.GL_SHADER_COMPILER, mShaderCompilerSupport,
				0); 
 
		// If not, show user an error message and return immediately. 
		if (!mShaderCompilerSupport[0]) {
			String msg = getContext().getString(R.string.error_shader_compiler);
			showError(msg);
			return; 
		} 
 
		try { 
			String vertexSource, fragmentSource;
			vertexSource = loadRawString(R.raw.textures_vs);
			fragmentSource = loadRawString(R.raw.textures_fs);
			mShaderTextures.setProgram(vertexSource, fragmentSource);
		} catch (Exception ex) {
			showError(ex.getMessage());
		} 
	} 
 
	/** 
	 * Updates texture with given values plus alters matrix. 
	 */ 
	private void setTextureText(String text, Paint paint, int textureId,
			Matrix matrix) {
		int width = (int) (paint.measureText(text) + 2.5f);
		int height = (int) (paint.descent() - paint.ascent() + 2.5f);
 
		Bitmap bitmap = Bitmap.createBitmap(width, height,
				Bitmap.Config.ARGB_8888);
 
		final Canvas canvas = new Canvas();
		canvas.setBitmap(bitmap);
		canvas.drawColor(Color.TRANSPARENT);
		canvas.drawText(text, 1, 1 - paint.ascent(), paint);
 
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
		GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
		bitmap.recycle();
 
		matrix.reset();
		matrix.postScale(0.5f, -0.5f * width / height);
		matrix.postTranslate(0.5f, 0.5f);
	} 
 
	/** 
	 * Transpose 3x3 matrix in place. 
	 */