Skip to content

How to show mesh using bgl with proper occulsion/depth? #1772

Answered by OmarEmaraDev
harisreedhar asked this question in Q&A
Discussion options

You must be logged in to vote

@harisreedhar What you are looking for is called Depth Testing in OpenGL. In its most basic form, you just need to enable it before drawing then disable it after drawing like this:

        glEnable(GL_DEPTH_TEST)

        shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
        batch = batch_for_shader(shader, 'TRIS', {"pos": _vertices, "color": colors}, indices=_polygons)
        shader.bind()
        batch.draw(shader)

        glDisable(GL_DEPTH_TEST)

I haven't tested this, but it should work. There are other states you can play with, mentioned in the aforementioned article .

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@harisreedhar
Comment options

Comment options

You must be logged in to vote
1 reply
@harisreedhar
Comment options

Answer selected by harisreedhar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants