**vkvg** is a multiplatform **c** library for drawing 2D vector graphics with [Vulkan](https://www.khronos.org/vulkan/).
-[Cairo](https://www.cairographics.org/) was missing a Vulkan backend, so I decided to start one myself trying to keep my api as close to Cairo as possible. Maybe vkvg could serve as a starting point for Cairo maintainers to start their Vulkan backend.
+[Cairo](https://www.cairographics.org/) was missing a Vulkan backend, so I decided to start one myself trying to keep my api as close to Cairo as possible.
### Current status:
-vkvg is in early development stage, and no guarantee is given on the possible roadmap:
+**vkvg** is in early development stage, **0.1** beta release is on the road.
-- Basic shape fill and stroke functional, using ears clipping.
+- Fill (with stencil even-odd technic) and Stroke functional.
- Basic painting operation.
- Font system with caching operational.
-- Context should be thread safe, tests required.
-- Image loading with [stb lib](https://github.com/nothings/stb)
-- Nice logo.
+- Linear Gradients.
+- Line caps and joins.
+- Context should be thread safe, extensive tests required.
+- Image loading and writing with [stb lib](https://github.com/nothings/stb)
+- Test includes svg rendering with [nanoSVG](https://github.com/memononen/nanosvg)
### Requirements:
### Roadmap
-- Improve triangulation algorithm.
+- Radial gradients.
- Offscreen pattern building.
-- SVG rendering.
+- Avoid line joins inside curves and arc.
+- Structured unit testing.
+- Perf and memory checks.
+- Code clean and comment.
+- Documentations.
+
vkvg_arc (cr, xc, yc, radius, angle1, angle1);
vkvg_line_to (cr, xc, yc);
vkvg_arc (cr, xc, yc, radius, angle2, angle2);
- //vkvg_line_to (cr, xc, yc);
vkvg_stroke (cr);
}
void cairo_tests () {
VkvgContext ctx = vkvg_create(surf);
vkvg_set_source_rgba(ctx,0.7,0.7,0.7,1);
vkvg_paint(ctx);
- //cairo_print_arc(ctx);
- //cairo_test_clip(ctx);
- //vkvg_translate(ctx,200,0);
+
+ cairo_print_arc(ctx);
+
+ vkvg_translate(ctx,200,0);
cairo_test_fill_rule(ctx);
- //cairo_test_rounded_rect(ctx);
- //vkvg_translate(ctx,250,0);
- //cairo_test_curves(ctx);
-// vkvg_translate(ctx,200,0);
-// cairo_test_fill_and_stroke2(ctx);
-// vkvg_translate(ctx,-650,300);
- //vkvg_translate(ctx,250,0);
- //cairo_print_arc_neg(ctx);
+ vkvg_translate(ctx,250,0);
+ cairo_test_rounded_rect(ctx);
+
+ vkvg_translate(ctx,250,0);
+ cairo_test_curves(ctx);
+
+ vkvg_translate(ctx,-700,250);
+ cairo_test_fill_and_stroke2(ctx);
+
+ vkvg_translate(ctx,250,0);
+ cairo_print_arc_neg(ctx);
+
+ /*vkvg_translate(ctx,250,0);
+ cairo_test_clip(ctx);
+
+ vkvg_translate(ctx,250,0);
+ vkvg_test_fill_and_stroke(ctx);*/
- //vkvg_test_fill_and_stroke(ctx);
vkvg_destroy(ctx);
}
vkvg_set_source_rgba(ctx,1.0,1.0,1.0,1);
vkvg_paint(ctx);
- int cpt = 0;
- // Load
+ vkvg_scale(ctx,0.5,0.5);
+ vkvg_matrix_t m;
+ vkvg_get_matrix(ctx, &m);
+ vkvg_set_matrix(ctx, &m);
+
NSVGimage* svg;
NSVGshape* shape;
NSVGpath* path;
- svg = nsvgParseFromFile("/mnt/data/images/svg/tiger.svg", "px", 96);
+ svg = nsvgParseFromFile("/mnt/data/images/svg/tux.svg", "px", 96);
+ //svg = nsvgParseFromFile("/mnt/data/images/svg/world.svg", "px", 96);
+ //svg = nsvgParseFromFile("/mnt/data/images/svg/tiger.svg", "px", 96);
//svg = nsvgParseFromFile("/mnt/data/images/svg/WMD-biological.svg", "px", 96);
//svg = nsvgParseFromFile("/mnt/data/images/svg/Skull_and_crossbones.svg", "px", 96);
//svg = nsvgParseFromFile("/mnt/data/images/svg/IconAlerte.svg", "px", 96);
vkvg_fill_preserve (ctx);
}
- if (shape->stroke.type == NSVG_PAINT_COLOR){
+ if (shape->stroke.type == NSVG_PAINT_COLOR)
svg_set_color(ctx, shape->stroke.color, o);
- vkvg_stroke(ctx);
+ else if (shape->stroke.type == NSVG_PAINT_LINEAR_GRADIENT){
+ NSVGgradient* g = shape->stroke.gradient;
+ svg_set_color(ctx, g->stops[0].color, o);
}
- //vkvg_stroke(ctx);
- //cpt++;
- //if (cpt>290)
- // break;
+
+ vkvg_stroke(ctx);
+
vkvg_flush(ctx);
}
+
nsvgDelete(svg);
vkvg_destroy(ctx);
device = vkvg_device_create(e->phy, e->dev, e->renderer.queue, e->renderer.qFam);
surf = vkvg_surface_create (device,1024,800);
- test_svg();
+ //test_svg();
//multi_test1();
//test_grad_transforms();
- //cairo_tests();
+ cairo_tests();
//test_colinear();