2

正方形をブール値で描画するかどうかを決定するクラスがあります。問題は、ブール値が false の場合でも正方形がそのまま残ることです。私の質問は、ブール値が false になった場合に、描かれた正方形をどのように削除するのですか?

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 に答える