-rw-r--r-- | agg-plot/agg-parse-trans.cpp | 16 | ||||
-rw-r--r-- | agg-plot/agg-parse-trans.h | 8 | ||||
-rw-r--r-- | agg-plot/lua-draw.cpp | 54 | ||||
-rw-r--r-- | agg-plot/plot-window.cpp | 11 | ||||
-rw-r--r-- | agg-plot/trans.h | 20 | ||||
-rw-r--r-- | pre3d/pre3d.lua | 26 | ||||
-rw-r--r-- | pre3d/test.lua | 30 |
diff --git a/agg-plot/agg-parse-trans.cpp b/agg-plot/agg-parse-trans.cpp index 85042409..30657622 100644 --- a/agg-plot/agg-parse-trans.cpp +++ b/agg-plot/agg-parse-trans.cpp @@ -20,6 +20,14 @@ struct builder_reg { vertex_source *(*func)(lua_State *, int, vertex_source *); }; +static vertex_source * build_stroke (lua_State *L, int i, vertex_source *s); +static vertex_source * build_curve (lua_State *L, int i, vertex_source *s); +static vertex_source * build_marker (lua_State *L, int i, vertex_source *s); +static vertex_source * build_dash (lua_State *L, int i, vertex_source *s); +static vertex_source * build_extend (lua_State *L, int i, vertex_source *s); +static vertex_source * build_translate (lua_State *L, int i, vertex_source *s); +static vertex_source * build_rotate (lua_State *L, int i, vertex_source *s); + struct property_reg line_cap_properties[] = { {(int) agg::butt_cap, "butt" }, {(int) agg::square_cap, "square"}, @@ -41,6 +49,7 @@ const builder_reg builder_table[] = { {"dash", build_dash}, {"curve", build_curve}, {"marker", build_marker}, + {"extend", build_extend}, {"translate", build_translate}, {"rotate", build_rotate}, {NULL, NULL} @@ -114,6 +123,13 @@ build_dash (lua_State *L, int specindex, vertex_source *obj) } vertex_source * +build_extend (lua_State *L, int specindex, vertex_source *obj) +{ + double width = mlua_named_optnumber (L, specindex, "width", 1.0); + return (vertex_source *) new trans::extend(obj, width); +} + +vertex_source * build_translate (lua_State *L, int specindex, vertex_source *obj) { double x = mlua_named_number (L, specindex, "x"); diff --git a/agg-plot/agg-parse-trans.h b/agg-plot/agg-parse-trans.h index 02dff4ac..87973582 100644 --- a/agg-plot/agg-parse-trans.h +++ b/agg-plot/agg-parse-trans.h @@ -13,12 +13,4 @@ extern vertex_source * parse_spec (lua_State *L, int specindex, extern vertex_source * parse_spec_pipeline (lua_State *L, int index, vertex_source *obj); - -extern vertex_source * build_stroke (lua_State *L, int i, vertex_source *s); -extern vertex_source * build_curve (lua_State *L, int i, vertex_source *s); -extern vertex_source * build_marker (lua_State *L, int i, vertex_source *s); -extern vertex_source * build_dash (lua_State *L, int i, vertex_source *s); -extern vertex_source * build_translate (lua_State *L, int i, vertex_source *s); -extern vertex_source * build_rotate (lua_State *L, int i, vertex_source *s); - #endif diff --git a/agg-plot/lua-draw.cpp b/agg-plot/lua-draw.cpp index a26c49de..48e9580f 100644 --- a/agg-plot/lua-draw.cpp +++ b/agg-plot/lua-draw.cpp @@ -48,11 +48,6 @@ static int agg_rgba_free (lua_State *L); static int agg_rgba_add (lua_State *L); static int agg_rgba_mul (lua_State *L); static int agg_rgba_set_alpha (lua_State *L); -#if 0 -static int agg_rgba_invert (lua_State *L); -static int agg_rgba_dup (lua_State *L); -static int agg_rgba_set (lua_State *L); -#endif static void path_cmd (my::path *p, int cmd, struct cmd_call_stack *stack); @@ -85,11 +80,6 @@ static const struct luaL_Reg rgba_methods[] = { {"__add", agg_rgba_add }, {"__mul", agg_rgba_mul }, {"alpha", agg_rgba_set_alpha }, -#if 0 - {"set", agg_rgba_set }, - {"invert", agg_rgba_invert }, - {"dup", agg_rgba_dup }, -#endif {NULL, NULL} }; @@ -256,7 +246,7 @@ agg_text_new (lua_State *L) { double size = luaL_optnumber (L, 1, 10.0); double width = luaL_optnumber (L, 2, 1.0); - my::text *txt = new(L, GS_DRAW_TEXT) my::text(size, width); + new(L, GS_DRAW_TEXT) my::text(size, width); return 1; } @@ -345,48 +335,6 @@ agg_rgba_set_alpha (lua_State *L) return 0; } -#if 0 -int -agg_rgba_set (lua_State *L) -{ - agg::rgba8 *c = (agg::rgba8 *) gs_check_userdata (L, 1, GS_RGBA_COLOR); - double r, g, b, a; - - r = luaL_checknumber (L, 2); - g = luaL_checknumber (L, 3); - b = luaL_checknumber (L, 4); - if (lua_gettop (L) > 4) - a = luaL_checknumber (L, 5); - else - a = 1.0; - - c->r = r; - c->g = g; - c->b = b; - c->a = a; - - return 0; -} - -int -agg_rgba_invert (lua_State *L) -{ - agg::rgba8 *c = (agg::rgba8 *) gs_check_userdata (L, 1, GS_RGBA_COLOR); - c->r = 1 - c->r; - c->g = 1 - c->g; - c->b = 1 - c->b; - return 0; -} - -int -agg_rgba_dup (lua_State *L) -{ - agg::rgba8 *src = (agg::rgba8 *) gs_check_userdata (L, 1, GS_RGBA_COLOR); - new(L, GS_RGBA_COLOR) agg::rgba8(*src); - return 1; -} -#endif - int agg_rgba_add (lua_State *L) { diff --git a/agg-plot/plot-window.cpp b/agg-plot/plot-window.cpp index 70fec188..655bb5e7 100644 --- a/agg-plot/plot-window.cpp +++ b/agg-plot/plot-window.cpp @@ -88,7 +88,6 @@ public: delete m_canvas; }; - virtual void on_draw(); virtual void on_init(); virtual void on_resize(int sx, int sy); @@ -122,16 +121,6 @@ plot_window::on_init() } void -plot_window::on_draw() -{ - printf("on draw!\n"); - if (! m_canvas) - return; - - m_canvas->clear(); -}; - -void plot_window::on_resize(int sx, int sy) { if (m_canvas) diff --git a/agg-plot/trans.h b/agg-plot/trans.h index 0649ddaa..35dec2a7 100644 --- a/agg-plot/trans.h +++ b/agg-plot/trans.h @@ -6,6 +6,7 @@ #include "agg_conv_curve.h" #include "agg_conv_dash.h" #include "agg_conv_transform.h" +#include "agg_conv_contour.h" #include "agg_vcgen_markers_term.h" #include "agg_arrowhead.h" #include "agg_bounding_rect.h" @@ -59,6 +60,7 @@ typedef vs_trans_proxy<agg::conv_stroke<vertex_source> > vs_stroke; typedef vs_trans_proxy<agg::conv_curve<vertex_source> > vs_curve; typedef vs_trans_proxy<agg::conv_dash<vertex_source> > vs_dash; typedef vs_trans_proxy<agg::conv_transform<vertex_source> > vs_transform; +typedef vs_trans_proxy<agg::conv_contour<vertex_source> > vs_contour; namespace trans { @@ -127,6 +129,24 @@ namespace trans { m_source->apply_transform(m, as); }; }; + + class extend : public vs_contour { + public: + typedef agg::conv_contour<vertex_source> base_type; + + extend(vertex_source* src, double width): vs_contour(src) + { + base_type& v = self(); + v.width(width); + v.auto_detect_orientation(true); + }; + + virtual void apply_transform(agg::trans_affine& m, double as) + { + m_output.approximation_scale(as); + m_source->apply_transform(m, as); + }; + }; class resize : public vs_transform { agg::trans_affine m_matrix; diff --git a/pre3d/pre3d.lua b/pre3d/pre3d.lua index c2592ebe..2c379f44 100644 --- a/pre3d/pre3d.lua +++ b/pre3d/pre3d.lua @@ -822,26 +822,6 @@ function RendererMT.drawBuffer(this) local is_triangle = qf:isTriangle() - if obj.draw_overdraw then - -- Unfortunately when we fill with canvas, we can get some gap looking - -- things on the edges between quads. One possible solution is to - -- stroke the path, but this turns out to be really expensive. Instead - -- we try to increase the area of the quad. Each edge pushes its - -- vertices away from each other. This is sort of similar in concept - -- to the builtin canvas shadow support (shadowOffsetX, etc). However, - -- Chrome doesn't support shadows correctly now. It does in trunk, but - -- using shadows to fill the gaps looks awful, and also seems slower. - - pushPoints2dIP(qf.i0, qf.i1) - pushPoints2dIP(qf.i1, qf.i2) - if is_triangle then - pushPoints2dIP(qf.i2, qf.i0) - else - pushPoints2dIP(qf.i2, qf.i3) - pushPoints2dIP(qf.i3, qf.i0) - end - end - -- Create our quad as a <canvas> path. local qpath = path(qf.i0.x, qf.i0.y) qpath:line_to(qf.i1.x, qf.i1.y) @@ -854,7 +834,11 @@ function RendererMT.drawBuffer(this) -- Fill... local frgba = obj.fill_rgba if frgba then - win:draw(qpath, frgba) + if obj.draw_overdraw then + win:draw(qpath, frgba, {{'extend'}}) + else + win:draw(qpath, frgba) + end end -- Stroke... diff --git a/pre3d/test.lua b/pre3d/test.lua index 5f13e796..6823b67d 100644 --- a/pre3d/test.lua +++ b/pre3d/test.lua @@ -35,8 +35,6 @@ function demo1() -- We need to rebuild the normals after extruding the vertices. ShapeUtils.rebuildMeta(shape) - -- shape = ShapeUtils.makeXYFunction(|x,y| 1.2*exp(-x^2-y^2), -2, -2, 2, 2) - renderer.draw_overdraw = false renderer.draw_backfaces = true renderer.fill_rgba = rgb(0x4A/255, 0x92/255, 0xBF/255) @@ -69,7 +67,8 @@ function demo2() renderer.fill_rgba = rgb(0x4A/255, 0x92/255, 0xBF/255) renderer.fill_rgba_backside = rgb(0xBF/255, 0x92/255, 0x4A/255) renderer.set_light_intensity = true - renderer.stroke_rgba = rgb(0x66/255, 0x66/255, 0x66/255) + renderer.draw_overdraw = true +-- renderer.stroke_rgba = rgb(0x66/255, 0x66/255, 0x66/255) renderer.camera.focal_length = 30; @@ -80,3 +79,28 @@ function demo2() draw(renderer, shape) end end + +function demo3() + local win = window('white') + win:transform(400, 400, 240, 240) + + local renderer = Pre3d.Renderer(win) + local shape = ShapeUtils.makeSphere(1, 12, 12) + + renderer.draw_overdraw = true + renderer.draw_backfaces = false + renderer.fill_rgba = rgb(0x4A/255, 0x92/255, 0xBF/255) + renderer.fill_rgba_backside = rgb(0xBF/255, 0x92/255, 0x4A/255) + renderer.set_light_intensity = true +-- renderer.fill_rgba_alpha = 0.95 +-- renderer.stroke_rgba = rgb(0x66/255, 0x66/255, 0x66/255) + + renderer.camera.focal_length = 30; + + local N, tour = 256, 2*pi + for j=0, N do + local a = tour*j/N + setTransform(renderer.camera.transform, a, 0.15 * a) + draw(renderer, shape) + end +end |