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

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_gallery_gloo_colored_quad.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_gloo_colored_quad.py:


Show color quad Image
=====================

Create a new drawing using triangle_strip

.. GENERATED FROM PYTHON SOURCE LINES 17-69



.. image-sg:: /gallery/gloo/images/sphx_glr_colored_quad_001.png
   :alt: colored quad
   :srcset: /gallery/gloo/images/sphx_glr_colored_quad_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


    from vispy import app, gloo
    from vispy.gloo import Program

    vertex = """
        attribute vec4 color;
        attribute vec2 position;
        varying vec4 v_color;
        void main()
        {
            gl_Position = vec4(position, 0.0, 1.0);
            v_color = color;
        } """

    fragment = """
        varying vec4 v_color;
        void main()
        {
            gl_FragColor = v_color;
        } """


    class Canvas(app.Canvas):
        def __init__(self):
            super().__init__(size=(512, 512), title='Colored quad',
                             keys='interactive')

            # Build program
            self.program = Program(vertex, fragment, count=4)

            # Set uniforms and attributes
            self.program['color'] = [(1, 0, 0, 1), (0, 1, 0, 1),
                                     (0, 0, 1, 1), (1, 1, 0, 1)]
            self.program['position'] = [(-1, -1), (-1, +1),
                                        (+1, -1), (+1, +1)]

            gloo.set_viewport(0, 0, *self.physical_size)

            self.show()

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

        def on_resize(self, event):
            gloo.set_viewport(0, 0, *event.physical_size)


    c = Canvas()

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


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

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


.. _sphx_glr_download_gallery_gloo_colored_quad.py:

.. only:: html

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

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

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

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

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: colored_quad.zip <colored_quad.zip>`


.. only:: html

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

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