我有一个类,用于确定是否应通过布尔值绘制正方形。问题是,即使布尔值为假,方形也会保持不变。我的问题是,如果布尔值出现错误,如何删除绘制的方块?
public void onDrawFrame(GL10 unused) {
// Draw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
// Set the camera position (View matrix)
Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
// Calculate the projection and view transformation
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
// Draw square
Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f);
// Combine the rotation matrix with the projection and camera view
Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);
if (drawObject == true) {
mSquare.draw(mMVPMatrix);
}
// Draw Square
}
答案 0 :(得分:1)
好的,我找到了答案。
创建方法:
public void clearBuffers(boolean color, boolean depth, boolean stencil) {
int bits = 0;
if (color) {
bits = GLES20.GL_COLOR_BUFFER_BIT;
}
if (depth) {
bits |= GLES20.GL_DEPTH_BUFFER_BIT;
}
if (stencil) {
bits |= GLES20.GL_STENCIL_BUFFER_BIT;
}
if (bits != 0) {
GLES20.glClear(bits);
}
}
然后用:
来调用它 clearBuffers(true, true, true);
清除屏幕上的所有内容。