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

.. only:: html

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

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

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

.. _sphx_glr_gallery_gloo_display_shape.py:


Draw a Quad
===========

Simple example demonstrating showing a quad using a gloo Program.

.. GENERATED FROM PYTHON SOURCE LINES 11-65



.. image-sg:: /gallery/gloo/images/sphx_glr_display_shape_001.png
   :alt: display shape
   :srcset: /gallery/gloo/images/sphx_glr_display_shape_001.png
   :class: sphx-glr-single-img





.. code-block:: default


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

    # Create vertices
    vPosition = np.array([[-0.8, -0.8, 0.0], [+0.7, -0.7, 0.0],
                          [-0.7, +0.7, 0.0], [+0.8, +0.8, 0.0, ]], np.float32)


    VERT_SHADER = """ // simple vertex shader
    attribute vec3 a_position;
    void main (void) {
        gl_Position = vec4(a_position, 1.0);
    }
    """

    FRAG_SHADER = """ // simple fragment shader
    uniform vec4 u_color;
    void main()
    {
        gl_FragColor = u_color;
    }
    """


    class Canvas(app.Canvas):

        def __init__(self):
            super().__init__(keys='interactive')

            # Create program
            self._program = gloo.Program(VERT_SHADER, FRAG_SHADER)

            # Set uniform and attribute
            self._program['u_color'] = 0.2, 1.0, 0.4, 1
            self._program['a_position'] = gloo.VertexBuffer(vPosition)

            gloo.set_clear_color('white')

            self.show()

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

        def on_draw(self, event):
            gloo.clear()
            self._program.draw('triangle_strip')


    if __name__ == '__main__':
        canvas = Canvas()
        app.run()


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

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


.. _sphx_glr_download_gallery_gloo_display_shape.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: display_shape.py <display_shape.py>`



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

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


.. only:: html

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

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