Lib Blend2D addon for OpenFrameworks : a blazing fast CPU 2D vector graphics renderer.
Forks
Forks pushed to more recently than Daandelange/ofxBlend2D itself, plus any admin-confirmed fork with commits of its own — worth checking if you're hitting issues with the original.
README
ofxBlend2D
An OpenFrameworks addon integrating libBlend2D, a blazing fast CPU 2D vector graphics renderer powered by a JIT compiler.
Features:
- The library is loaded as an embedded library with access to its C API and C++ objects.
- There's a wrapper (
ofxBlend2DThreadedRenderer) to use for asynchronous multithreaded rendering, keeping the framerate of your openFrameworks pipeline. - It can also be used synchronously (in blocking mode), at risk of reducing your
ofAppframerate.
- Draw commands are submitted by the main thread (a dedicated thread is also possible).
- Then the pipeline is flushed using multiple threads.
- When the threads are done rendering, the resulting pixels are loaded into an
ofTexture(from within the GL thread). - The texture is available for rendering and updates as soon as a new frame is available.
When to use
OpenFrameworks has its own renderer pipelines, why use a different one ?!? I can think of multiple use cases, but generally this should be thought of as an additional renderer rather than the main renderer. Depending on your needs, ofxBlend2D can be faster to render than OpenFrameworks, for example when your draw commands exceed real-time rendering capabilities of your GPU. This is typically useful on computers with a poor GPU and a good multithreaded CPU, or submitting lots of real-time (2d) vector data.See example-compare for a performance test, by adapting the draw code to your usecase. A comparison of Blend2D performance vs other CPU renderers is available on their homepage.
Compatibility
Tested on MacOs + Linux, both of_v0.11.2 and of_v0.12.0. (C++17 is required.) For C++14 you can downgrade libBlend2D to v0.11.5 or use commit 49af45713a5574203b122f8c1c24064f263ac64c. Should work on Windows too, probably with some inclusion fixes.Installation
- Warning! libBlend2D doesn't compile with Clang 3.8 and below (until Xcode 8.x).
xcode-select -s. - Clone recursively (to get the submodules).
- Install optional dependencies:
- ofxFPS to embed an FPS counter for the renderer.
- ofxImGui/develop to provide GUI helper widgets.
- Install
example-svgdependencies: (example-simpledoesn't need any) - The optional dependencies (above)
- ofxSvgLoader
- Install
example-comparedependencies: - ofxFPS
- ofxTimeMeasurements
Usage
For now, we have to use the Blend2D pipeline and commands, there is noofDraw...() compatibility yet. I recommend reading trough the Blend2D guide to get started using their graphics API.Some OpenFrameworks / Blend2D glue utilities are being written, any contribution is welcome to facilitate interaction with OF objects.
Please note that Blend2d runs on a JIT interpreter and performance varies a lot between Debug and Release builds due to their respective exported debug symbols and compile-time optimisations. For performance, prefer Release builds.
Configure
- ofxImGui compatibility: Optionally define
ofxBlend2D_ENABLE_IMGUI(orofxAddons_ENABLE_IMGUI) to enable some ofxImGui helpers likeofxBlend2DInstance.drawImGuiSettings().
Examples
example-simple: A bare-bones example of how to use the C++ Blend2D API, pretty similar to the Blend2D "getting started" examples.example-svg: Loads an SVG to provide someofPathwhich are converted toBLPathfor rendering in Blend2D. Also demonstrates the ofxImGui integration which lets you interactively change some settings.example-compare: A benchmarking and graphical comparison tool for comparing Blend2D rendering with native OpenFrameworks rendering. Also features saving a frame as PNG.
Contributions
Contributions are welcome, don't hesitate to submit a PR or open an issue for talking about bugs or new features.Future ideas
- Implement as ofRenderer subclass (would need porting all
ofDraw...functions to ofxBlend2D, it would provide an easier integration with OF). - Provide instructions for building libBlend2D as a library (to prevent recompiling for every single project).
- Offline rendering outputting to files.
ofxAddons