.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/validation/validate_blend_bg.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_validation_validate_blend_bg.py: Validate transparency with and without bg ========================================= Shows a semi-transparent square. On the left it uses a background, on the right it does not. In the latter case, there is no background to blend with, so the resulting pixels are still semi-transparent. When these final pixels are shown on screen, they are blended with a virtual black background (i.e. the alpha channel is applied), resulting in a darker appearance. The semi-transparent regions may also be blended with your desktop, if the OS and GUI library are configured to do so. .. GENERATED FROM PYTHON SOURCE LINES 16-48 .. image-sg:: /_gallery/validation/images/sphx_glr_validate_blend_bg_001.webp :alt: validate blend bg :srcset: /_gallery/validation/images/sphx_glr_validate_blend_bg_001.webp :class: sphx-glr-single-img .. code-block:: Python from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx canvas = RenderCanvas(size=(600, 600)) renderer = gfx.renderers.WgpuRenderer(canvas) geometry = gfx.plane_geometry(100, 100) plane_bg = gfx.Mesh( geometry, gfx.MeshBasicMaterial(color=(0, 0, 0, 1), alpha_mode="blend") ) plane_red = gfx.Mesh( geometry, gfx.MeshBasicMaterial(color=(0, 1, 0, 0.3), alpha_mode="blend") ) plane_bg.local.position = -50, 0, 0 plane_red.local.position = 0, 0, 10 scene = gfx.Scene() scene.add(plane_bg, plane_red) camera = gfx.OrthographicCamera(100, 100) canvas.request_draw(lambda: renderer.render(scene, camera)) if __name__ == "__main__": print(__doc__) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.196 seconds) .. _sphx_glr_download__gallery_validation_validate_blend_bg.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: validate_blend_bg.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: validate_blend_bg.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: validate_blend_bg.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_ .. only:: html Interactive example ------------------- Try this example in your browser using Pyodide. Might not work with all examples and all devices. Check the output and your browser's console for details. .. raw:: html