简体   繁体   中英

OpenGL blend not work and the square disappear

I have some questions about using the openGL I am newbie in using the openGL and I try to set the RGB of the square and it works but it does not work after i use the blend function. And the square finally disappear when it redraw.

The following is the part of the code

@Override
public void onDrawFrame(GL10 gl) {
    // clear Screen and Depth Buffer
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    // Reset the Modelview Matrix
    gl.glLoadIdentity();

    // Drawing
    gl.glTranslatef(0.0f, 0.0f, -5.0f);     // move 5 units INTO the screen
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    GLES20.glEnable(GLES20.GL_BLEND);                   // is the same as moving the camera 5 units away
    square.draw(gl);                        // Draw the triangle
    //square.loadGLTexture(gl, this.context);
    gl.glColor4f(red, green, blue, 0f);
    red = red - 0.01f;
    blue = blue - 0.01f;
    green = green - 0.01f;
    GLES20.glDisable(GLES20.GL_BLEND);


}

The first time onDrawFrame is called, both color and depth buffers are cleared, then a triangle is drawn and, after that, color is changed with a 0 alpha value.

Next time onDrawFrame gets called, the triangle is drawn once again but this time using the alpha value 0. Being both color and depth buffers cleared as they have been, all you probably see is an empty screen because 0 alpha, using that blend function, can be translated to "completely transparent".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM