.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/validation/validate_depth_overlay1.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_depth_overlay1.py: Depth Overlay 1 =============== Example (and test) for behavior of the depth buffer w.r.t. overlays, implemented by multiple render calls. The overlay should always be on top. .. GENERATED FROM PYTHON SOURCE LINES 9-74 .. image-sg:: /_gallery/validation/images/sphx_glr_validate_depth_overlay1_001.webp :alt: validate depth overlay1 :srcset: /_gallery/validation/images/sphx_glr_validate_depth_overlay1_001.webp :class: sphx-glr-single-img .. code-block:: Python import numpy as np from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx import pylinalg as la # Create a canvas and renderer canvas = RenderCanvas(size=(500, 300)) renderer = gfx.renderers.WgpuRenderer(canvas) # Compose a scene with a 3D cube at the origin scene1 = gfx.Scene() cube1 = gfx.Mesh( gfx.box_geometry(), gfx.MeshPhongMaterial(color="#ff0"), ) rot = la.quat_from_euler((0.2, 0.3), order="XY") cube1.local.rotation = la.quat_mul(rot, cube1.local.rotation) scene1.add(cube1) # Compose a scene with a 2D square at the origin, in the xy plane scene2 = gfx.Scene() positions = np.array( [ [-1, -1, 0.0], [-1, +1, 0.0], [+1, +1, 0.0], [+1, -1, 0.0], [-1, -1, 0.0], [+1, +1, 0.0], ], np.float32, ) line2 = gfx.Line( gfx.Geometry(positions=positions * 0.5), gfx.LineMaterial( thickness=5.0, color="#f0f", depth_test=False, depth_write=False, aa=True ), ) scene2.add(line2) # Camera camera = gfx.OrthographicCamera(2, 2) scene1.add(camera.add(gfx.DirectionalLight())) def draw(): renderer.render(scene1, camera, flush=False) renderer.render(scene2, camera, flush=False) renderer.flush() canvas.request_draw(draw) if __name__ == "__main__": print(__doc__) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.140 seconds) .. _sphx_glr_download__gallery_validation_validate_depth_overlay1.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: validate_depth_overlay1.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: validate_depth_overlay1.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: validate_depth_overlay1.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