9
$\begingroup$

How to smooth the bound of the shape? If you run the following script in blender,
you can see the Jagged Edge in that shape.

import bpy, gpu, bgl
from gpu_extras.batch import batch_for_shader

vertices = [[150, 41.52], [150, 71.52], [56, 234.39],
    [30.0, 249.4], [270, 249.4], [244.02, 234.39]]
indices = ((0, 1, 2), (0, 2, 3), (2, 3, 4), (2, 4, 5), (0, 1, 4), (1, 5, 4))

shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
batch = batch_for_shader(shader, 'TRIS', {"pos": vertices}, indices=indices)

def draw():
    # bgl.glHint(bgl.GL_POLYGON_SMOOTH_HINT, bgl.GL_NICEST)
    # bgl.glEnable(bgl.GL_BLEND)
    # bgl.glEnable(bgl.GL_POLYGON_SMOOTH)

    shader.bind()
    shader.uniform_float("color", (0, 0.5, 0.5, 1.0))
    batch.draw(shader)

bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_PIXEL')

enter image description here

So, I try some code to smooth the bound.

bgl.glHint(bgl.GL_POLYGON_SMOOTH_HINT, bgl.GL_NICEST)
bgl.glEnable(bgl.GL_BLEND)
bgl.glEnable(bgl.GL_POLYGON_SMOOTH)

But it has some gap inside. I am no idea how to fix it.

enter image description here

$\endgroup$
0

1 Answer 1

2
$\begingroup$

As far as I know (and from looking at the docs), I don't see any smoothing options for gpu module. Also note that bgl is likely to be deprecated eventually.

I know you said you'd rather not, but as my answer, I'd suggest loading an image. Ideally there would be a way to tint the image within Blender (not sure if that's the case), but if not you can create multiple icons of different colors.

$\endgroup$
1
  • 2
    $\begingroup$ It's been four years, and there still doesn't seem to be a way to set anti-aliasing with the GPU module. Such a shame... $\endgroup$
    – Midas
    Commented Jan 24 at 4:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .