How to use the moderngl.CULL_FACE function in moderngl

To help you get started, we’ve selected a few moderngl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github moderngl / moderngl-window / examples / gltf_scenes.py View on Github external
def render(self, time: float, frametime: float):
        """Render the scene"""
        self.ctx.enable_only(moderngl.DEPTH_TEST | moderngl.CULL_FACE)

        # Move camera in on the z axis slightly by default
        translation = Matrix44.from_translation((0, 0, -1.5), dtype='f4')
        camera_matrix = self.camera.matrix * translation

        self.scene.draw(
            projection_matrix=self.camera.projection.matrix,
            camera_matrix=camera_matrix,
            time=time,
        )
github Contraz / demosys-py / examples / system / effects.py View on Github external
def draw(self, time, frametime, target):
        # Enable depth testing and face fulling
        self.ctx.disable(moderngl.DEPTH_TEST | moderngl.CULL_FACE)
        cam_mat = self.sys_camera.view_matrix

        # Skybox
        sky_matrix = matrix44.create_from_matrix33(matrix33.create_from_matrix44(cam_mat))
        self.sky_shader['m_mv'].write(sky_matrix.astype('f4').tobytes())
        self.sky_sphere.render(self.sky_shader)

        self.ctx.enable(moderngl.DEPTH_TEST | moderngl.CULL_FACE)

        # Sun position
        self.sun_pos = cam_mat[3][0:3].astype('f4')

        # Sun
        self.sun_shader['m_mv'].write(self.sys_camera.view_matrix.astype('f4').tobytes())
        self.sun_shader['m_proj'].write(self.projection_bytes)
        self.sun_shader['time'].value = time
github Contraz / demosys-py / examples / minecraft / effects.py View on Github external
def draw(self, time, frametime, target):
        self.ctx.enable(moderngl.DEPTH_TEST)
        self.ctx.disable(moderngl.CULL_FACE)
        self.sys_camera.velocity = 10.0
        self.sampler.use(location=0)

        m_proj = self.create_projection(75, near=0.1, far=300.0)

        self.fbo.use()

        self.scene.draw(
            projection_matrix=m_proj,
            camera_matrix=self.sys_camera.view_matrix,
            time=time
        )

        self.window.use()

        self.ctx.disable(moderngl.DEPTH_TEST)
github moderngl / moderngl-window / examples / cube_model.py View on Github external
def render(self, time: float, frametime: float):
        self.ctx.enable_only(moderngl.DEPTH_TEST | moderngl.CULL_FACE)

        translation = Matrix44.from_translation((0, 0, -1.5))
        rotation = Matrix44.from_eulers((0, 0, 0))
        model_matrix = translation * rotation
        camera_matrix = self.camera.matrix * model_matrix

        self.scene.draw(
            projection_matrix=self.camera.projection.matrix,
            camera_matrix=camera_matrix,
            time=time,
        )
github airalcorn2 / strike-with-a-pose / strike_with_a_pose / scene.py View on Github external
self.PROG["dif_rgb"].value = self.MTL_INFOS[RENDER_OBJ]["Kd"]
                    if self.use_spec:
                        self.PROG["spc_rgb"].value = self.MTL_INFOS[RENDER_OBJ]["Ks"]
                        self.PROG["spec_exp"].value = self.MTL_INFOS[RENDER_OBJ]["Ns"]
                    else:
                        self.PROG["spc_rgb"].value = (0.0, 0.0, 0.0)

                    self.PROG["trans"].value = self.MTL_INFOS[RENDER_OBJ]["d"]
                    if RENDER_OBJ in self.TEXTURES:
                        self.PROG["has_image"].value = True
                        self.TEXTURES[RENDER_OBJ].use()

                self.VAOS[RENDER_OBJ].render()
                self.PROG["has_image"].value = False

            self.CTX.disable(moderngl.CULL_FACE)
github Contraz / demosys-py / demosys / deferred / renderer.py View on Github external
self.point_lights = []

        depth_texture = self.ctx.depth_texture(self.size)

        if not self.gbuffer:
            self.gbuffer = self.ctx.framebuffer(
                (
                    self.ctx.texture(self.size, 4, dtype='f1'),
                    self.ctx.texture(self.size, 3, dtype='f2'),
                ),
                depth_attachment=depth_texture,
            )

        self.gbuffer_scope = self.ctx.scope(
            self.gbuffer,
            enable_only=moderngl.DEPTH_TEST | moderngl.CULL_FACE
        )

        if not self.lightbuffer:
            self.lightbuffer = self.ctx.framebuffer(
                self.ctx.texture(self.size, 4),
            )

        self.lightbuffer_scope = self.ctx.scope(
            self.lightbuffer,
            enable_only=moderngl.BLEND | moderngl.CULL_FACE
        )

        # Unit cube for point lights (cube with radius 1.0)
        self.unit_cube = geometry.cube(width=2, height=2, depth=2)
        self.point_light_shader = resources.shaders.get("deferred/light_point.glsl", create=True)
