void render_gouraud(Scanline& sl, Ras& ras) { unsigned alpha = int(m_alpha.value() * 255.0); unsigned brc = 255; typedef agg::renderer_base<pixfmt> base_ren_type; #ifdef AGG_GRAY8 typedef agg::span_gouraud_gray8<> gouraud_span_gen_type; #else typedef agg::span_gouraud_rgba8<> gouraud_span_gen_type; #endif typedef agg::span_allocator<gouraud_span_gen_type::color_type> gouraud_span_alloc_type; typedef agg::renderer_scanline_u<base_ren_type, gouraud_span_gen_type> renderer_gouraud; pixfmt pf(rbuf_window()); base_ren_type ren_base(pf); gouraud_span_alloc_type span_alloc; gouraud_span_gen_type span_gen(span_alloc); renderer_gouraud ren_gouraud(ren_base, span_gen); ras.gamma(agg::gamma_linear(0.0, m_gamma.value())); double d = m_dilation.value(); // Single triangle //span_gen.colors(agg::rgba8(255, 0, 0, alpha), // agg::rgba8(0, 255, 0, alpha), // agg::rgba8(0, 0, 255, alpha)); //span_gen.triangle(m_x[0], m_y[0], m_x[1], m_y[1], m_x[2], m_y[2], d); //ras.add_path(span_gen); //ras.render(sl, ren_gouraud); // Six triangles double xc = (m_x[0] + m_x[1] + m_x[2]) / 3.0; double yc = (m_y[0] + m_y[1] + m_y[2]) / 3.0; double x1 = (m_x[1] + m_x[0]) / 2 - (xc - (m_x[1] + m_x[0]) / 2); double y1 = (m_y[1] + m_y[0]) / 2 - (yc - (m_y[1] + m_y[0]) / 2); double x2 = (m_x[2] + m_x[1]) / 2 - (xc - (m_x[2] + m_x[1]) / 2); double y2 = (m_y[2] + m_y[1]) / 2 - (yc - (m_y[2] + m_y[1]) / 2); double x3 = (m_x[0] + m_x[2]) / 2 - (xc - (m_x[0] + m_x[2]) / 2); double y3 = (m_y[0] + m_y[2]) / 2 - (yc - (m_y[0] + m_y[2]) / 2); span_gen.colors(agg::rgba8(255, 0, 0, alpha), agg::rgba8(0, 255, 0, alpha), agg::rgba8(brc, brc, brc, alpha)); span_gen.triangle(m_x[0], m_y[0], m_x[1], m_y[1], xc, yc, d); ras.add_path(span_gen); ras.render(sl, ren_gouraud); span_gen.colors(agg::rgba8(0, 255, 0, alpha), agg::rgba8(0, 0, 255, alpha), agg::rgba8(brc, brc, brc, alpha)); span_gen.triangle(m_x[1], m_y[1], m_x[2], m_y[2], xc, yc, d); ras.add_path(span_gen); ras.render(sl, ren_gouraud); span_gen.colors(agg::rgba8(0, 0, 255, alpha), agg::rgba8(255, 0, 0, alpha), agg::rgba8(brc, brc, brc, alpha)); span_gen.triangle(m_x[2], m_y[2], m_x[0], m_y[0], xc, yc, d); ras.add_path(span_gen); ras.render(sl, ren_gouraud); brc = 255-brc; span_gen.colors(agg::rgba8(255, 0, 0, alpha), agg::rgba8(0, 255, 0, alpha), agg::rgba8(brc, brc, brc, alpha)); span_gen.triangle(m_x[0], m_y[0], m_x[1], m_y[1], x1, y1, d); ras.add_path(span_gen); ras.render(sl, ren_gouraud); span_gen.colors(agg::rgba8(0, 255, 0, alpha), agg::rgba8(0, 0, 255, alpha), agg::rgba8(brc, brc, brc, alpha)); span_gen.triangle(m_x[1], m_y[1], m_x[2], m_y[2], x2, y2, d); ras.add_path(span_gen); ras.render(sl, ren_gouraud); span_gen.colors(agg::rgba8(0, 0, 255, alpha), agg::rgba8(255, 0, 0, alpha), agg::rgba8(brc, brc, brc, alpha)); span_gen.triangle(m_x[2], m_y[2], m_x[0], m_y[0], x3, y3, d); ras.add_path(span_gen); ras.render(sl, ren_gouraud); }
void render_gouraud(Scanline& sl, Ras& ras) { double alpha = m_alpha.value(); double brc = 1; typedef agg::renderer_base<pixfmt> base_ren_type; #ifdef AGG_GRAY8 typedef agg::span_gouraud_gray<color_type> span_gen_type; #else typedef agg::span_gouraud_rgba<color_type> span_gen_type; #endif typedef agg::span_allocator<color_type> span_alloc_type; pixfmt pf(rbuf_window()); base_ren_type ren_base(pf); span_alloc_type span_alloc; span_gen_type span_gen; ras.gamma(agg::gamma_linear(0.0, m_gamma.value())); double d = m_dilation.value(); // Single triangle //span_gen.colors(agg::rgba(1, 0, 0, alpha), // agg::rgba(0, 1, 0, alpha), // agg::rgba(0, 0, 1, alpha)); //span_gen.triangle(m_x[0], m_y[0], m_x[1], m_y[1], m_x[2], m_y[2], d); //ras.add_path(span_gen); //agg::render_scanlines_aa(ras, sl, ren_base, span_alloc, span_gen); // Six triangles double xc = (m_x[0] + m_x[1] + m_x[2]) / 3.0; double yc = (m_y[0] + m_y[1] + m_y[2]) / 3.0; double x1 = (m_x[1] + m_x[0]) / 2 - (xc - (m_x[1] + m_x[0]) / 2); double y1 = (m_y[1] + m_y[0]) / 2 - (yc - (m_y[1] + m_y[0]) / 2); double x2 = (m_x[2] + m_x[1]) / 2 - (xc - (m_x[2] + m_x[1]) / 2); double y2 = (m_y[2] + m_y[1]) / 2 - (yc - (m_y[2] + m_y[1]) / 2); double x3 = (m_x[0] + m_x[2]) / 2 - (xc - (m_x[0] + m_x[2]) / 2); double y3 = (m_y[0] + m_y[2]) / 2 - (yc - (m_y[0] + m_y[2]) / 2); span_gen.colors(agg::rgba(1, 0, 0, alpha), agg::rgba(0, 1, 0, alpha), agg::rgba(brc, brc, brc, alpha)); span_gen.triangle(m_x[0], m_y[0], m_x[1], m_y[1], xc, yc, d); ras.add_path(span_gen); agg::render_scanlines_aa(ras, sl, ren_base, span_alloc, span_gen); span_gen.colors(agg::rgba(0, 1, 0, alpha), agg::rgba(0, 0, 1, alpha), agg::rgba(brc, brc, brc, alpha)); span_gen.triangle(m_x[1], m_y[1], m_x[2], m_y[2], xc, yc, d); ras.add_path(span_gen); agg::render_scanlines_aa(ras, sl, ren_base, span_alloc, span_gen); span_gen.colors(agg::rgba(0, 0, 1, alpha), agg::rgba(1, 0, 0, alpha), agg::rgba(brc, brc, brc, alpha)); span_gen.triangle(m_x[2], m_y[2], m_x[0], m_y[0], xc, yc, d); ras.add_path(span_gen); agg::render_scanlines_aa(ras, sl, ren_base, span_alloc, span_gen); brc = 1-brc; span_gen.colors(agg::rgba(1, 0, 0, alpha), agg::rgba(0, 1, 0, alpha), agg::rgba(brc, brc, brc, alpha)); span_gen.triangle(m_x[0], m_y[0], m_x[1], m_y[1], x1, y1, d); ras.add_path(span_gen); agg::render_scanlines_aa(ras, sl, ren_base, span_alloc, span_gen); span_gen.colors(agg::rgba(0, 1, 0, alpha), agg::rgba(0, 0, 1, alpha), agg::rgba(brc, brc, brc, alpha)); span_gen.triangle(m_x[1], m_y[1], m_x[2], m_y[2], x2, y2, d); ras.add_path(span_gen); agg::render_scanlines_aa(ras, sl, ren_base, span_alloc, span_gen); span_gen.colors(agg::rgba(0, 0, 1, alpha), agg::rgba(1, 0, 0, alpha), agg::rgba(brc, brc, brc, alpha)); span_gen.triangle(m_x[2], m_y[2], m_x[0], m_y[0], x3, y3, d); ras.add_path(span_gen); agg::render_scanlines_aa(ras, sl, ren_base, span_alloc, span_gen); }