Rendering order of shapes

eleven :

Is there way to handle rendering order of different shapes (vertices arrays)?

The green plane should be in front of blue ones:

enter image description here

override fun onDrawFrame(unused: GL10) {
    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT)

    Matrix.setLookAtM(
            view,
            0,
            eyeValue.x, eyeValue.y, eyeValue.z,
            0f, 0f, 0f,
            0f, 1.0f, 0.0f
    )

    Matrix.multiplyMM(mvp, 0, projection, 0, view, 0)

    shapes.forEach {
        it.onDraw(mvp)
    }
}


open fun onDraw(mvp: FloatArray) {
    program.onDrawStart()
    program.setV4(uNames.uColor, arrayColor)
    program.setV4Matrix(uNames.uMvp, mvp)
    program.drawVertexes(vertexes.buffer)
}
Rabbid76 :

You have to enable the Depth Test:

GLES30.glEnable(GLES30.GL_DEPTH_TEST)

When the depth test is enabled, then the depth buffer has to be cleared, too:

GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT | GLES30.GL_DEPTH_BUFFER_BIT)

The depth test cause that the depth of a fragment is tested against the depth which is stored in the depth buffer. If the test fails, the fragment is discarded and the target buffer stays unchanged.
By default the depth test function is GL_LESS. That causes that a fragment pass the test if it is closer to the camera then all the fragments that have been written before at the same position. Because of that the depth buffer has to be cleared at the begin of a frame.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=7351&siteId=1
Recommended