摘自:http://blog.gmane.org/gmane.comp.graphics.agg
代码如下:
void TestOverlappedColorProblem()
{
agg::rendering_buffer &rbuf = rbuf_window();
agg::pixfmt_bgr24 pixf(rbuf);
typedef agg::renderer_base<agg::pixfmt_bgr24> renderer_base_type;
renderer_base_type renb(pixf);
typedef agg::renderer_scanline_aa_solid<renderer_base_type> renderder_scanline_type;
renderder_scanline_type rensl(renb);
agg::rasterizer_scanline_aa<> ras;
agg::scanline_u8 sl;
ras.reset();
renb.clear(agg::rgba8(255, 255, 255));
{ // box 1
agg::path_storage path;
path.move_to(100, 100);
path.line_to(100, 300);
path.line_to(300, 300);
path.line_to(300, 100);
path.line_to(100, 100);
ras.add_path(path);
}
{ // box 2
agg::path_storage path;
path.move_to(200, 200);
path.line_to(200, 400);
path.line_to(400, 400);
path.line_to(400, 200);
path.line_to(200, 200);
agg::conv_stroke<agg::path_storage> stroke(path);
stroke.width(2);
ras.add_path(stroke);
}
agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(0, 0, 0));
}
渲染的结果:可以看到box2的轮廓线在box1的内部,显示为白色,问题是明明采用的是黑色的画刷。
可以通过多次调用render_scanlines_aa_solid,避免这种问题,但是效率不高!!!
邮件原文如下:
Hi, I‘m working on drawing images with simple boxes. I‘ve got a problem with the color of overlapping boxes.
The code I wrote is as follows:
using pixfmt_type = agg::pixfmt_rgba32;
using renbase_type = agg::renderer_base<pixfmt_type>;
using renderer_type = agg::renderer_scanline_aa_solid<renbase_type>;
using rasterizer_type = agg::rasterizer_scanline_aa<>;
using scanline_type = agg::scanline_p8;
rbase.clear(agg::rgba(1, 1, 1));
{ // box 1
agg::path_storage path;
path.move_to(100, 100);
path.line_to(100, 300);
path.line_to(300, 300);
path.line_to(300, 100);
path.line_to(100, 100);
ras.add_path(path);
}
{ // box 2
agg::path_storage path;
path.move_to(200, 200);
path.line_to(200, 400);
path.line_to(400, 400);
path.line_to(400, 200);
path.line_to(200, 200);
agg::conv_stroke<decltype(path)> stroke(path);
stroke.width(2);
ras.add_path(stroke);
}
ren.color(agg::rgba(0, 0, 0));
agg::render_scanlines(ras, sl, ren);
One box is a simple stroke and the other is a filled box.
I expected the overlapping region will also be painted with black, but it‘s painted with white.