0

This is an example that I referred to : https://github.com/vispy/vispy/blob/d7763448dd398e5dab91cc21db7378c1aa707c63/vispy/visuals/line/line.py#L273

class _GlPoint(Visual):
    VERTEX_SHADER = """
        #version 120
        varying vec4 v_color;

        void main()
        {
            gl_Position = $transform($to_vec4($position));
            gl_PointSize = 12;
            v_color = $color;

        }
    """

    FRAGMENT_SHADER = """
        #version 120
        varying vec4 v_color;

        void main()
        {
            gl_FragColor = v_color;
        }
    """

    def __init__(self, parent):
        self._parent = parent
        self._pos_vbo = gloo.VertexBuffer()
        self._color_vbo = gloo.VertexBuffer()

        Visual.__init__(self, vcode=self.VERTEX_SHADER, fcode=self.FRAGMENT_SHADER, gcode=None)

        self._draw_mode = 'points'
        self._connect   = 'segments'

        self.freeze()

    def _prepare_transforms(self, view):
        xform = view.transforms.get_transform()
        view.view_program.vert['transform'] = xform

    def _prepare_draw(self, view):
        if self._parent._changed['pos']:
            if self._parent._pos is None or len(self._parent._pos) == 0:
                return False

            pos = self._parent._point
            self._pos_vbo.set_data(pos)                                                                      

            self._program.vert['to_vec4'] = vec2to4
            
            self._color_vbo.set_data(self._parent._pointColor)
            self._program.vert['color'] = self._color_vbo

There are 2 inputs: self._parent._point is an (n, 2) array that corresponds to X, Y coordinates. self._parent._pointColor is an (n, 4) array that corresponds to the colors of the points.

It works fine when I set gl_PointSize as a fixed number. My question is how to use another array to set different point sizes. I looked into Visual/Markers but it uses just one VertexBuffer, which is different from Visual/Lines, so I'm more confused. If it's not so complicated, could anyone show me how it can be done?

maynull
  • 1,936
  • 4
  • 26
  • 46
  • 1
    Is there a reason you aren't using a MarkersVisual directly? Why does it matter if `MarkersVisual` implements this as a single buffer array if you, the user, can pass an array for the size? Or do you plan on customizing the shape of the point/marker? I would highly recommend using existing vispy Visuals whenever possible. Even if you are planning on customizing the shape of the point I would still recommend subclassing the MarkersVisual and possibly contributing the new shape back to vispy in the future. – djhoese Apr 26 '23 at 14:27
  • Thank you for your help! I'm new to Vispy, so I thought that it would be less confusing if I stick to just one Visual. Thanks to your advice, I was able to make a new CompoundVisual with MarkersVisual. Thank you again! – maynull Apr 27 '23 at 00:26

0 Answers0