updated nanovg example
This commit is contained in:
parent
06c3c57954
commit
c3db81e0d5
28
demo/nanovg/.gitignore
vendored
Normal file
28
demo/nanovg/.gitignore
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
## Compiled source #
|
||||
*.com
|
||||
*.class
|
||||
*.dll
|
||||
*.exe
|
||||
*.o
|
||||
*.so
|
||||
test
|
||||
|
||||
## Logs and databases #
|
||||
*.log
|
||||
*.sql
|
||||
*.sqlite
|
||||
|
||||
## OS generated files #
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
## Build dir
|
||||
build/*
|
||||
|
||||
## xcode specific
|
||||
*xcuserdata*
|
18
demo/nanovg/LICENSE.txt
Normal file
18
demo/nanovg/LICENSE.txt
Normal file
@ -0,0 +1,18 @@
|
||||
Copyright (c) 2013 Mikko Mononen memon@inside.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
118
demo/nanovg/README.md
Normal file
118
demo/nanovg/README.md
Normal file
@ -0,0 +1,118 @@
|
||||
/work in progress.../
|
||||
|
||||
|
||||
NanoVG
|
||||
==========
|
||||
|
||||
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.
|
||||
|
||||
## Screenshot
|
||||
|
||||
![screenshot of some text rendered witht the sample program](/example/screenshot-01.png?raw=true)
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
The NanoVG API is modeled loosely on HTML5 canvas API. If you know canvas, you're up to speed with NanoVG in no time.
|
||||
|
||||
## Creating drawing context
|
||||
|
||||
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:
|
||||
```C
|
||||
#define NANOVG_GL2_IMPLEMENTATION // Use GL2 implementation.
|
||||
#include "nanovg_gl.h"
|
||||
...
|
||||
struct NVGcontext* vg = nvgCreateGL2(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
|
||||
```
|
||||
|
||||
The first parameter defines flags for creating the renderer.
|
||||
|
||||
- `NVG_ANTIALIAS` means that the renderer adjusts the geometry to include anti-aliasing. If you're using MSAA, you can omit this flags.
|
||||
- `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.
|
||||
|
||||
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.
|
||||
|
||||
## Drawing shapes with NanoVG
|
||||
|
||||
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.
|
||||
|
||||
```C
|
||||
nvgBeginPath(vg);
|
||||
nvgRect(vg, 100,100, 120,30);
|
||||
nvgFillColor(vg, nvgRGBA(255,192,0,255));
|
||||
nvgFill(vg);
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
## Understanding Composite Paths
|
||||
|
||||
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.
|
||||
|
||||
``` C
|
||||
nvgBeginPath(vg);
|
||||
nvgRect(vg, 100,100, 120,30);
|
||||
nvgCircle(vg, 120,120, 5);
|
||||
nvgPathWinding(vg, NVG_HOLE); // Mark circle as a hole.
|
||||
nvgFillColor(vg, nvgRGBA(255,192,0,255));
|
||||
nvgFill(vg);
|
||||
```
|
||||
|
||||
## Rendering is wrong, what to do?
|
||||
|
||||
- make sure you have created NanoVG context using one of the `nvgCreatexxx()` calls
|
||||
- make sure you have initialised OpenGL with stencil buffer
|
||||
- make sure you have cleared stencil buffer
|
||||
- make sure all rendering calls happen between `nvgBeginFrame()` and `nvgEndFrame()`
|
||||
- to enable more checks for OpenGL errors, add `NVG_DEBUG` flag to `nvgCreatexxx()`
|
||||
- if the problem still persists, please report an issue!
|
||||
|
||||
## OpenGL state touched by the backend
|
||||
|
||||
The OpenGL back-end touches following states:
|
||||
|
||||
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()`.
|
||||
|
||||
The data for the whole frame is buffered and flushed in `nvgEndFrame()`. The following code illustrates the OpenGL state touched by the rendering code:
|
||||
```C
|
||||
glUseProgram(prog);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
glFrontFace(GL_CCW);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glStencilMask(0xffffffff);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
glStencilFunc(GL_ALWAYS, 0, 0xffffffff);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, buf);
|
||||
glBindVertexArray(arr);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buf);
|
||||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
See the header file [nanovg.h](/src/nanovg.h) for API reference.
|
||||
|
||||
## Ports
|
||||
|
||||
- [DX11 port](https://github.com/cmaughan/nanovg) by [Chris Maughan](https://github.com/cmaughan)
|
||||
- [bgfx port](https://github.com/bkaradzic/bgfx/tree/master/examples/20-nanovg) by [Branimir Karadžić](https://github.com/bkaradzic)
|
||||
|
||||
## Projects using NanoVG
|
||||
|
||||
- [Processing API simulation by vinjn](https://github.com/vinjn/island/blob/master/examples/01-processing/sketch2d.h)
|
||||
|
||||
## License
|
||||
The library is licensed under [zlib license](LICENSE.txt)
|
||||
|
||||
## Discussions
|
||||
[NanoVG mailing list](https://groups.google.com/forum/#!forum/nanovg)
|
||||
|
||||
## Links
|
||||
Uses [stb_truetype](http://nothings.org) (or, optionally, [freetype](http://freetype.org)) for font rendering.
|
||||
Uses [stb_image](http://nothings.org) for image loading.
|
2752
demo/nanovg/nanovg.c
Normal file
2752
demo/nanovg/nanovg.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -4127,8 +4127,7 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
|
||||
static stbi_uc *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
||||
{
|
||||
stbi_uc *u = 0;
|
||||
stbi__gif g;
|
||||
memset(&g, 0, sizeof(g));
|
||||
stbi__gif g={0};
|
||||
|
||||
u = stbi__gif_load_next(s, &g, comp, req_comp);
|
||||
if (u == (void *) 1) u = 0; // end of animated gif marker
|
||||
|
Loading…
Reference in New Issue
Block a user