附上代码:
agg::rendering_buffer &rbuf = rbuf_window();//获取渲染缓存
agg::pixfmt_bgr24 pixf(rbuf);//组成像素
typedef agg::renderer_base<agg::pixfmt_bgr24> renderer_base_type;
renderer_base_type renb(pixf);//提供裁剪区域,只有在裁剪区域内才渲染有效
typedef agg::renderer_scanline_bin_solid<renderer_base_type> renderder_scanline_type;
renderder_scanline_type rensl(renb);//自定义底层的渲染器
agg::rasterizer_scanline_aa<> ras;
agg::scanline_u8 sl;
ras.reset();
renb.clear(agg::rgba8(255,255,255));
agg::ellipse ell(320,320,230,230);
agg::conv_stroke<agg::ellipse> stroke(ell);
ras.add_path(stroke);
rensl.color(agg::rgba8(255,0,0));
agg::render_scanlines(ras,sl,rensl);
这种方法是不提供抗锯齿的效果,采用的是agg::renderer_scanline_bin_solid,
对比下面的代码:
agg::rendering_buffer &rbuf = rbuf_window();
agg::pixfmt_bgr24 pixf(rbuf);
typedef agg::renderer_base<agg::pixfmt_bgr24> renderer_base_type;
renderer_base_type renb(pixf);
renb.clear(agg::rgba8(255,255,255));
agg::rasterizer_scanline_aa<> ras;
agg::scanline_u8 sl;
ren_bas.clear(agg::rgba8(255,255,255));
agg::ellipse ell(320,320,230,230);
agg::conv_stroke<agg::ellipse> stroke(ell);
ras.add_path(stroke);
agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255,0,0));
渲染的圆是抗锯齿的,效果非常的好,aa实际上就是anti-aliasing的意思。