ThorVG Example provides a wide range of example codes. Those examples demonstrate how to use ThorVG's APIs to render vector graphics, handle images, and play animations. Each example is designed to highlight specific features and help developers get started quickly with ThorVG.
This section details the steps required to configure the environment for installing ThorVG Example. Please note that ThorVG and ThorVG Toolkit must be installed on your system before building the examples. Install ThorVG first, then ThorVG Toolkit.
ThorVG Example supports Meson build system. Install meson and ninja if you don't have them already.
Run Meson to configure ThorVG Example in the project root folder.
meson setup builddir
Run ninja to build
ninja -C builddir
Once the build is complete, you can run each example binary directly from the builddir folder.
To run an example with the GL or WebGPU engine, pass -e gl or -e wg as a command-line argument. By default, the examples run with the cpu rendering engine.
./builddir/src/Shapes # Runs with Software (default)
./builddir/src/Shapes -e gl # Runs with OpenGL/ES
./builddir/src/Shapes -e wg # Runs with WebGPU
./builddir/src/Shapes -r 1200x1200 # Runs with a 1200x1200 window
./builddir/src/Shapes -t 3 # Runs with 3 worker threads
./builddir/src/Shapes --fps # Enables FPS (frames per second) output
./builddir/src/Picture -i <input_path> # Loads and renders the given asset
Options can be combined when applicable:
./builddir/src/Animation -e wg -r 1200x1200 -i ./sample.json
This runs the Animation example using the WebGPU engine with a 1200x1200 window and the specified input asset.
| Option | Description | Default |
|---|---|---|
-e <engine> |
Select the rendering engine: gl for OpenGL/ES or wg for WebGPU. |
CPU (software) |
-r <width>x<height> |
Set the window size in pixels. Both dimensions must be positive integers. | Example-specific |
-i <filepath> |
Set the input asset path. Supported by Animation, Lottie, Picture, Svg, and Video. | Example-specific |
-t <threads> |
Set the number of worker threads, capped at a max thread. | 4 |
--fps |
Print average main loop FPS to the console once per second. | Disabled |