Skip to content

Commit b6168be

Browse files
committed
Add NanoVG properly
1 parent d8c316b commit b6168be

47 files changed

Lines changed: 24262 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Core/vendor/nanovg

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
env:
6+
BUILD_TYPE: release
7+
8+
jobs:
9+
build:
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ ubuntu-latest]
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Install required packages
19+
run: sudo apt-get install premake4 build-essential libglfw3-dev libglew-dev pkg-config
20+
21+
- name: Premake
22+
run: premake4 gmake
23+
24+
# due to glew problems with in the current ubuntu-latest, we don't build the examples (yet)
25+
# https://github.com/openai/mujoco-py/issues/383 has the same problem for reference
26+
# this doesn't happen in focal
27+
- name: Make
28+
run: cd build && make nanovg

Core/vendor/nanovg/.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Compiled source #
2+
*.com
3+
*.class
4+
*.dll
5+
*.exe
6+
*.o
7+
*.so
8+
test
9+
10+
## Logs and databases #
11+
*.log
12+
*.sql
13+
*.sqlite
14+
15+
## OS generated files #
16+
.DS_Store
17+
.DS_Store?
18+
._*
19+
.Spotlight-V100
20+
.Trashes
21+
ehthumbs.db
22+
Thumbs.db
23+
24+
## Build dir
25+
build/*
26+
27+
## xcode specific
28+
*xcuserdata*

Core/vendor/nanovg/LICENSE.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Copyright (c) 2013 Mikko Mononen memon@inside.org
2+
3+
This software is provided 'as-is', without any express or implied
4+
warranty. In no event will the authors be held liable for any damages
5+
arising from the use of this software.
6+
7+
Permission is granted to anyone to use this software for any purpose,
8+
including commercial applications, and to alter it and redistribute it
9+
freely, subject to the following restrictions:
10+
11+
1. The origin of this software must not be misrepresented; you must not
12+
claim that you wrote the original software. If you use this software
13+
in a product, an acknowledgment in the product documentation would be
14+
appreciated but is not required.
15+
2. Altered source versions must be plainly marked as such, and must not be
16+
misrepresented as being the original software.
17+
3. This notice may not be removed or altered from any source distribution.
18+

Core/vendor/nanovg/README.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
*This project is not actively maintained.*
2+
3+
NanoVG
4+
==========
5+
6+
NanoVG is small antialiased vector graphics rendering library for OpenGL. It has lean API modeled after HTML5 canvas API. It is aimed to be a practical and fun toolset for building scalable user interfaces and visualizations.
7+
8+
## Screenshot
9+
10+
![screenshot of some text rendered witht the sample program](/example/screenshot-01.png?raw=true)
11+
12+
Usage
13+
=====
14+
15+
The NanoVG API is modeled loosely on HTML5 canvas API. If you know canvas, you're up to speed with NanoVG in no time.
16+
17+
## Creating drawing context
18+
19+
The drawing context is created using platform specific constructor function. If you're using the OpenGL 2.0 back-end the context is created as follows:
20+
```C
21+
#define NANOVG_GL2_IMPLEMENTATION // Use GL2 implementation.
22+
#include "nanovg_gl.h"
23+
...
24+
struct NVGcontext* vg = nvgCreateGL2(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
25+
```
26+
27+
The first parameter defines flags for creating the renderer.
28+
29+
- `NVG_ANTIALIAS` means that the renderer adjusts the geometry to include anti-aliasing. If you're using MSAA, you can omit this flags.
30+
- `NVG_STENCIL_STROKES` means that the render uses better quality rendering for (overlapping) strokes. The quality is mostly visible on wider strokes. If you want speed, you can omit this flag.
31+
32+
Currently there is an OpenGL back-end for NanoVG: [nanovg_gl.h](/src/nanovg_gl.h) for OpenGL 2.0, OpenGL ES 2.0, OpenGL 3.2 core profile and OpenGL ES 3. The implementation can be chosen using a define as in above example. See the header file and examples for further info.
33+
34+
*NOTE:* The render target you're rendering to must have stencil buffer.
35+
36+
## Drawing shapes with NanoVG
37+
38+
Drawing a simple shape using NanoVG consists of four steps: 1) begin a new shape, 2) define the path to draw, 3) set fill or stroke, 4) and finally fill or stroke the path.
39+
40+
```C
41+
nvgBeginPath(vg);
42+
nvgRect(vg, 100,100, 120,30);
43+
nvgFillColor(vg, nvgRGBA(255,192,0,255));
44+
nvgFill(vg);
45+
```
46+
47+
Calling `nvgBeginPath()` will clear any existing paths and start drawing from blank slate. There are number of number of functions to define the path to draw, such as rectangle, rounded rectangle and ellipse, or you can use the common moveTo, lineTo, bezierTo and arcTo API to compose the paths step by step.
48+
49+
## Understanding Composite Paths
50+
51+
Because of the way the rendering backend is build in NanoVG, drawing a composite path, that is path consisting from multiple paths defining holes and fills, is a bit more involved. NanoVG uses even-odd filling rule and by default the paths are wound in counter clockwise order. Keep that in mind when drawing using the low level draw API. In order to wind one of the predefined shapes as a hole, you should call `nvgPathWinding(vg, NVG_HOLE)`, or `nvgPathWinding(vg, NVG_CW)` _after_ defining the path.
52+
53+
``` C
54+
nvgBeginPath(vg);
55+
nvgRect(vg, 100,100, 120,30);
56+
nvgCircle(vg, 120,120, 5);
57+
nvgPathWinding(vg, NVG_HOLE); // Mark circle as a hole.
58+
nvgFillColor(vg, nvgRGBA(255,192,0,255));
59+
nvgFill(vg);
60+
```
61+
62+
## Rendering is wrong, what to do?
63+
64+
- make sure you have created NanoVG context using one of the `nvgCreatexxx()` calls
65+
- make sure you have initialised OpenGL with *stencil buffer*
66+
- make sure you have cleared stencil buffer
67+
- make sure all rendering calls happen between `nvgBeginFrame()` and `nvgEndFrame()`
68+
- to enable more checks for OpenGL errors, add `NVG_DEBUG` flag to `nvgCreatexxx()`
69+
- if the problem still persists, please report an issue!
70+
71+
## OpenGL state touched by the backend
72+
73+
The OpenGL back-end touches following states:
74+
75+
When textures are uploaded or updated, the following pixel store is set to defaults: `GL_UNPACK_ALIGNMENT`, `GL_UNPACK_ROW_LENGTH`, `GL_UNPACK_SKIP_PIXELS`, `GL_UNPACK_SKIP_ROWS`. Texture binding is also affected. Texture updates can happen when the user loads images, or when new font glyphs are added. Glyphs are added as needed between calls to `nvgBeginFrame()` and `nvgEndFrame()`.
76+
77+
The data for the whole frame is buffered and flushed in `nvgEndFrame()`. The following code illustrates the OpenGL state touched by the rendering code:
78+
```C
79+
glUseProgram(prog);
80+
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
81+
glEnable(GL_CULL_FACE);
82+
glCullFace(GL_BACK);
83+
glFrontFace(GL_CCW);
84+
glEnable(GL_BLEND);
85+
glDisable(GL_DEPTH_TEST);
86+
glDisable(GL_SCISSOR_TEST);
87+
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
88+
glStencilMask(0xffffffff);
89+
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
90+
glStencilFunc(GL_ALWAYS, 0, 0xffffffff);
91+
glActiveTexture(GL_TEXTURE0);
92+
glBindBuffer(GL_UNIFORM_BUFFER, buf);
93+
glBindVertexArray(arr);
94+
glBindBuffer(GL_ARRAY_BUFFER, buf);
95+
glBindTexture(GL_TEXTURE_2D, tex);
96+
glUniformBlockBinding(... , GLNVG_FRAG_BINDING);
97+
```
98+
99+
## API Reference
100+
101+
See the header file [nanovg.h](/src/nanovg.h) for API reference.
102+
103+
## Ports
104+
105+
- [DX11 port](https://github.com/cmaughan/nanovg) by [Chris Maughan](https://github.com/cmaughan)
106+
- [Metal port](https://github.com/ollix/MetalNanoVG) by [Olli Wang](https://github.com/olliwang)
107+
- [bgfx port](https://github.com/bkaradzic/bgfx/tree/master/examples/20-nanovg) by [Branimir Karadžić](https://github.com/bkaradzic)
108+
109+
## Projects using NanoVG
110+
111+
- [Processing API simulation by vinjn](https://github.com/island-org/island/blob/master/include/sketch2d.h)
112+
- [NanoVG for .NET, C# P/Invoke binding](https://github.com/sbarisic/nanovg_dotnet)
113+
114+
## License
115+
The library is licensed under [zlib license](LICENSE.txt)
116+
Fonts used in examples:
117+
- Roboto licensed under [Apache license](http://www.apache.org/licenses/LICENSE-2.0)
118+
- Entypo licensed under CC BY-SA 4.0.
119+
- Noto Emoji licensed under [SIL Open Font License, Version 1.1](http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL)
120+
121+
## Discussions
122+
[NanoVG mailing list](https://groups.google.com/forum/#!forum/nanovg)
123+
124+
## Links
125+
Uses [stb_truetype](http://nothings.org) (or, optionally, [freetype](http://freetype.org)) for font rendering.
126+
Uses [stb_image](http://nothings.org) for image loading.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
This Font Software is licensed under the SIL Open Font License,
2+
Version 1.1.
3+
4+
This license is copied below, and is also available with a FAQ at:
5+
http://scripts.sil.org/OFL
6+
7+
-----------------------------------------------------------
8+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
9+
-----------------------------------------------------------
10+
11+
PREAMBLE
12+
The goals of the Open Font License (OFL) are to stimulate worldwide
13+
development of collaborative font projects, to support the font
14+
creation efforts of academic and linguistic communities, and to
15+
provide a free and open framework in which fonts may be shared and
16+
improved in partnership with others.
17+
18+
The OFL allows the licensed fonts to be used, studied, modified and
19+
redistributed freely as long as they are not sold by themselves. The
20+
fonts, including any derivative works, can be bundled, embedded,
21+
redistributed and/or sold with any software provided that any reserved
22+
names are not used by derivative works. The fonts and derivatives,
23+
however, cannot be released under any other type of license. The
24+
requirement for fonts to remain under this license does not apply to
25+
any document created using the fonts or their derivatives.
26+
27+
DEFINITIONS
28+
"Font Software" refers to the set of files released by the Copyright
29+
Holder(s) under this license and clearly marked as such. This may
30+
include source files, build scripts and documentation.
31+
32+
"Reserved Font Name" refers to any names specified as such after the
33+
copyright statement(s).
34+
35+
"Original Version" refers to the collection of Font Software
36+
components as distributed by the Copyright Holder(s).
37+
38+
"Modified Version" refers to any derivative made by adding to,
39+
deleting, or substituting -- in part or in whole -- any of the
40+
components of the Original Version, by changing formats or by porting
41+
the Font Software to a new environment.
42+
43+
"Author" refers to any designer, engineer, programmer, technical
44+
writer or other person who contributed to the Font Software.
45+
46+
PERMISSION & CONDITIONS
47+
Permission is hereby granted, free of charge, to any person obtaining
48+
a copy of the Font Software, to use, study, copy, merge, embed,
49+
modify, redistribute, and sell modified and unmodified copies of the
50+
Font Software, subject to the following conditions:
51+
52+
1) Neither the Font Software nor any of its individual components, in
53+
Original or Modified Versions, may be sold by itself.
54+
55+
2) Original or Modified Versions of the Font Software may be bundled,
56+
redistributed and/or sold with any software, provided that each copy
57+
contains the above copyright notice and this license. These can be
58+
included either as stand-alone text files, human-readable headers or
59+
in the appropriate machine-readable metadata fields within text or
60+
binary files as long as those fields can be easily viewed by the user.
61+
62+
3) No Modified Version of the Font Software may use the Reserved Font
63+
Name(s) unless explicit written permission is granted by the
64+
corresponding Copyright Holder. This restriction only applies to the
65+
primary font name as presented to the users.
66+
67+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
68+
Software shall not be used to promote, endorse or advertise any
69+
Modified Version, except to acknowledge the contribution(s) of the
70+
Copyright Holder(s) and the Author(s) or with their explicit written
71+
permission.
72+
73+
5) The Font Software, modified or unmodified, in part or in whole,
74+
must be distributed entirely under this license, and must not be
75+
distributed under any other license. The requirement for fonts to
76+
remain under this license does not apply to any document created using
77+
the Font Software.
78+
79+
TERMINATION
80+
This license becomes null and void if any of the above conditions are
81+
not met.
82+
83+
DISCLAIMER
84+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
86+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
87+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
88+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
89+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
90+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
91+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
92+
OTHER DEALINGS IN THE FONT SOFTWARE.
409 KB
Binary file not shown.
133 KB
Binary file not shown.
137 KB
Binary file not shown.
142 KB
Binary file not shown.

0 commit comments

Comments
 (0)