针对Vertex source 定义后,进行坐标变换--仿射变换,在对其栅格化渲染。 代码如下: #include "platform/agg_platform_support.h" #include "agg_basics.h" #include "agg_rendering_buffer.h" #include "agg_pixfmt_rgb.h" #include "agg_alpha_mask_u8.h" #include "agg_pixfmt_amask_adaptor.h" #include "agg_rasterizer_scanline_aa.h" #include "agg_scanline_u.h" #include "agg_renderer_scanline.h" #include "agg_ellipse.h" #include "agg_conv_contour.h" #include "agg_conv_stroke.h" #include "agg_conv_transform.h" enum { flip_y = true}; class the_application : public agg::platform_support { public: the_application(agg::pix_format_e format, bool flip_y): agg::platform_support(format,flip_y) {} virtual ~the_application() { } virtual void on_init(){} virtual void on_draw() { unsigned i; //renderer buffer agg::rendering_buffer rbuf = this->rbuf_window(); //renderers agg::pixfmt_bgr24 pixf(rbuf);//底层像素渲染对象,对渲染内存进行包装了 typedef agg::renderer_base<agg::pixfmt_bgr24> ren_base_type;//底层渲染器 ren_base_type ren_base(pixf); ren_base.clear( agg::rgba8(255,255,255) );//清除buffer背景色 typedef agg::renderer_scanline_aa_solid<ren_base_type> renderer_scanline_type;//高层渲染器 renderer_scanline_type ren_scanline(ren_base); //vertex source agg::ellipse ell(0,0, 80, 80);//定义一个圆vertex source //仿射变换 agg::trans_affine mtx; mtx.scale(1, 0.6);//x轴向缩小 mtx.rotate( agg::deg2rad(60) ); //旋转30度 mtx.translate( 150, 150 ); //x、y轴向分别平移150(注意: 旋转、平移操作的先后顺序不同,效果是不同滴) typedef agg::conv_transform<agg::ellipse, agg::trans_affine> ell_ct_type; ell_ct_type ctell(ell,mtx);//矩阵变换,形成一个旋转60度的椭圆 //coordinate conversion pipeline typedef agg::conv_contour<ell_ct_type> ell_cc_type; ell_cc_type ccell(ctell);//轮廓变换 typedef agg::conv_stroke<ell_cc_type> ell_cc_cs_type; ell_cc_cs_type csccell(ccell); csccell.width(1); agg::rasterizer_scanline_aa<> ras;//Polygon rasterizer, which including a clipper,将ell定点数据转换为scanline(由多个span组成) agg::scanline_u8 sl;//非封装扫描线容器,rasterizer use it to render the render_buffer for (i=0; i<5; ++i) { ccell.width( i*20);//什么作用呢?为什么呢? ras.add_path(csccell);//添加路径 ren_scanline.color( agg::rgba8(i*50,40,23) ); agg::render_scanlines( ras, sl, ren_scanline );//ras使用sl中的span渲染ren_scanline } } }; int agg_main(int argc, char* argv[]) { the_application app(agg::pix_format_bgr24, flip_y); app.caption("My AGG Demo"); if(app.init(300, 300, agg::window_resize )) { app.run(); } return 1; } 效果图: 再来一个新线型--虚线,今后在GIS制图中会经常用到的。代码如下: #include "platform/agg_platform_support.h" #include "agg_basics.h" #include "agg_rendering_buffer.h" #include "agg_pixfmt_rgb.h" #include "agg_alpha_mask_u8.h" #include "agg_pixfmt_amask_adaptor.h" #include "agg_rasterizer_scanline_aa.h" #include "agg_scanline_u.h" #include "agg_renderer_scanline.h" #include "agg_ellipse.h" #include "agg_conv_contour.h" #include "agg_conv_stroke.h" #include "agg_conv_dash.h" #include "agg_conv_transform.h" #include "platform/win32/agg_win32_bmp.h" #include "agg_span_allocator.h" #include "agg_span_image_filter_rgb.h" enum { flip_y = true}; class the_application : public agg::platform_support { public: the_application(agg::pix_format_e format, bool flip_y): agg::platform_support(format,flip_y) {} virtual ~the_application() { } virtual void on_init(){} virtual void on_draw() { unsigned i; //renderer buffer agg::rendering_buffer rbuf = this->rbuf_window(); //renderers agg::pixfmt_bgr24 pixf(rbuf);//底层像素渲染对象,对渲染内存进行包装了 typedef agg::renderer_base<agg::pixfmt_bgr24> ren_base_type;//底层渲染器 ren_base_type ren_base(pixf); ren_base.clear( agg::rgba8(255,255,255) );//清除buffer背景色 typedef agg::renderer_scanline_aa_solid<ren_base_type> renderer_scanline_type;//高层渲染器 renderer_scanline_type ren_scanline(ren_base); //vertex source agg::ellipse ell(0,0, 80, 80);//定义一个圆vertex source //仿射变换 agg::trans_affine mtx; mtx.scale(1, 0.6);//x轴向缩小 mtx.rotate( agg::deg2rad(60) ); //旋转30度 mtx.translate( 150, 150 ); //x、y轴向分别平移150(注意: 旋转、平移操作的先后顺序不同,效果是不同滴) typedef agg::conv_transform<agg::ellipse, agg::trans_affine> ell_ct_type; ell_ct_type ctell(ell,mtx);//矩阵变换,形成一个旋转60度的椭圆 //coordinate conversion pipeline typedef agg::conv_contour<ell_ct_type> ell_cc_type; ell_cc_type ccell(ctell);//轮廓变换 typedef agg::conv_dash<ell_cc_type> ell_cd_type; ell_cd_type cdell(ccell);//虚线 cdell.add_dash( 5,5 ); typedef agg::conv_stroke<ell_cd_type> ell_cc_cs_type; ell_cc_cs_type csccell(cdell); csccell.width(1);//con_stroke的width属性决定线宽度 agg::rasterizer_scanline_aa<> ras;//Polygon rasterizer, which including a clipper,将ell定点数据转换为scanline(由多个span组成) agg::scanline_u8 sl;//非封装扫描线容器,rasterizer use it to render the render_buffer for (i=0; i<5; ++i) { ccell.width( i*20);//conv_contour决定轮廓的收缩宽度 ras.add_path(csccell);//添加路径 ren_scanline.color( agg::rgba8(i*50,40,23) ); agg::render_scanlines( ras, sl, ren_scanline );//ras使用sl中的span渲染ren_scanline } } }; int agg_main(int argc, char* argv[]) { the_application app(agg::pix_format_bgr24, flip_y); app.caption("My AGG Demo"); if(app.init(300, 300, agg::window_resize )) { app.run(); } return 1; } 效果图如下: