您的位置:首页 > 移动开发

AGG学习之六----完整的渲染流程

2011-03-01 11:08 127 查看
AGG的渲染流程:

vertex source-->coordinate conversion pipeline-->scanline rasterizer -->renderers-->rendering buffer-->screen output

 

 

样例代码如下:

]#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"
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(150,150, 80, 80);

//coordinate conversion pipeline
typedef	agg::conv_contour<agg::ellipse>		ell_cc_type;
ell_cc_type	ccell(ell);
typedef	agg::conv_stroke<agg::ellipse>		ell_stroke_type;
ell_stroke_type ell_stroke(ell);
ell_stroke.width(1.5);
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)
{
ell.init(150,150,80+10*i,80+10*i);

ras.add_path(ell_stroke);//添加路径
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;
}


 

 

 

效果图如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息