LinaVG is a 2D vector graphics library providing low-level functionality to draw variety of anti-aliased convex shapes & lines, along with traditional and Signed-Distance-Field (SDF) text rendering. LinaVG also provides rich styling options including gradients, outlines, drop shadows, varying thickness, filled & non-filled shapes, text alignment/spacing and many more!
LinaVG does not provide a "rendering" functionality on its own. It generates buffers according to your draw calls and sends them back to a custom backend you determine in batches of optimized buffers.
That being said, the example project provides an example OpenGL backend you can basically copy and paste. Also Lina Engine uses LinaVG and have examples for custom DirectX12 backend. Please check Wiki for more details.
LinaVG's purpose is to provide you with an easy way to do low-level anti-aliased shape, line and text rendering. It does not provide any window management or input functionality, and it's not a GUI library. It assumes your application already has a graphics rendering backend and an application loop setup.
With that in mind, you can use LinaVG to build both retained and immediate mode GUI applications/libraries.
LinaVG was initially made for Lina Engine, however this library is completely decoupled from it. You can use LinaVG in your own projects with minimal dependencies.
LinaVG is tested on:
- MSVC 14.36.xxx
- Clang 17.0.1
LinaVG is thread-safe as long as no multiple threads modify the same LinaVG::Drawer object. Only global functions are not thread-safe at the moment are those used for loading fonts, which require wrapping around a mutex.
- Rectangle, triangle, ngon, circle, half-circle, arcs, user-defined convex shapes
- All shapes can be filled & non-filled
- Flat colors, vertical/horizontal/radial gradients
- Customizable thickness
- Textures, custom UV offsets, custom UV tiling
- Shape rounding, only rounding particular corners if desired
- Custom rotation
- Inner outlines, outer outlines & both
- Customizable outline thickness
- Flat colors, vertical/horizontal/radial gradients
- Textures, custom UV offsets, custom UV tiling
- Vector-based anti-aliasing borders
- Framebuffer scaled AA thickness
- User-defined AA multipliers
- Single lines
- Multi lines
- Bezier curves
- Line caps: Left, right & both
- Customizable line cap rounding
- Line Joints: Vertex Average, Miter, Bevel, Bevel Round
- All outline options apply to lines as well.
- Custom rotation only on single lines
- FreeType font loading
- SDF fonts
- Font atlases, atlas merging
- Custom glyph-ranges
- Unicode support
- Traditional anti-aliased bitmap glyph rendering
- Flat colors, vertical/horizontal gradients
- Drop shadows, customizable drop shadow color, customizable offsets.
- Character spacing
- Line spacing
- Word-wrapping
- Text alignment: Left, right & center
- Custom rotation
- All text options apply to SDF texts.
- SDF thickness
- SDF softness
- SDF outlines
- Custom draw orders, z-sorting
- Rect clipping
- Exposed configs, such as; garbage collection intervals, buffer reserves, AA params, line joint limits, texture flipping, debug functionality
Download a release from Releases.
Recommended way of using LinaVG is to link it together with your application using CMake. Alternatively, you can build the CMake project yourself and link to produced binaries, but please mind that you also have to link to the produced FreeType binaries if you choose to do it this way.
Use LINAVG_BUILD_EXAMPLES
option to build the example project.
cmake DLINAVG_BUILD_EXAMPLES=ON
Use LINAVG_DISABLE_TEXT_SUPPORT
option to skip text support and FreeType dependency.
cmake DLINAVG_DISABLE_TEXT_SUPPORT=ON
Note: LinaVG requires C++ 17 features.
Below is a bare-minimum implementation steps for drawing with LinaVG. As said in the home page, it's assumed that your application already has a graphics rendering backend setup and running, of course along with a window with a valid context.
#include "LinaVG.hpp"
LinaVG::Drawer lvgDrawer;
lvgDrawer.GetCallbacks().drawDefault = std::bind(&MyRenderingBackend::DrawDefault, &myRenderer, std::placeholders::_1);
// Your application loop
while (m_applicationRunning)
{
// Setup style, give a gradient color from red to blue.
StyleOptions style;
style.isFilled = true;
style.color.start = Vec4(1, 0, 0, 1);
style.color.end = Vec4(0, 0, 1, 1);
// Draw a 200x200 rectangle starting from 300, 300.
const Vec2 min = Vec2(300, 300);
const Vec2 max = Vec2(500, 500);
lvgDrawer.DrawRect(min, max, style);
lvgDrawer.FlushBuffers();
lvgDrawer.ResetFrame();
}
And that's basically it!
There are a lot more to LinaVG in regards to usage, configuration, other shapes/lines/texts and styling. Check out the rest of the Wiki or the example application to learn about them all.
Copyright [2022-] Inan Evin
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
Any contributions and PR are welcome.
You can join Lina Engine's Discord channel to talk about the Lina Project.