Reputation: 401
I want draw square and draw Text on GLSurfaceView camera preview.
first I try draw square
private void drawSquare() {
GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
GLES20.glScissor(20, 300, 500, 50);
GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
this method call on onDrawFrame(); and show square on camera preview glsurfaceview.
and I try draw Text
public void 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);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
}
and show text. but backgroud color green
why background color green? please help for me.
thanks.
Upvotes: 1
Views: 1198
Reputation: 1066
I don't see your code drawing texts using openGL api but there is no reason to set your fbo green.
GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
GLES20.glScissor(20, 300, 500, 50);
GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f); // here you initialize your fbo color as black
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
If you want to draw a square, follow these steps below.
glclearcolor(...); //Actually, glclearColor() and glclear() are not required.
glclear();
glviewport(....);
gluseprogram() // a shader program you compiled
bindVBO() // VBO you already set in this case, it saves four vertices
glactivetexture() and bindtexture()
gluniform1f(..) // for the texture
gldrawarray(...) or gldrawelement(...)
Upvotes: 1