the_application(agg::pix_format_e format, bool flip_y) : agg::platform_support(format, flip_y), m_feng(), m_fman(m_feng), m_poly1(6, 5.0), m_poly2(6, 5.0), m_num_points (5.0, 5.0, 340.0, 12.0, !flip_y), m_fixed_len (350, 5.0, "Fixed Length", !flip_y), m_preserve_x_scale(465, 5.0, "Preserve X scale", !flip_y), m_animate (350, 25.0, "Animate", !flip_y), m_prev_animate(false) { add_ctrl(m_fixed_len); add_ctrl(m_preserve_x_scale); add_ctrl(m_animate); m_fixed_len.status(true); m_preserve_x_scale.status(true); m_num_points.range(10.0, 400.0); m_num_points.value(200.0); m_num_points.label("Number of intermediate Points = %.3f"); add_ctrl(m_num_points); m_poly1.close(false); m_poly2.close(false); }
virtual void on_mouse_button_up(int x, int y, unsigned flags) { if(m_quad1.on_mouse_button_up(x, y) || m_quad2.on_mouse_button_up(x, y) ) { force_redraw(); } }
virtual void on_idle() { int i; for(i = 0; i < 6; i++) { move_point(m_poly.xn(i), m_poly.yn(i), m_dx[i], m_dy[i]); } force_redraw(); }
virtual void on_idle() { int i; for(i = 0; i < 6; i++) { move_point(m_poly1.xn(i), m_poly1.yn(i), m_dx1[i], m_dy1[i]); move_point(m_poly2.xn(i), m_poly2.yn(i), m_dx2[i], m_dy2[i]); normalize_point(i); } force_redraw(); }
virtual void on_mouse_button_down(int x, int y, unsigned flags) { if(flags & agg::mouse_left) { if(m_quad1.on_mouse_button_down(x, y) || m_quad2.on_mouse_button_down(x, y) ) { force_redraw(); } } }
virtual void on_mouse_button_up(int x, int y, unsigned flags) { if(m_poly1.on_mouse_button_up(x, y)) { force_redraw(); } if(m_poly2.on_mouse_button_up(x, y)) { force_redraw(); } }
virtual void on_init() { g_x1 = 0.0; g_y1 = 0.0; g_x2 = rbuf_img(0).width(); g_y2 = rbuf_img(0).height(); double x1 = g_x1;// * 100.0; double y1 = g_y1;// * 100.0; double x2 = g_x2;// * 100.0; double y2 = g_y2;// * 100.0; double dx = width() / 2.0 - (x2 - x1) / 2.0; double dy = height() / 2.0 - (y2 - y1) / 2.0; m_quad.xn(0) = floor(x1 + dx); m_quad.yn(0) = floor(y1 + dy);// - 150; m_quad.xn(1) = floor(x2 + dx); m_quad.yn(1) = floor(y1 + dy);// - 110; m_quad.xn(2) = floor(x2 + dx); m_quad.yn(2) = floor(y2 + dy);// - 300; m_quad.xn(3) = floor(x1 + dx); m_quad.yn(3) = floor(y2 + dy);// - 200; pixfmt pixf(rbuf_img(0)); pixf.apply_gamma_dir(m_gamma_lut); }
virtual void on_mouse_move(int x, int y, unsigned flags) { if(flags & agg::mouse_left) { if(m_quad1.on_mouse_move(x, y) || m_quad2.on_mouse_move(x, y) ) { force_redraw(); } } if((flags & agg::mouse_left) == 0) { on_mouse_button_up(x, y, flags); } }
virtual void on_mouse_button_down(int x, int y, unsigned flags) { if(flags & agg::mouse_left) { if(m_quad.on_mouse_button_down(x, y)) { force_redraw(); } else { start_timer(); m_test_flag = true; on_draw(); on_draw(); on_draw(); on_draw(); char buf[100]; sprintf(buf, "time=%.3f", elapsed_time()); m_test_flag = false; force_redraw(); message(buf); } } }
the_application(agg::pix_format_e format, bool flip_y) : agg::platform_support(format, flip_y), m_quad(4, 5.0), m_trans_type(420, 5.0, 420+130.0, 55.0, !flip_y) { parse_lion(); m_quad.xn(0) = g_x1; m_quad.yn(0) = g_y1; m_quad.xn(1) = g_x2; m_quad.yn(1) = g_y1; m_quad.xn(2) = g_x2; m_quad.yn(2) = g_y2; m_quad.xn(3) = g_x1; m_quad.yn(3) = g_y2; m_trans_type.add_item("Bilinear"); m_trans_type.add_item("Perspective"); m_trans_type.cur_item(0); add_ctrl(m_trans_type); }
virtual void on_init() { g_x1 = -150; g_y1 = -150; g_x2 = 150; g_y2 = 150; double trans_x1 = -200; double trans_y1 = -200; double trans_x2 = 200; double trans_y2 = 200; double dx = width() / 2.0 - (trans_x2 + trans_x1) / 2.0; double dy = height() / 2.0 - (trans_y2 + trans_y1) / 2.0; m_quad.xn(0) = floor(trans_x1 + dx); m_quad.yn(0) = floor(trans_y1 + dy); m_quad.xn(1) = floor(trans_x2 + dx); m_quad.yn(1) = floor(trans_y1 + dy); m_quad.xn(2) = floor(trans_x2 + dx); m_quad.yn(2) = floor(trans_y2 + dy); m_quad.xn(3) = floor(trans_x1 + dx); m_quad.yn(3) = floor(trans_y2 + dy); }
virtual void on_draw() { pixfmt pixf(rbuf_window()); renderer_base rb(pixf); renderer_solid r(rb); rb.clear(agg::rgba(1, 1, 1)); scanline_type sl; agg::rasterizer_scanline_aa<> ras; m_poly.close(m_close.status()); agg::simple_polygon_vertex_source path(m_poly.polygon(), m_poly.num_points(), false, m_close.status()); typedef agg::conv_bspline<agg::simple_polygon_vertex_source> conv_bspline_type; conv_bspline_type bspline(path); bspline.interpolation_step(1.0 / m_num_points.value()); agg::trans_single_path tcurve; tcurve.add_path(bspline); tcurve.preserve_x_scale(m_preserve_x_scale.status()); if(m_fixed_len.status()) tcurve.base_length(1120); typedef agg::conv_curve<font_manager_type::path_adaptor_type> conv_font_curve_type; typedef agg::conv_segmentator<conv_font_curve_type> conv_font_segm_type; typedef agg::conv_transform<conv_font_segm_type, agg::trans_single_path> conv_font_trans_type; conv_font_curve_type fcurves(m_fman.path_adaptor()); conv_font_segm_type fsegm(fcurves); conv_font_trans_type ftrans(fsegm, tcurve); fsegm.approximation_scale(3.0); fcurves.approximation_scale(2.0); m_feng.height(40.0); //m_feng.italic(true); if(m_feng.create_font("Times New Roman", agg::glyph_ren_outline)) { double x = 0.0; double y = 3.0; const char* p = text; while(*p) { const agg::glyph_cache* glyph = m_fman.glyph(*p); if(glyph) { if(x > tcurve.total_length()) break; m_fman.add_kerning(&x, &y); m_fman.init_embedded_adaptors(glyph, x, y); if(glyph->data_type == agg::glyph_data_outline) { ras.reset(); ras.add_path(ftrans); r.color(agg::rgba8(0, 0, 0)); agg::render_scanlines(ras, sl, r); } // increment pen position x += glyph->advance_x; y += glyph->advance_y; } ++p; } } typedef agg::conv_stroke<conv_bspline_type> conv_stroke_type; conv_stroke_type stroke(bspline); stroke.width(2.0); r.color(agg::rgba8(170, 50, 20, 100)); ras.add_path(stroke); agg::render_scanlines(ras, sl, r); //-------------------------- // Render the "poly" tool and controls r.color(agg::rgba(0, 0.3, 0.5, 0.3)); ras.add_path(m_poly); agg::render_scanlines(ras, sl, r); agg::render_ctrl(ras, sl, rb, m_close); agg::render_ctrl(ras, sl, rb, m_preserve_x_scale); agg::render_ctrl(ras, sl, rb, m_fixed_len); agg::render_ctrl(ras, sl, rb, m_animate); agg::render_ctrl(ras, sl, rb, m_num_points); //-------------------------- }
virtual void on_init() { m_quad1.xn(0) = 50; m_quad1.yn(0) = 200 - 20; m_quad1.xn(1) = width() / 2 - 25; m_quad1.yn(1) = 200; m_quad1.xn(2) = width() / 2 - 25; m_quad1.yn(2) = height() - 50 - 20; m_quad1.xn(3) = 50; m_quad1.yn(3) = height() - 50; m_quad2.xn(0) = width() / 2 + 25; m_quad2.yn(0) = 200 - 20; m_quad2.xn(1) = width() - 50; m_quad2.yn(1) = 200; m_quad2.xn(2) = width() - 50; m_quad2.yn(2) = height() - 50 - 20; m_quad2.xn(3) = width() / 2 + 25; m_quad2.yn(3) = height() - 50; }
void normalize_point(unsigned i) { double d = agg::calc_distance(m_poly1.xn(i), m_poly1.yn(i), m_poly2.xn(i), m_poly2.yn(i)); // 28.8 is 20 * sqrt(2) if(d > 28.28) { m_poly2.xn(i) = m_poly1.xn(i) + (m_poly2.xn(i) - m_poly1.xn(i)) * 28.28 / d; m_poly2.yn(i) = m_poly1.yn(i) + (m_poly2.yn(i) - m_poly1.yn(i)) * 28.28 / d; } }
virtual void on_draw() { pixfmt pixf(rbuf_window()); renderer_base rb(pixf); renderer_solid r(rb); rb.clear(agg::rgba(1, 1, 1)); scanline_type sl; agg::rasterizer_scanline_aa<> ras; agg::rasterizer_scanline_aa<> ras1; agg::rasterizer_scanline_aa<> ras2; agg::sbool_op_e op = (agg::sbool_op_e)m_trans_type.cur_item(); ras1.gamma(agg::gamma_multiply(m_mul1.value())); ras2.gamma(agg::gamma_multiply(m_mul2.value())); ras.clip_box(0, 0, width(), height()); agg::path_storage ps1; generate_circles(ps1, m_quad1.polygon(), 5, 20); agg::path_storage ps2; generate_circles(ps2, m_quad2.polygon(), 5, 20); ras1.filling_rule(agg::fill_even_odd); r.color(agg::rgba8(240, 255, 200, 100)); ras1.add_path(ps1); agg::render_scanlines(ras1, sl, r); r.color(agg::rgba8(255, 240, 240, 100)); ras2.add_path(ps2); agg::render_scanlines(ras2, sl, r); typedef agg::scanline_p8 sbool_scanline_type; typedef agg::renderer_scanline_aa_solid<renderer_base> sbool_renderer_type; sbool_scanline_type sl_result; sbool_scanline_type sl1; sbool_scanline_type sl2; sbool_renderer_type sren(rb); sren.color(agg::rgba8(0, 0, 0)); agg::sbool_combine_shapes_aa(op, ras1, ras2, sl1, sl2, sl_result, sren); //-------------------------- // Render the "quad" tools and controls r.color(agg::rgba(0, 0.3, 0.5, 0.6)); ras.add_path(m_quad1); agg::render_scanlines(ras, sl, r); ras.add_path(m_quad2); agg::render_scanlines(ras, sl, r); agg::render_ctrl(ras, sl, rb, m_trans_type); agg::render_ctrl(ras, sl, rb, m_reset); agg::render_ctrl(ras, sl, rb, m_mul1); agg::render_ctrl(ras, sl, rb, m_mul2); //-------------------------- }
virtual void on_draw() { pixfmt pixf(rbuf_window()); renderer_base rb(pixf); renderer_solid r(rb); rb.clear(agg::rgba(1, 1, 1)); scanline_type sl; agg::rasterizer_scanline_aa<> ras; agg::simple_polygon_vertex_source path1(m_poly1.polygon(), m_poly1.num_points(), false, false); agg::simple_polygon_vertex_source path2(m_poly2.polygon(), m_poly2.num_points(), false, false); typedef agg::conv_bspline<agg::simple_polygon_vertex_source> conv_bspline_type; conv_bspline_type bspline1(path1); conv_bspline_type bspline2(path2); bspline1.interpolation_step(1.0 / m_num_points.value()); bspline2.interpolation_step(1.0 / m_num_points.value()); typedef agg::conv_curve<font_manager_type::path_adaptor_type> conv_font_curve_type; typedef agg::conv_segmentator<conv_font_curve_type> conv_font_segm_type; typedef agg::conv_transform<conv_font_segm_type, agg::trans_double_path> conv_font_trans_type; agg::trans_double_path tcurve; conv_font_curve_type fcurves(m_fman.path_adaptor()); conv_font_segm_type fsegm(fcurves); conv_font_trans_type ftrans(fsegm, tcurve); tcurve.preserve_x_scale(m_preserve_x_scale.status()); if(m_fixed_len.status()) tcurve.base_length(1140.0); tcurve.base_height(30.0); tcurve.add_paths(bspline1, bspline2); fsegm.approximation_scale(3.0); fcurves.approximation_scale(5.0); if(m_feng.load_font(full_file_name("timesi.ttf"), 0, agg::glyph_ren_outline)) { double x = 0.0; double y = 3.0; const char* p = text; m_feng.hinting(false); m_feng.height(40); while(*p) { const agg::glyph_cache* glyph = m_fman.glyph(*p); if(glyph) { if(x > tcurve.total_length1()) break; m_fman.add_kerning(&x, &y); m_fman.init_embedded_adaptors(glyph, x, y); if(glyph->data_type == agg::glyph_data_outline) { ras.reset(); ras.add_path(ftrans); r.color(agg::rgba8(0, 0, 0)); agg::render_scanlines(ras, sl, r); } // increment pen position x += glyph->advance_x; y += glyph->advance_y; } ++p; } } else { message("Please copy file timesi.ttf to the current directory\n" "or download it from http://www.antigrain.com/timesi.zip"); } typedef agg::conv_stroke<conv_bspline_type> conv_stroke_type; conv_stroke_type stroke1(bspline1); conv_stroke_type stroke2(bspline2); stroke1.width(2.0); stroke2.width(2.0); r.color(agg::rgba8(170, 50, 20, 100)); ras.add_path(stroke1); agg::render_scanlines(ras, sl, r); ras.add_path(stroke2); agg::render_scanlines(ras, sl, r); //-------------------------- // Render the "poly" tool and controls r.color(agg::rgba(0, 0.3, 0.5, 0.2)); ras.add_path(m_poly1); agg::render_scanlines(ras, sl, r); ras.add_path(m_poly2); agg::render_scanlines(ras, sl, r); agg::render_ctrl(ras, sl, rb, m_fixed_len); agg::render_ctrl(ras, sl, rb, m_preserve_x_scale); agg::render_ctrl(ras, sl, rb, m_animate); agg::render_ctrl(ras, sl, rb, m_num_points); //-------------------------- }
virtual void on_draw() { pixfmt pixf(rbuf_window()); renderer_base rb(pixf); renderer_solid r(rb); rb.clear(agg::rgba(1, 1, 1)); g_rasterizer.clip_box(0, 0, width(), height()); if(m_trans_type.cur_item() == 0) { agg::trans_bilinear tr(g_x1, g_y1, g_x2, g_y2, m_quad.polygon()); if(tr.is_valid()) { //-------------------------- // Render transformed lion // agg::conv_transform<agg::path_storage, agg::trans_bilinear> trans(g_path, tr); agg::render_all_paths(g_rasterizer, g_scanline, r, trans, g_colors, g_path_idx, g_npaths); //-------------------------- //-------------------------- // Render transformed ellipse // agg::ellipse ell((g_x1 + g_x2) * 0.5, (g_y1 + g_y2) * 0.5, (g_x2 - g_x1) * 0.5, (g_y2 - g_y1) * 0.5, 200); agg::conv_stroke<agg::ellipse> ell_stroke(ell); ell_stroke.width(3.0); agg::conv_transform<agg::ellipse, agg::trans_bilinear> trans_ell(ell, tr); agg::conv_transform<agg::conv_stroke<agg::ellipse>, agg::trans_bilinear> trans_ell_stroke(ell_stroke, tr); g_rasterizer.add_path(trans_ell); r.color(agg::rgba(0.5, 0.3, 0.0, 0.3)); agg::render_scanlines(g_rasterizer, g_scanline, r); g_rasterizer.add_path(trans_ell_stroke); r.color(agg::rgba(0.0, 0.3, 0.2, 1.0)); agg::render_scanlines(g_rasterizer, g_scanline, r); //-------------------------- } } else { agg::trans_perspective tr(g_x1, g_y1, g_x2, g_y2, m_quad.polygon()); if(tr.is_valid()) { //-------------------------- // Render transformed lion // agg::conv_transform<agg::path_storage, agg::trans_perspective> trans(g_path, tr); agg::render_all_paths(g_rasterizer, g_scanline, r, trans, g_colors, g_path_idx, g_npaths); //-------------------------- //-------------------------- // Render transformed ellipse // agg::ellipse ell((g_x1 + g_x2) * 0.5, (g_y1 + g_y2) * 0.5, (g_x2 - g_x1) * 0.5, (g_y2 - g_y1) * 0.5, 200); agg::conv_stroke<agg::ellipse> ell_stroke(ell); ell_stroke.width(3.0); agg::conv_transform<agg::ellipse, agg::trans_perspective> trans_ell(ell, tr); agg::conv_transform<agg::conv_stroke<agg::ellipse>, agg::trans_perspective> trans_ell_stroke(ell_stroke, tr); g_rasterizer.add_path(trans_ell); r.color(agg::rgba(0.5, 0.3, 0.0, 0.3)); agg::render_scanlines(g_rasterizer, g_scanline, r); g_rasterizer.add_path(trans_ell_stroke); r.color(agg::rgba(0.0, 0.3, 0.2, 1.0)); agg::render_scanlines(g_rasterizer, g_scanline, r); //-------------------------- // Testing the reverse transformations //agg::trans_perspective tr2(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2); //if(tr2.is_valid()) //{ // double x, y; // x = m_quad.xn(0); y = m_quad.yn(0); tr2.transform(&x, &y); // g_rasterizer.move_to_d(x, y); // x = m_quad.xn(1); y = m_quad.yn(1); tr2.transform(&x, &y); // g_rasterizer.line_to_d(x, y); // x = m_quad.xn(2); y = m_quad.yn(2); tr2.transform(&x, &y); // g_rasterizer.line_to_d(x, y); // x = m_quad.xn(3); y = m_quad.yn(3); tr2.transform(&x, &y); // g_rasterizer.line_to_d(x, y); // r.color(agg::rgba(0.5, 0.0, 0.0, 0.5)); // agg::render_scanlines(g_rasterizer, g_scanline, r); //} //else //{ // message("Singularity..."); //} } } //-------------------------- // Render the "quad" tool and controls g_rasterizer.add_path(m_quad); r.color(agg::rgba(0, 0.3, 0.5, 0.6)); agg::render_scanlines(g_rasterizer, g_scanline, r); agg::render_ctrl(g_rasterizer, g_scanline, rb, m_trans_type); //-------------------------- }
virtual void on_init() { double dx = width() / 2.0 - (m_quad.xn(1) - m_quad.xn(0)) / 2.0; double dy = height() / 2.0 - (m_quad.yn(2) - m_quad.yn(0)) / 2.0; m_quad.xn(0) += dx; m_quad.yn(0) += dy; m_quad.xn(1) += dx; m_quad.yn(1) += dy; m_quad.xn(2) += dx; m_quad.yn(2) += dy; m_quad.xn(3) += dx; m_quad.yn(3) += dy; }
virtual void on_draw() { pixfmt pixf(rbuf_window()); pixfmt_pre pixf_pre(rbuf_window()); renderer_base rb(pixf); renderer_base_pre rb_pre(pixf_pre); if(!m_test_flag) { rb.clear(agg::rgba(1, 1, 1)); } if(m_trans_type.cur_item() == 0) { // For the affine parallelogram transformations we // calculate the 4-th (implicit) point of the parallelogram m_quad.xn(3) = m_quad.xn(0) + (m_quad.xn(2) - m_quad.xn(1)); m_quad.yn(3) = m_quad.yn(0) + (m_quad.yn(2) - m_quad.yn(1)); } if(!m_test_flag) { //-------------------------- // Render the "quad" tool and controls g_rasterizer.add_path(m_quad); agg::render_scanlines_aa_solid(g_rasterizer, g_scanline, rb, agg::rgba(0, 0.3, 0.5, 0.6)); //-------------------------- agg::render_ctrl(g_rasterizer, g_scanline, rb, m_trans_type); } // Prepare the polygon to rasterize. Here we need to fill // the destination (transformed) polygon. g_rasterizer.clip_box(0, 0, width(), height()); g_rasterizer.reset(); g_rasterizer.move_to_d(m_quad.xn(0), m_quad.yn(0)); g_rasterizer.line_to_d(m_quad.xn(1), m_quad.yn(1)); g_rasterizer.line_to_d(m_quad.xn(2), m_quad.yn(2)); g_rasterizer.line_to_d(m_quad.xn(3), m_quad.yn(3)); typedef agg::span_allocator<color_type> span_alloc_type; span_alloc_type sa; agg::image_filter<agg::image_filter_hanning> filter; typedef agg::wrap_mode_reflect_auto_pow2 remainder_type; typedef agg::image_accessor_wrap<pixfmt, remainder_type, remainder_type> img_source_type; pixfmt img_pixf(rbuf_img(0)); img_source_type img_src(img_pixf); enum subdiv_shift_e { subdiv_shift = 2 }; switch(m_trans_type.cur_item()) { case 0: { // Note that we consruct an affine matrix that transforms // a parallelogram to a rectangle, i.e., it's inverted. // It's actually the same as: // tr(g_x1, g_y1, g_x2, g_y2, m_triangle.polygon()); // tr.invert(); agg::trans_affine tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2); // Also note that we can use the linear interpolator instead of // arbitrary span_interpolator_trans. It works much faster, // but the transformations must be linear and parellel. typedef agg::span_interpolator_linear<agg::trans_affine> interpolator_type; interpolator_type interpolator(tr); typedef span_image_filter_2x2<img_source_type, interpolator_type> span_gen_type; span_gen_type sg(img_src, interpolator, filter); agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg); break; } case 1: { agg::trans_bilinear tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2); if(tr.is_valid()) { typedef agg::span_interpolator_linear<agg::trans_bilinear> interpolator_type; interpolator_type interpolator(tr); typedef span_image_filter_2x2<img_source_type, interpolator_type> span_gen_type; span_gen_type sg(img_src, interpolator, filter); agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg); } break; } case 2: { agg::trans_perspective tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2); if(tr.is_valid()) { typedef agg::span_interpolator_linear_subdiv<agg::trans_perspective, 8> interpolator_type; interpolator_type interpolator(tr); typedef span_image_filter_2x2<img_source_type, interpolator_type> span_gen_type; span_gen_type sg(img_src, interpolator, filter); agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg); } break; } } }
virtual void on_init() { m_poly.xn(0) = 50; m_poly.yn(0) = 50; m_poly.xn(1) = 150 + 20; m_poly.yn(1) = 150 - 20; m_poly.xn(2) = 250 - 20; m_poly.yn(2) = 250 + 20; m_poly.xn(3) = 350 + 20; m_poly.yn(3) = 350 - 20; m_poly.xn(4) = 450 - 20; m_poly.yn(4) = 450 + 20; m_poly.xn(5) = 550; m_poly.yn(5) = 550; }
virtual void on_key(int x, int y, unsigned key, unsigned flags) { if(key == ' ') { double cx = (m_quad.xn(0) + m_quad.xn(1) + m_quad.xn(2) + m_quad.xn(3)) / 4; double cy = (m_quad.yn(0) + m_quad.yn(1) + m_quad.yn(2) + m_quad.yn(3)) / 4; agg::trans_affine tr = agg::trans_affine_translation(-cx, -cy); tr *= agg::trans_affine_rotation(agg::pi / 2.0); tr *= agg::trans_affine_translation(cx, cy); tr.transform(&m_quad.xn(0), &m_quad.yn(0)); tr.transform(&m_quad.xn(1), &m_quad.yn(1)); tr.transform(&m_quad.xn(2), &m_quad.yn(2)); tr.transform(&m_quad.xn(3), &m_quad.yn(3)); force_redraw(); } }
virtual void on_init() { m_poly1.xn(0) = 10 + 50; m_poly1.yn(0) = -10 + 50; m_poly1.xn(1) = 10 + 150 + 20; m_poly1.yn(1) = -10 + 150 - 20; m_poly1.xn(2) = 10 + 250 - 20; m_poly1.yn(2) = -10 + 250 + 20; m_poly1.xn(3) = 10 + 350 + 20; m_poly1.yn(3) = -10 + 350 - 20; m_poly1.xn(4) = 10 + 450 - 20; m_poly1.yn(4) = -10 + 450 + 20; m_poly1.xn(5) = 10 + 550; m_poly1.yn(5) = -10 + 550; m_poly2.xn(0) = -10 + 50; m_poly2.yn(0) = 10 + 50; m_poly2.xn(1) = -10 + 150 + 20; m_poly2.yn(1) = 10 + 150 - 20; m_poly2.xn(2) = -10 + 250 - 20; m_poly2.yn(2) = 10 + 250 + 20; m_poly2.xn(3) = -10 + 350 + 20; m_poly2.yn(3) = 10 + 350 - 20; m_poly2.xn(4) = -10 + 450 - 20; m_poly2.yn(4) = 10 + 450 + 20; m_poly2.xn(5) = -10 + 550; m_poly2.yn(5) = 10 + 550; }
virtual void on_draw() { if(m_gamma.value() != m_old_gamma) { m_gamma_lut.gamma(m_gamma.value()); load_img(0, "spheres"); pixfmt pixf(rbuf_img(0)); pixf.apply_gamma_dir(m_gamma_lut); m_old_gamma = m_gamma.value(); } pixfmt pixf(rbuf_window()); pixfmt_pre pixf_pre(rbuf_window()); renderer_base rb(pixf); renderer_base_pre rb_pre(pixf_pre); renderer_solid r(rb); rb.clear(agg::rgba(1, 1, 1)); if(m_trans_type.cur_item() < 2) { // For the affine parallelogram transformations we // calculate the 4-th (implicit) point of the parallelogram m_quad.xn(3) = m_quad.xn(0) + (m_quad.xn(2) - m_quad.xn(1)); m_quad.yn(3) = m_quad.yn(0) + (m_quad.yn(2) - m_quad.yn(1)); } //-------------------------- // Render the "quad" tool and controls g_rasterizer.add_path(m_quad); r.color(agg::rgba(0, 0.3, 0.5, 0.1)); agg::render_scanlines(g_rasterizer, g_scanline, r); // Prepare the polygon to rasterize. Here we need to fill // the destination (transformed) polygon. g_rasterizer.clip_box(0, 0, width(), height()); g_rasterizer.reset(); int b = 0; g_rasterizer.move_to_d(m_quad.xn(0)-b, m_quad.yn(0)-b); g_rasterizer.line_to_d(m_quad.xn(1)+b, m_quad.yn(1)-b); g_rasterizer.line_to_d(m_quad.xn(2)+b, m_quad.yn(2)+b); g_rasterizer.line_to_d(m_quad.xn(3)-b, m_quad.yn(3)+b); typedef agg::span_allocator<color_type> span_alloc_type; span_alloc_type sa; agg::image_filter_bilinear filter_kernel; agg::image_filter_lut filter(filter_kernel, true); pixfmt pixf_img(rbuf_img(0)); typedef agg::image_accessor_clone<pixfmt> source_type; source_type source(pixf_img); start_timer(); switch(m_trans_type.cur_item()) { case 0: { agg::trans_affine tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2); typedef agg::span_interpolator_linear<agg::trans_affine> interpolator_type; interpolator_type interpolator(tr); typedef image_filter_2x2_type<source_type, interpolator_type> span_gen_type; span_gen_type sg(source, interpolator, filter); agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg); break; } case 1: { agg::trans_affine tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2); typedef agg::span_interpolator_linear<agg::trans_affine> interpolator_type; typedef image_resample_affine_type<source_type> span_gen_type; interpolator_type interpolator(tr); span_gen_type sg(source, interpolator, filter); sg.blur(m_blur.value()); agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg); break; } case 2: { agg::trans_perspective tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2); if(tr.is_valid()) { typedef agg::span_interpolator_linear_subdiv<agg::trans_perspective> interpolator_type; interpolator_type interpolator(tr); typedef image_filter_2x2_type<source_type, interpolator_type> span_gen_type; span_gen_type sg(source, interpolator, filter); agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg); } break; } case 3: { agg::trans_perspective tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2); if(tr.is_valid()) { typedef agg::span_interpolator_trans<agg::trans_perspective> interpolator_type; interpolator_type interpolator(tr); typedef image_filter_2x2_type<source_type, interpolator_type> span_gen_type; span_gen_type sg(source, interpolator, filter); agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg); } break; } case 4: { typedef agg::span_interpolator_persp_lerp<> interpolator_type; typedef agg::span_subdiv_adaptor<interpolator_type> subdiv_adaptor_type; interpolator_type interpolator(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2); subdiv_adaptor_type subdiv_adaptor(interpolator); if(interpolator.is_valid()) { typedef image_resample_type<source_type, subdiv_adaptor_type> span_gen_type; span_gen_type sg(source, subdiv_adaptor, filter); sg.blur(m_blur.value()); agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg); } break; } case 5: { typedef agg::span_interpolator_persp_exact<> interpolator_type; typedef agg::span_subdiv_adaptor<interpolator_type> subdiv_adaptor_type; interpolator_type interpolator(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2); subdiv_adaptor_type subdiv_adaptor(interpolator); if(interpolator.is_valid()) { typedef image_resample_type<source_type, subdiv_adaptor_type> span_gen_type; span_gen_type sg(source, subdiv_adaptor, filter); sg.blur(m_blur.value()); agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg); } break; } } double tm = elapsed_time(); pixf.apply_gamma_inv(m_gamma_lut); char buf[64]; agg::gsv_text t; t.size(10.0); agg::conv_stroke<agg::gsv_text> pt(t); pt.width(1.5); sprintf(buf, "%3.2f ms", tm); t.start_point(10.0, 70.0); t.text(buf); g_rasterizer.add_path(pt); r.color(agg::rgba(0,0,0)); agg::render_scanlines(g_rasterizer, g_scanline, r); //-------------------------- agg::render_ctrl(g_rasterizer, g_scanline, rb, m_trans_type); agg::render_ctrl(g_rasterizer, g_scanline, rb, m_gamma); agg::render_ctrl(g_rasterizer, g_scanline, rb, m_blur); }