Esempio n. 1
0
            public styles_gouraud(mesh_ctrl mesh, GammaLut gamma)
            {
                uint i;

                for (i = 0; i < mesh.num_triangles(); i++)
                {
                    mesh_triangle t  = mesh.triangle(i);
                    mesh_point    p1 = mesh.vertex(t.p1);
                    mesh_point    p2 = mesh.vertex(t.p2);
                    mesh_point    p3 = mesh.vertex(t.p3);

                    RGBA_Bytes c1 = p1.color;
                    RGBA_Bytes c2 = p2.color;
                    RGBA_Bytes c3 = p3.color;
                    c1.ApplyGammaDir(gamma);
                    c2.ApplyGammaDir(gamma);
                    c3.ApplyGammaDir(gamma);
                    SpanGouraudRgba <T> gouraud = new SpanGouraudRgba <T>(c1, c2, c3,
                                                                          p1.x, p1.y,
                                                                          p2.x, p2.y,
                                                                          p3.x, p3.y);
                    gouraud.Prepare();
                    m_triangles.Add(gouraud);
                }
            }
Esempio n. 2
0
        //template<class Scanline, class Ras>
        public void render_gouraud(IScanlineCache sl, IRasterizer <T> ras)
        {
            T alpha = m_alpha.value();
            T brc   = M.One <T>();

#if SourceDepth24
            pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr());
#else
            FormatRGBA pf = new FormatRGBA(rbuf_window(), new BlenderBGRA());
#endif
            FormatClippingProxy ren_base = new FormatClippingProxy(pf);

            AGG.SpanAllocator   span_alloc = new SpanAllocator();
            SpanGouraudRgba <T> span_gen   = new SpanGouraudRgba <T>();

            ras.Gamma(new GammaLinear(0.0, m_gamma.value().ToDouble()));

            T d = m_dilation.value();

            // Six triangles
            T xc = m_x[0].Add(m_x[1]).Add(m_x[2]).Divide(3.0);
            T yc = m_y[0].Add(m_y[1]).Add(m_y[2]).Divide(3.0);

            T x1 = m_x[1].Add(m_x[0]).Divide(2).Subtract(xc.Subtract(m_x[1].Add(m_x[0]).Divide(2)));
            T y1 = m_y[1].Add(m_y[0]).Divide(2).Subtract(yc.Subtract(m_y[1].Add(m_y[0]).Divide(2)));

            T x2 = m_x[2].Add(m_x[1]).Divide(2).Subtract(xc.Subtract(m_x[2].Add(m_x[1]).Divide(2)));
            T y2 = m_y[2].Add(m_y[1]).Divide(2).Subtract(yc.Subtract(m_y[2].Add(m_y[1]).Divide(2)));

            T x3 = m_x[0].Add(m_x[2]).Divide(2).Subtract(xc.Subtract(m_x[0].Add(m_x[2]).Divide(2)));
            T y3 = m_y[0].Add(m_y[2]).Divide(2).Subtract(yc.Subtract(m_y[0].Add(m_y[2]).Divide(2)));

            span_gen.Colors(new RGBA_Doubles(1, 0, 0, alpha.ToDouble()),
                            new RGBA_Doubles(0, 1, 0, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[0], m_y[0], m_x[1], m_y[1], xc, yc, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            span_gen.Colors(new RGBA_Doubles(0, 1, 0, alpha.ToDouble()),
                            new RGBA_Doubles(0, 0, 1, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[1], m_y[1], m_x[2], m_y[2], xc, yc, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            span_gen.Colors(new RGBA_Doubles(0, 0, 1, alpha.ToDouble()),
                            new RGBA_Doubles(1, 0, 0, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[2], m_y[2], m_x[0], m_y[0], xc, yc, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            brc = M.One <T>().Subtract(brc);
            span_gen.Colors(new RGBA_Doubles(1, 0, 0, alpha.ToDouble()),
                            new RGBA_Doubles(0, 1, 0, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[0], m_y[0], m_x[1], m_y[1], x1, y1, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            span_gen.Colors(new RGBA_Doubles(0, 1, 0, alpha.ToDouble()),
                            new RGBA_Doubles(0, 0, 1, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[1], m_y[1], m_x[2], m_y[2], x2, y2, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            span_gen.Colors(new RGBA_Doubles(0, 0, 1, alpha.ToDouble()),
                            new RGBA_Doubles(1, 0, 0, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[2], m_y[2], m_x[0], m_y[0], x3, y3, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);
        }