github moderngl / moderngl-window / examples / cube_simple.py View on Github external
def render(self, time: float, frametime: float):
        self.ctx.enable_only(moderngl.CULL_FACE | moderngl.DEPTH_TEST)

        m_rot = Matrix44.from_eulers(Vector3((time, time, time)))
        m_trans = matrix44.create_from_translation(Vector3((0.0, 0.0, -3.0)))
        m_mv = matrix44.multiply(m_rot, m_trans)

        self.prog['m_mv'].write(m_mv.astype('f4').tobytes())
        self.cube.render(self.prog, mode=moderngl.TRIANGLES)
github Contraz / demosys-py / examples / geocubes / effects.py View on Github external
def draw(self, time, frametime, target):
        self.ctx.enable(mgl.DEPTH_TEST)
        self.ctx.enable(mgl.CULL_FACE)

        mv_m = self.create_transformation(rotation=(time * 1.2, time * 2.1, time * 0.25),
                                          translation=(0.0, 0.0, -8.0))
        normal_m = self.create_normal_matrix(mv_m)
        proj_m = self.create_projection(fov=60.0, aspect_ratio=1.0)

        self.fbo.use()

        self.cube_prog1["m_proj"].write(proj_m.astype('f4').tobytes())
        self.cube_prog1["m_mv"].write(mv_m.astype('f4').tobytes())
        self.cube_prog1["m_normal"].write(normal_m.astype('f4').tobytes())
        self.texture1.use(location=0)
        self.texture2.use(location=1)
        self.cube_prog1["texture0"].value = 0
        self.cube_prog1["texture1"].value = 1
        self.cube_prog1["time"].value = time
github airalcorn2 / strike-with-a-pose / paper_code / renderer.py View on Github external
def render(self):
        if self.background is not None:
            # See: https://computergraphics.stackexchange.com/a/4007.
            self.ctx.disable(moderngl.DEPTH_TEST)
            self.prog["mode"].value = 1
            self.background.use()
            self.fbo.clear()
            self.background_vao.render()

            self.ctx.enable(moderngl.DEPTH_TEST)
            self.prog["mode"].value = 0
        else:
            self.fbo.clear(R, G, B)

        if self.cull_faces:
            self.ctx.enable(moderngl.CULL_FACE)

        for render_obj in self.render_objs:
            if self.prog["use_texture"].value:
                self.prog["amb_rgb"].value = self.mtl_infos[render_obj]["Ka"]
                self.prog["dif_rgb"].value = self.mtl_infos[render_obj]["Kd"]
                if self.use_spec:
                    self.prog["spc_rgb"].value = self.mtl_infos[render_obj]["Ks"]
                    self.prog["spec_exp"].value = self.mtl_infos[render_obj]["Ns"]
                else:
                    self.prog["spc_rgb"].value = (0.0, 0.0, 0.0)

                self.prog["trans"].value = self.mtl_infos[render_obj]["d"]
                if render_obj in self.textures:
                    self.prog["has_image"].value = True
                    self.textures[render_obj].use()
github moderngl / moderngl-window / examples / advanced / tetrahedral_mesh.py View on Github external
def render(self, time, frametime):

        # Render background
        self.ctx.wireframe = False
        if not self.with_blending:
            self.ctx.enable_only(moderngl.NOTHING)
            self.quad_fs.render(self.prog_background)

        # Handle blend mode toggle
        if self.with_blending:
            self.ctx.enable_only(moderngl.BLEND)
            self.ctx.blend_func = moderngl.ONE, moderngl.ONE
        else:
            self.ctx.enable_only(moderngl.DEPTH_TEST | moderngl.CULL_FACE)

        # Render tetrahedral mesh
        translate = Matrix44.from_translation((0.0, 2.5, -15.0), dtype='f4')
        rotate = Matrix44.from_eulers((np.radians(180), 0, 0), dtype='f4')
        scale = Matrix44.from_scale((400, 400, 400), dtype='f4')
        mat = self.camera.matrix * translate * rotate * scale

        # All render calls inside this context are timed
        with self.query:
            self.alive_texture.use(location=0)
            self.prog_gen_tetra['alive_texture'].value = 0
            self.prog_gen_tetra['threshold'].value = self.threshold
            self.prog_gen_tetra['color'].value = self.mesh_color
            self.prog_gen_tetra['m_cam'].write(mat)
            self.prog_gen_tetra['m_proj'].write(self.camera.projection.matrix)
            self.geometry.render(self.prog_gen_tetra, mode=moderngl.LINES_ADJACENCY)