实用像素渲染器 agg::pixel format rendering buffer与掩码agg::amask_no_clip_gray8的适配器,进行掩码式渲染。 代码如下: #include "agg_rendering_buffer.h" #include "agg_basics.h" #include "platform/agg_platform_support.h" #include "agg_pixfmt_rgb.h" #include "agg_alpha_mask_u8.h" #include "agg_pixfmt_amask_adaptor.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; agg::rendering_buffer rbuf = this->rbuf_window(); agg::pixfmt_rgb24 pixf(rbuf);//底层像素渲染对象,对渲染内存进行包装了 int w = pixf.width(); int h = pixf.height(); agg::int8u *amask_buf = new agg::int8u[w*h]; //mask的缓存区申请 agg::rendering_buffer amask_rbuf(amask_buf, w, h, w); //mask的rendering buffer object, 对mask buffer进行封装 for (i=0; i<h; ++i) { unsigned val = 255*i/h; memset(amask_rbuf.row_ptr(i), val, w); } agg::amask_no_clip_gray8 amask(amask_rbuf); //创建无裁剪区的mask object agg::pixfmt_amask_adaptor<agg::pixfmt_rgb24, agg::amask_no_clip_gray8> pixf_amask(pixf,amask);//创建像素渲染器与掩码的适配器 memset( rbuf.row_ptr(0), 255, w*h*3 ); //设定光谱值 agg::rgba8 *span = new agg::rgba8[w]; agg::int8u *cover = new agg::int8u[w]; for (i=0; i<w; ++i) { agg::rgba c(380.0+400.0*i/w,0.8); span[i] = agg::rgba8(c); } for (i=0; i<h; ++i) { pixf_amask.blend_color_hspan(0,i,w,span,cover); } delete []span; delete []cover; } }; int agg_main(int argc, char* argv[]) { the_application app(agg::pix_format_bgr24, flip_y); app.caption("My AGG Demo"); if(app.init(320, 200, agg::window_resize )) { app.run(); } return 1; } 效果如下: