
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/gloo/start_shaders.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_gallery_gloo_start_shaders.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_gloo_start_shaders.py:


Simplest Shader Program
=======================

.. GENERATED FROM PYTHON SOURCE LINES 9-58



.. image-sg:: /gallery/gloo/images/sphx_glr_start_shaders_001.png
   :alt: start shaders
   :srcset: /gallery/gloo/images/sphx_glr_start_shaders_001.png
   :class: sphx-glr-single-img





.. code-block:: default

    import sys

    from vispy import gloo
    from vispy import app
    import numpy as np

    VERT_SHADER = """
    attribute vec2 a_position;
    uniform float u_size;

    void main() {
        gl_Position = vec4(a_position, 0.0, 1.0);
        gl_PointSize = u_size;
    }
    """

    FRAG_SHADER = """
    void main() {
        gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
    }
    """


    class Canvas(app.Canvas):
        def __init__(self):
            app.Canvas.__init__(self, keys='interactive')

            ps = self.pixel_scale

            self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
            data = np.random.uniform(-0.5, 0.5, size=(20, 2))
            self.program['a_position'] = data.astype(np.float32)
            self.program['u_size'] = 20.*ps

            self.show()

        def on_resize(self, event):
            width, height = event.size
            gloo.set_viewport(0, 0, width, height)

        def on_draw(self, event):
            gloo.clear('white')
            self.program.draw('points')


    if __name__ == '__main__':
        canvas = Canvas()
        if sys.flags.interactive != 1:
            app.run()


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  0.462 seconds)


.. _sphx_glr_download_gallery_gloo_start_shaders.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download sphx-glr-download-python

     :download:`Download Python source code: start_shaders.py <start_shaders.py>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: start_shaders.ipynb <start_shaders.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
