render

Function render 

Source
pub fn render<Prim, Vtx: Clone, Var, Uni: Copy, Shd>(
    prims: impl AsRef<[Prim]>,
    verts: impl AsRef<[Vtx]>,
    shader: &Shd,
    uniform: Uni,
    to_screen: Mat4x4<NdcToScreen>,
    target: &mut impl Target,
    ctx: &Context,
)
where Prim: Render<Var> + Clone, [Prim::Clip]: Clip<Item = Prim::Clip>, Var: Vary, Shd: Shader<Vtx, Var, Uni>,
Expand description

Renders the given primitives into target.

Examples found in repository?
examples/hello_tri.rs (lines 37-45)
4fn main() {
5    let verts = [
6        vertex(pt3(-1.0, 1.0, 0.0), rgb(1.0, 0.0, 0.0)),
7        vertex(pt3(1.0, 1.0, 0.0), rgb(0.0, 0.8, 0.0)),
8        vertex(pt3(0.0, -1.0, 0.0), rgb(0.4, 0.4, 1.0)),
9    ];
10
11    #[cfg(feature = "fp")]
12    let shader = shader::new(
13        |v: Vertex3<Color3f>, mvp: &Mat4x4<ModelToProj>| {
14            // Transform vertex position from model to projection space
15            // Interpolate vertex colors in linear color space
16            vertex(mvp.apply(&v.pos), v.attrib.to_linear())
17        },
18        |frag: Frag<Color3f<_>>| frag.var.to_srgb().to_color4(),
19    );
20    #[cfg(not(feature = "fp"))]
21    let shader = shader::new(
22        |v: Vertex3<Color3f>, mvp: &Mat4x4<ModelToProj>| {
23            // Transform vertex position from model to projection space
24            // Interpolate vertex colors in normal sRGB color space
25            vertex(mvp.apply(&v.pos), v.attrib)
26        },
27        |frag: Frag<Color3f<_>>| frag.var.to_color4(),
28    );
29
30    let dims @ (w, h) = (640, 480);
31    let modelview = translate3(0.0, 0.0, 2.0).to();
32    let project = perspective(1.0, w as f32 / h as f32, 0.1..1000.0);
33    let viewport = viewport(pt2(0, h)..pt2(w, 0));
34
35    let mut framebuf = Buf2::<Color4>::new(dims);
36
37    render(
38        [tri(0, 1, 2)],
39        verts,
40        &shader,
41        &modelview.then(&project),
42        viewport,
43        &mut framebuf,
44        &Context::default(),
45    );
46
47    let center_pixel = framebuf[[w / 2, h / 2]];
48
49    if cfg!(feature = "fp") {
50        assert_eq!(center_pixel, rgba(150, 128, 186, 255));
51    } else {
52        assert_eq!(center_pixel, rgba(114, 102, 127, 255));
53    }
54    #[cfg(feature = "std")]
55    {
56        pnm::save_ppm("triangle.ppm", framebuf).unwrap();
57    }
58}