https://github.com/crushedpixel/polyline2d
A header-only library to generate meshes for a solid path. Useful to render thick lines using OpenGL.
https://github.com/crushedpixel/polyline2d
2d-graphics mesh opengl polyline
Last synced: 1 day ago
JSON representation
A header-only library to generate meshes for a solid path. Useful to render thick lines using OpenGL.
- Host: GitHub
- URL: https://github.com/crushedpixel/polyline2d
- Owner: CrushedPixel
- License: mit
- Created: 2019-01-23T01:37:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-05T18:20:59.000Z (about 1 year ago)
- Last Synced: 2025-01-17T07:05:33.368Z (4 months ago)
- Topics: 2d-graphics, mesh, opengl, polyline
- Language: C++
- Homepage:
- Size: 18.6 KB
- Stars: 193
- Watchers: 9
- Forks: 21
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Polyline2D
*Polyline2D* is a header-only C++17 library that generates a triangle mesh from a list of points.
It can be used to draw thick lines with rendering APIs like *OpenGL*, which do not support line drawing out of the box.
It supports common joint and end cap styles.## Example usage
```c++
#include
using namespace crushedpixel;std::vector points{
{ -0.25f, -0.5f },
{ -0.25f, 0.5f },
{ 0.25f, 0.25f },
{ 0.0f, 0.0f },
{ 0.25f, -0.25f },
{ -0.4f, -0.25f }
};auto thickness = 0.1f;
auto vertices = Polyline2D::create(points, thickness,
Polyline2D::JointStyle::ROUND,
Polyline2D::EndCapStyle::SQUARE);// render vertices, for example using OpenGL...
```
This code results in the following mesh:

For demonstration purposes, the generated mesh is once rendered in wireframe mode (light green), and once in fill mode (transparent green).The red points show the input points.
There is *no overdraw* within segments, only lines that overlap are filled twice.
For an example application using this software, visit [Polyline2DExample](https://github.com/CrushedPixel/Polyline2DExample).
## Installation
### Manual
To use *Polyline2D*, simply clone this repository and include the file `Polyline2D.h` from the `include` directory.### Using CMake
To install the header files into your global header directory, you can use CMake:
```
mkdir build
cd build
cmake ..
make install
```You can then include the header file using `#include `.
## Attribution and similar projects
The concepts and maths behind this project are largely inspired by [this amazing blog post](https://artgrammer.blogspot.com/2011/07/drawing-polylines-by-tessellation.html) by "To be an Artgrammer".Check out the original author's project
[vaserenderer](https://github.com/tyt2y3/vaserenderer), which also offers
a C# implementation based on fragment shaders.