AGG学习之三----像素渲染器之bland功效时间:2021-09-23 05:39:14实用pixel format renderer 进行blend操作,绘制光谱。 此例子在copy代码后,发现无法编译,进行代码调整后能显示效果,但具体因果还未清楚。 #include "agg_rendering_buffer.h" #include "agg_basics.h" #include "platform/agg_platform_support.h" #include "agg_pixfmt_rgb.h" enum { flip_y = true, }; template<class Ren> void draw_black_frame(Ren &ren) { agg::rgba8 c(255,0,0); int h = ren.height(); int w = ren.width(); ren.copy_hline( 0,0,w,c ); ren.copy_hline( 0,h-1,w,c ); ren.copy_vline( 0,0,h,c ); ren.copy_vline( w-1,0,h,c ); } 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() { agg::rendering_buffer rbuf = this->rbuf_window(); agg::pixfmt_rgb24 pixf(rbuf);//底层像素渲染对象,对渲染内存进行包装了 int w = pixf.width(); int h = pixf.height(); memset( rbuf.row_ptr(0), 255, w*h*3 ); unsigned i; //设定光谱值 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.blend_color_hspan(0, i, frame_width, span, 0);//原文为此语句,但无法编译通过,所以改为一下语句暂时通过,但由此引发的实际问题并未清楚啊 pixf.blend_color_hspan( 0, i, w, span, cover, 0.8 ); } draw_black_frame(pixf);//绘制边框线 delete []span; } }; 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; } 效果图如下: