2

我有一个类可以确定是否应该通过布尔值绘制正方形。问题是,即使布尔值是假的,正方形也会保持不变。我的问题是,如果布尔值出现错误,我如何删除绘制的正方形?

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
}
4

1 回答 1

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);

清除屏幕上的所有内容。

于 2013-02-21T21:22:09.527 回答