# LinaVG
**Repository Path**: water_source/LinaVG
## Basic Information
- **Project Name**: LinaVG
- **Description**: LinaVG 是一个 2D 矢量图形库,提供低级功能来绘制各种抗锯齿凸形状和线条,以及传统和签名距离场(SDF)文本渲染。LinaVG 还提供了丰富的样式选项,包括渐变,轮廓,阴影,不同的厚度,填充和非填充形状,文本对齐/间距等。
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2023-07-31
- **Last Updated**: 2023-07-31
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
[](https://opensource.org/licenses/MIT)
[](https://paypal.me/inanevin)
[](https://discord.gg/QYeTkEtRMB)
[](https://www.codacy.com/gh/inanevin/LinaVG/dashboard?utm_source=github.com&utm_medium=referral&utm_content=inanevin/LinaVG&utm_campaign=Badge_Grade)
[](https://github.com/inanevin/LinaVG/issues)

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](https://github.com/inanevin/LinaEngine) uses LinaVG and have examples for custom DirectX12 backend. Please check [Wiki](https://github.com/inanevin/LinaVG/wiki) for more details.
# What
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](https://www.github.com/inanevin/LinaEngine), however this library is completely decoupled from it. You can use LinaVG in your own projects with minimal dependencies.
# Thread-safety
LinaVG is thread-safe as long as the [Threading](https://github.com/inanevin/LinaVG/wiki/13-Threading) guidelines are followed. Only functions that are not thread-safe at the moment are those used for loading fonts, which require wrapping around a mutex.
# Features

## Shapes
* 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
## Outlines
* Inner outlines, outer outlines & both
* Customizable outline thickness
* Flat colors, vertical/horizontal/radial gradients
* Textures, custom UV offsets, custom UV tiling
## AA
* Vector-based anti-aliasing borders
* Framebuffer scaled AA thickness
* User-defined AA multipliers
## Lines
* 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
## Fonts
* FreeType font loading
* SDF fonts
* Font atlases, atlas merging
* Custom glyph-ranges
* Unicode support
## Texts
* 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
## SDF
* All text options apply to SDF texts.
* SDF thickness
* SDF softness
* SDF outlines
## Utility
* 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
# Installation
Download a release from [Releases](https://github.com/inanevin/LinaVG/releases). The zip file will contain pre-built binaries for LinaVG and FreeType.
If you want to use text drawing functionalities:
- Your application first needs to link against & include FreeType.
- Then link against & include LinaVG.
- ```#define LINAVG_TEXT_SUPPORT``` before including ``````.
If you don't want to use text drawing:
- You can directly link against and include LinaVG, omit FreeType. Don't define text support macro.
The pre-built binaries and LinaVG core do not support any kind of rendering backend. You are expected to provide your own backend. You can of course make use of the example OpenGL backend given in the Example project.
Note: LinaVG requires C++ 17 features.
# Demo Application
You can download this whole repository and generate the project files using CMake to run the example application, demonstrating all capabilities of LinaVG.
```shell
# Clone repo
git clone https://github.com/inanevin/LinaVG
# Create target dir & cd
mkdir build_x64
cd build_x64
# Build LinaVG w/ examples & text support
cmake ../ -DLINAVG_TEXT_SUPPORT=ON -DLINAVG_BUILD_EXAMPLES=ON -G "Visual Studio 17 2022" -A "x64"
# After the project files are generated, you can build the project via
cmake --build . --target ALL_BUILD
```
CMake build process downloads the pre-built dependencies during configuration. If you choose to build & run the demo application using another method, remember to get the required dependency binaries from [Lina Dependencies](https://github.com/inanevin/LinaDependencies/tree/linavg) repository.
# Quick Demonstration
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.
```cpp
// Include LinaVG
#include "LinaVG.hpp"
// Initialize LinaVG
LinaVG::Initialize();
// Your application loop
while (m_applicationRunning)
{
// Let LinaVG know that we are starting to render.
LinaVG::StartFrame();
// 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);
LinaVG::DrawRect(min, max, style);
// Finally, flush all the buffers and render to screen.
LinaVG::Render();
// Let LinaVG know that we are finishing this frame
LinaVG::EndFrame();
}
// Terminate LinaVG before exiting your application.
LinaVG::Terminate();
```
And that's basically it! Now you should have this on your screen, easy peasy.

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.
# License
[](https://opensource.org/licenses/MIT)
[LICENSE.MD](https://github.com/inanevin/LinaVG/blob/master/LICENSE)
# Contributing
Any contributions and PR are welcome.
# Support
You can join [Lina Engine's Discord channel](https://discord.gg/QYeTkEtRMB) to talk about the Lina Project.
[](https://discord.gg/QYeTkEtRMB)