Rust three_d crate. Culling does not work or am i getting things wrong?

I am trying to get the culling mechanism to work, but regardless of what culling option I choose I don’t see any difference in what is being rendered. Perhaps i am understanding culling wrong, or maybe the cause is elsewhere.

Below follows a test program using the three_d crate, in which i try to get culling to work.
The program is very simple, and pretty much only renders a cube and a triangle.

I have not bothered defining the vertices in any order, as i have implemented functionality allowing for moving the camera to look at both faces (move using w/s, also exit with ctrl+w).

In the example i try to cull both front and back sides, but this does not yield anything for me. The same goes for the other culling options, being front, back and none.
In other words, no matter the option i choose, i get the behaviour as if i choose to cull none of the sides.

use three_d::*;

pub fn main() {
    // Create a window (a canvas on web)
    let window = Window::new(WindowSettings {
        title: "Cull test!".to_string(),
        min_size: (10, 10),
        max_size: Some((1280, 720)),
        borderless: false,
        surface_settings: Default::default(),
    })
    .unwrap();

    // Get the graphics context from the window
    let context = window.gl();
    
    context.set_cull(Cull::FrontAndBack);
    
    // this is what context.set_cull() calls essentially.  
    // unsafe {
    //     //context.enable(context::CULL_FACE);
    //     context.cull_face(context::FRONT_AND_BACK);
    // }
    dbg!(&context);

    let mut camera = Camera::new_perspective(
        window.viewport(),
        vec3(0.0, 0.0, 20.0),
        vec3(0.0, 0.0, 0.0),
        vec3(0.0, 1.0, 0.0),
        degrees(45.0),
        0.1,
        1000.0,
    );

    let mut cube_trimesh = CpuMesh::cube();
    cube_trimesh.colors = Some(Vec::from([Srgba::RED; 36]));
    let cube_obj = Gm::new(Mesh::new(&context, &cube_trimesh), PhysicalMaterial::default());

    
    // Create a CPU-side mesh consisting of a single colored triangle
    let positions = vec![
        vec3(5.0, -5.0, 5.0),  // bottom right
        vec3(-5.0, -5.0, 5.0), // bottom left
        vec3(0.0, 5.0, 5.0),   // top
    ];
    dbg!(vec3(0.5, -0.5, 0.0).cross(vec3(-0.5, -0.5, 0.0)));

    let colors = vec![
        Srgba::BLUE,   // bottom right
        Srgba::BLUE, // bottom left
        Srgba::BLUE,  // top
    ];
    let mut triangle_mesh = CpuMesh {
        positions: Positions::F32(positions),
        colors: Some(colors),
        ..Default::default()
    };
    triangle_mesh.compute_normals();
    
    let blue_triangle = Gm::new(Mesh::new(&context, &triangle_mesh), PhysicalMaterial::default());

    let mut directional_light =
    renderer::light::DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(1.0, 0.0, -1.0));    
    let ambient_light = renderer::light::AmbientLight::new(&context, 0.05, Srgba::WHITE);
    // Start the main render loop
    window.render_loop(
        move |frame_input| // Begin a new frame with an updated frame input
    {
        dbg!(&context);

        // Ensure the viewport matches the current window viewport which changes if the window is resized
        camera.set_viewport(frame_input.viewport);

        directional_light.generate_shadow_map(128, &cube_obj);
        //unsafe {context.cull_face(Cull::FrontAndBack as u32);}
        for ev in &frame_input.events{          
            if let Event::KeyPress { kind, modifiers, handled: _ } =  ev {
                if *kind == Key::W && modifiers.ctrl {
                    println!("Ctrl + W pressed. Exiting application...");
                    std::process::exit(0);   
                }
                match *kind {
                    Key::W => {
                        let mut pos = camera.position().clone();
                        pos.z += 3.0;
                        let target = camera.target().clone();
                        let up = camera.up().clone();
                        camera.set_view(pos, target, up)
                    },
                    Key::S => {
                        let mut pos = camera.position().clone();
                        pos.z += -3.0;
                        let target = camera.target().clone();
                        let up = camera.up().clone();
                        camera.set_view(pos, target, up)
                    },
                    _ =>(),
                }
            }
        };
        

        // Get the screen render target to be able to render something on the screen
        frame_input.screen()
            // Clear the color and depth of the screen render target
            .clear(ClearState::color_and_depth(0.8, 0.8, 0.8, 1.0, 1.0))
            .render(
                &camera, &[&cube_obj,&blue_triangle], &[&directional_light,&ambient_light]
            );
        // Returns default frame output to end the frame
        FrameOutput::default()
    },
    );
}

Am i using the three_d crate wrongly? Or could this be a platform or hardware-specific thing? Or could it be a bug in the three_d crate?

I am on Ubuntu 22.04.4. Any help is appreciated 🙂

I think i explained this in the previous section.

New contributor

lobster is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật