AGG是一个开源、高效的跨平台2D图形库。AGG的功能与GDI+的功能非常类似,但提供了比GDI+更灵活的编程接口,其产生的图形的质量也非常高(自称超过GDI+)
其中:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include "agg_basics.h"
#include "agg_rendering_buffer.h"
#include "agg_rasterizer_scanline_aa.h"
#include "agg_scanline_u.h"
#include "agg_renderer_scanline.h"
#include "agg_pixfmt_rgb.h"
#include "platform/agg_platform_support.h"
#include "agg_ellipse.h"
#include "agg_conv_contour.h"
#include "agg_conv_stroke.h"
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
void
on_draw()
{
//Rendering Buffer
agg::rendering_buffer &rbuf = rbuf_window();
agg::pixfmt_bgr24 pixf(rbuf);
// Renderers
typedef
agg::renderer_base<agg:agg:agg:agg:agg:agg:agg:agg::pixfmt_bgr24> renderer_base_type;
renderer_base_type renb(pixf);
typedef
agg::renderer_scanline_aa_solid<renderer_base_type> renderer_scanline_type;
renderer_scanline_type rensl(renb);
// Vertex Source
agg::ellipse ell(100,100,50,50);
// Coordinate conversion pipeline
typedef
agg::conv_contour<agg:agg:agg:agg:agg:agg:agg:agg::ellipse> ell_cc_type;
ell_cc_type ccell(ell);
typedef
agg::conv_stroke<ell_cc_type> ell_cc_cs_type;
ell_cc_cs_type csccell(ccell);
// Scanline Rasterizer
agg::rasterizer_scanline_aa<> ras;
agg::scanline_u8 sl;
// Draw
renb.clear(agg::rgba8(255,255,255));
for
(
int
i=0; i<5; i++)
{
ccell.width(i*20);
ras.add_path(csccell);
rensl.color( agg::rgba8(0,0,i*50));
agg::render_scanlines(ras,sl,rensl);
}
}
};
int
agg_main(
int
argc,
char
* argv[])
{
the_application app(agg::pix_format_bgr24,
false
);
app.caption(
"AGG Example. Anti-Aliasing Demo"
);
if
(app.init(600, 400, agg::window_resize))
{
return
app.run();
}
return
-1;
}</ell_cc_type></agg:agg:agg:agg:agg:agg:agg:agg::ellipse></renderer_base_type></agg:agg:agg:agg:agg:agg:agg:agg::pixfmt_bgr24>
|
编译这段代码的方法是(以VC为例):
显示效果:
我们先不管agg_main及agg::platform_support的问题,实际上agg::platform_support只是AGG给我们方便显示AGG图形用的,真正应用时几乎不会用到(后面会讲到怎样把AGG图形画到HDC上)。
现在我们只需要知道这个框架可以生成一个窗体,当窗体重画时会调用virtual void on_draw()就行了。
现在直接从on_draw()开始看