.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/gloo/geometry_shader.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_gloo_geometry_shader.py: Use a Geometry Shader ===================== Simple geometry shader: Takes one point as input emits one triangle as output. NOTE: This example is currently not processed in CI. .. GENERATED FROM PYTHON SOURCE LINES 15-95 .. image-sg:: /gallery/gloo/images/sphx_glr_geometry_shader_001.png :alt: geometry shader :srcset: /gallery/gloo/images/sphx_glr_geometry_shader_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np from vispy import gloo from vispy import app # geometry shaders require full OpenGL namespace provided by PyOpenGL gloo.gl.use_gl('gl+') position = np.random.normal(loc=0, scale=0.3, size=(1000, 2)).astype('float32') VERT_SHADER = """ #version 330 in vec2 a_position; void main (void) { gl_Position = vec4(a_position, 0, 1); gl_PointSize = 3.0; } """ GEOM_SHADER = """ #version 330 layout (points) in; layout (triangle_strip, max_vertices=3) out; void main(void) { vec4 p = gl_in[0].gl_Position; gl_Position = p; EmitVertex(); gl_Position = p + vec4(0.06, 0.03, 0, 0); EmitVertex(); gl_Position = p + vec4(0.03, 0.06, 0, 0); EmitVertex(); EndPrimitive(); } """ FRAG_SHADER = """ #version 330 out vec4 frag_color; void main() { frag_color = vec4(0,0,0,0.5); } """ class Canvas(app.Canvas): def __init__(self): app.Canvas.__init__(self, keys='interactive', size=(400, 400)) self.program = gloo.Program() self.program.set_shaders(vert=VERT_SHADER, geom=GEOM_SHADER, frag=FRAG_SHADER) self.program['a_position'] = gloo.VertexBuffer(position) gloo.set_viewport(0, 0, self.physical_size[0], self.physical_size[1]) self.context.set_clear_color('white') self.context.set_state('translucent', cull_face=False, depth_test=False) self.show() def on_resize(self, event): gloo.set_viewport(0, 0, event.physical_size[0], event.physical_size[1]) def on_draw(self, event): self.context.clear() self.program.draw('points') if __name__ == '__main__': canvas = Canvas() app.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.448 seconds) .. _sphx_glr_download_gallery_gloo_geometry_shader.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: geometry_shader.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: geometry_shader.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: geometry_shader.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_