Win32 Application 空工程例子(1)

摘自:http://blog.csdn.net/yinyhy/article/details/10001239
#include"agg/include/agg_basics.h"
#include"agg/include/agg_conv_curve.h"
#include"agg/include/agg_trans_perspective.h"
#include"agg/include/agg_conv_dash.h"
#include"agg/include/agg_renderer_scanline.h"
#include"agg/include/agg_rendering_buffer.h"
#include"agg/include/agg_rasterizer_scanline_aa.h"
#include "agg/include/agg_scanline_u.h"
#include"agg/include/agg_pixfmt_rgb.h"
#include"agg/include/platform/agg_platform_support.h"
#include"agg/include/agg_ellipse.h"
#include"agg/include/agg_conv_contour.h"
#include"agg/include/agg_conv_stroke.h"
#include "agg/include/agg_renderer_base.h"
#include"agg/include/agg_path_storage.h"
#include"agg/include/agg_arrowhead.h"
#include"agg/include/agg_rounded_rect.h"
#include"agg/include/agg_conv_marker.h"
#include"agg/include/agg_vcgen_markers_term.h"
#include"agg/include/agg_gsv_text.h"
#include "stdlib.h"
#include "stdio.h"
 
 
 
class the_application:publicagg::platform_support
{
public:
  the_application(agg::pix_format_e format,bool flip_y):agg::platform_support(format,flip_y),pix_fmt(rbuf_window()),ren_bas(pix_fmt)
  {
    
  }
 
  void draw_ellipse()
  {
    //Rendering Buffer渲染的内存块,就是即将显示界面的颜色内存块,其中agg::rendering_buffer
    //类提供了一系列直接操作某一个坐标点颜色的函数,例如row_ptr();
    agg::rendering_buffer &rbuf =rbuf_window();
    agg::pixfmt_bgr24 pixf(rbuf);
 
    //Renderers渲染器,我们可以看成是油漆,颜料,
    typedef agg::renderer_base<agg::pixfmt_bgr24>renderer_base_type;
    renderer_base_type renb(pixf);
 
    typedefagg::renderer_scanline_aa_solid<renderer_base_type>renderder_scanline_type;
    renderder_scanline_type rensl(renb);
 
    //Scanline Rasterizer光栅化,说她是画册,描述了所有我们即将描绘图案,颜色,线条,
    //但是并不切确,因为她只是一个容器,一个记载线段,标志,详细参数的规格说明书,
    //连草图都不是,她更像是一张菜谱,里面记录了食材,记录了烹饪的过程,仅此而已。
    agg::rasterizer_scanline_aa<> ras;
    agg::scanline_u8 sl;
 
    //用白色对内存块里面的数据进行填充,实际上了刷成白色
    renb.clear(agg::rgba8(255,255,255));
 ////////////////////////////////////////////
    ras.reset();
    //创建画笔工具,在后面的章节会陆续介绍其他的画笔,现在只是想画一直线
    agg::path_storage ps1;
    ps1.move_to(200,200);
    ps1.line_to(300,300);

    //设置线段端点的形状,半圆形状
    agg::line_cap_e cap = agg::round_cap;
    //线条的样式,虚线,或者实线
    agg::conv_stroke<agg::path_storage>stroke(ps1);
    stroke.line_cap(cap);
    //设置线段的宽度
    stroke.width(50);
    //添加到渲染器中                       
    ras.add_path(stroke);
    //将线条渲染到内存图片当中,准备显示
    agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255,0,0));
    ras.reset();
    ////////////////////////////////////////////
  }
 
  virtual void on_draw()
  {
    draw_ellipse();
  }
private:
  agg::pixfmt_rgb24 pix_fmt;
  agg::renderer_base<agg::pixfmt_rgb24>ren_bas;
};
 
 
 
int agg_main(int argc, char*argv[])
{
  //创建一个窗口,显示内容,大小是600*600
  the_applicationapp(agg::pix_format_bgr24,false);
  app.caption("AGG Example.Anti_AliasingDemo");
 
  if (app.init(600, 600, agg::window_resize))
  {
    return app.run();
  }
 
  return -1;
}

总结:

在整个例子,当中出现了大量的专业术语,并且调用的逻辑非常繁琐,而仅仅是为了在桌面上描绘一条线段。但是针对波浪线的里面的渲染,结构应该是非常清晰的。读者可能比较疑惑的一点就是前面的一大堆声明和定义。下一章节先对渲染线段进行总结。

你可能感兴趣的:(agg,path_storage)