当前位置: 动力学知识库 > 问答 > 编程问答 >

opengl es - how to draw text on GLSurfaceView android?

问题描述:

I try refer by Draw text in OpenGL ES

I want draw text on camera preview glsurfaceview.

To draw text, use Bitmap.

so I add method GLText(GL10 gl)

and

GLText(GL10 gl)call onDrawFrame(GL10 gl)

onDrawFrame(GL10 gl) is Called to draw the current frame. so, always execute.

and GLText(GL10 gl) source

 Bitmap bitmap = Bitmap.createBitmap(64, 64, Bitmap.Config.ARGB_4444);

Canvas canvas = new Canvas(bitmap);

bitmap.eraseColor(0);

Paint paint = new Paint();

paint.setTextSize(18);

paint.setAntiAlias(true);

paint.setARGB(0xff, 0xff, 0xff, 0xff);

paint.setTextAlign(Paint.Align.LEFT);

paint.setTextScaleX(0.5f);

canvas.drawText("testGLText", 0.f, 15.f, paint);

GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

bitmap.recycle();

and I try build

this picture show draw text, but background color green.

so, and I modified GLText(GL10 gl)

 Bitmap bitmap = Bitmap.createBitmap(64, 64, Bitmap.Config.ARGB_4444);

Canvas canvas = new Canvas(bitmap);

bitmap.eraseColor(0);

Paint paint = new Paint();

paint.setTextSize(18);

paint.setAntiAlias(true);

paint.setARGB(0xff, 0xff, 0xff, 0xff);

paint.setTextAlign(Paint.Align.LEFT);

paint.setTextScaleX(0.5f);

canvas.drawText("testGLText", 0.f, 15.f, paint);

int[] mTextures = new int[1];

gl.glGenTextures(1, mTextures, 0);

gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextures[0]);

gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST );

gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR );

gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT );

gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT );

GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

bitmap.recycle();

and I try build

this picture not draw text. but clean background color.

in other words , I want clean background and draw text.

how to I draw text on glsurface android?

thanks.

分享给朋友:
您可能感兴趣的文章:
随机阅读: