memononen / nanosvg

Simple stupid SVG parser
zlib License
1.71k stars 364 forks source link

Unable to render svgs properly #212

Closed DeDiamondPro closed 2 years ago

DeDiamondPro commented 2 years ago

Hi, I'm trying to use nanosvg in LWJGL3 to render a basic svg but something seems to be going wrong somewhere.

Expected result: e Result; image Code:

NSVGImage image = ImageLoader.INSTANCE.getSVG(filename);
NSVGShape shape = image.shapes();
NSVGPath path = shape.paths();
while (shape.address() != 0) {
          while (path.address() != 0) {
                 nvgBeginPath(vg);
                 nvgFillColor(vg, color(vg, new Color(255, 255, 255).getRGB()));
                 nvgStrokeColor(vg, color(vg, new Color(255, 255, 255).getRGB()));
                 nvgStrokeWidth(vg, shape.strokeWidth());
                 FloatBuffer points = path.pts();
                 nvgMoveTo(vg, points.get(), points.get());
                  while (points.remaining() >= 6) {
                       nvgBezierTo(vg, points.get(), points.get(), points.get(), points.get(), points.get(), points.get());
                  }
                  if (path.closed() == 1) {
                       nvgMoveTo(vg, points.get(0), points.get(1));
                  }
                  nvgStroke(vg);
                  nvgClosePath(vg);
                  path = path.next();
           }
           shape = shape.next();
}
path.free();
shape.free();

Things I tried:

Thanks in advance for your time.

DeDiamondPro commented 2 years ago

I ended up switching too rasterizing.