Code Monkey home page Code Monkey logo

nanovg-rs's Introduction

NanoVG - Rust Wrapper

NanoVG-RS is a wrapper around the NanoVG vector graphics library for the Rust programming language.

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.

NanoVG-RS provides a fully featured, functional, high-level and Rust-idiomatic API on top of the NanoVG C-API.

Building

We recommend grabbing the latest release from crates.io.

Alternatively, you can clone and build the library yourself:

git clone --recursive https://github.com/KevinKelley/nanovg-rs
cd nanovg-rs
cargo build --features "gl3"

This library comes with a couple examples:

  • very useful example called demo-glutin. If you want to make sure that nanovg is working on your system, clone and build this crate as shown above and run the command cargo run --example demo-glutin --features="gl3". This should produce a window similar to that below.
  • a clock example, 'demo-clock', because who doesn't like clocks? And I needed to get rotation transforms working. Run it with cargo run --example demo-clock --features "gl3"

Note that when running the examples, the needed resources might not be found if you run it without a cargo run --example command. Thist is just a working-directory path issue.

Usage

Add the following to your Cargo.toml:

[dependencies.nanovg]
version = "Use the latest version from crates.io"
features = ["glX"]

glX can be exactly one of gl2, gl3, gles2 or gles3, to specify the version of OpenGL to use. Use gl3 or gl2 for computers and gles3 or gles2 for mobile devices.

TODO: SIMPLE API GUIDE

Screenshots

You can see more screenshots here.

demo-ui Output of the demo-ui example.

Interesting Links

License and Credits

The binding is licensed under the MIT license. NanoVG is released under the zlib license.

Test-font Mechanic of the Heart by Agathe M.Joyce.

nanovg-rs's People

Contributors

dleslie avatar enex avatar genbattle avatar gw3583 avatar haudan avatar henrikno avatar kevinkelley avatar lordi avatar mruegenberg avatar mthiesen avatar netvl avatar oipo avatar porky11 avatar readmecritic avatar richard-hozak avatar sergejjurecko avatar tamamu avatar wbogocki avatar wezm avatar whitequark avatar zxey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nanovg-rs's Issues

Upgrade to newer nanovg version

This crate currently targets a outdated nanovg commit from 2015. Upgrading to a newer version is probably a very good idea. I'm not a nanovg pro so I don't know specifics, but I assume not much has changed API wise, so the upgrade should be mostly straight forward.

nanovg-rs doesn't compile

Hi,
nanovg-rs doesn't compile on Macosx 10.9.4 using cargo 0.0.1 and rustc 0.12.0:

"
p:nanovg-rs p$ cargo build
the [[lib]] section has been deprecated in favor of [lib]
Compiling nanovg v0.2.0 (file:///Users/p/Desktop/RustTests/nanovg-rs)
Process didn't exit successfully: make -f nanovg.mk (status=2)
--- stdout
mkdir -p "/Users/p/Desktop/RustTests/nanovg-rs/target/native/nanovg-13b844ec41c928f9"

cd "/Users/p/Desktop/RustTests/nanovg-rs/target/native/nanovg-13b844ec41c928f9" && ([[ -d "nanovg" ]] && (cd nanovg; git pull) || git clone https://github.com/KevinKelley/nanovg)

cd "/Users/p/Desktop/RustTests/nanovg-rs/target/native/nanovg-13b844ec41c928f9" && ([ -d "nanovg" ] && (cd nanovg; git pull) || git clone https://github.com/memononen/nanovg)
Already up-to-date.
cd "/Users/p/Desktop/RustTests/nanovg-rs/target/native/nanovg-13b844ec41c928f9/nanovg" && premake4 gmake

--- stderr
/bin/sh: premake4: command not found
make: *** [/Users/p/Desktop/RustTests/nanovg-rs/target/native/nanovg-13b844ec41c928f9/libnanovg.a] Error 127"

Nested `transformed` calls on the root frame are allowed

Consider the following code:

extern crate nanovg as nvg;

use nvg::Transform;

fn main() {
    let ctx = nvg::ContextBuilder::new().build().unwrap();
    ctx.frame((10, 10), 1.0, |frame| {
        frame.transformed(Transform::new(), |f2| {
            frame.transformed(Transform::new(), |f3| {});
        });
    });
}

What should the transformation for f3 be?

  • frame * f2 * f3: Very misleading, because frame.transformed(Transform::new(), |f3| {}); would imply only frame * f3.
  • frame * f3: Also misleading, because why is this possible to create a "sibling transform" as a "child transform"?

I propose to disallow calling transformed on the root frame inside nested frames.

Edit: Removed mut keywords from above snippet (accidental copy-paste error).

Improve Transform & Scissor

See #44

Work on branch transform_scissor

Progress:

  • Clarify the meaning of the Transform setters by making them constructors with a from_* naming convention.
  • Provide conversion between Transform and 4x4 matrices.
    • Transform to 4x4.
    • 4x4 to Transform (is this even possible? You would lose properties of the transform, right?)
  • Provide multiplication methods for Transform
    • Transform * Transform
    • Transform * f32 and f32 * Transform (good idea?)
  • Provide a way to transform a Scissor by a Transform
    • Rotation
    • Details tbd.
  • Provide a way to create intersection-scissors by intersecting a fresh scissor with a transformed scissor
  • Make Scissor not keep it's state globally. Reset it for every Path, just like with Transform

More tbd.

Not compiling on Arch Linux

failed to run custom build command for `nanovg v0.2.0 (file:///home/jeroen/Documents/Projects/nanovg-rs)`
Process didn't exit successfully: `/home/jeroen/Documents/Projects/nanovg-rs/target/debug/build/nanovg-34d3720beaf1d9ae/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("x86_64-unknown-linux-gnu")
TARGET = Some("x86_64-unknown-linux-gnu")
CARGO_MANIFEST_DIR = Some("/home/jeroen/Documents/Projects/nanovg-rs")
OUT_DIR = Some("/home/jeroen/Documents/Projects/nanovg-rs/target/debug/build/nanovg-34d3720beaf1d9ae/out")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
debug 0
TARGET = Some("x86_64-unknown-linux-gnu")
HOST = Some("x86_64-unknown-linux-gnu")
CC_x86_64-unknown-linux-gnu = None
CC_x86_64_unknown_linux_gnu = None
HOST_CC = None
CC = None
TARGET = Some("x86_64-unknown-linux-gnu")
HOST = Some("x86_64-unknown-linux-gnu")
CFLAGS_x86_64-unknown-linux-gnu = None
CFLAGS_x86_64_unknown_linux_gnu = None
HOST_CFLAGS = None
CFLAGS = None
running: "cc" "-O0" "-c" "-ffunction-sections" "-fdata-sections" "-g" "-m64" "-fPIC" "-I" "nanovg/src" "-I" "nanovg/example" "-o" "/home/jeroen/Documents/Projects/nanovg-rs/target/debug/build/nanovg-34d3720beaf1d9ae/out/nanovg/src/nanovg.o" "/home/jeroen/Documents/Projects/nanovg-rs/nanovg/src/nanovg.c"


command did not execute successfully, got: exit code: 1



--- stderr
cc: error: /home/jeroen/Documents/Projects/nanovg-rs/nanovg/src/nanovg.c: No such file or directory
cc: fatal error: no input files
compilation terminated.
thread '<main>' panicked at 'explicit panic', /home/jeroen/.multirust/toolchains/stable/cargo/registry/src/github.com-1ecc6299db9ec823/gcc-0.3.10/src/lib.rs:514

NanoVG + SDL2 results in missing OpenGL references

Trying to compile NanoVG + SDL2 results in the following:

error: linking with `cc` failed: exit code: 1 
note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/oipo/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/example.0.o" "-o" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/example" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps" "-L" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/build/nanovg-50ea647ce203bf77/out" "-L" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/build/png-3fe3db068e366aa6/out" "-L" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/build/png-sys-3715ded1ea8759b1/out/.libs" "-L" "/usr/lib/x86_64-linux-gnu" "-L" "/home/oipo/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libgl-be53465f748324c7.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libsdl2-99eee13a97cfac5c.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libbitflags-b8c7fb7df9b2bc2e.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libbitflags-7f195425ed5f21fc.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libsdl2_sys-f2b6c7dfddd5d66c.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnum-45a7f1df1ffbcf4c.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnum_rational-7726582d22be0b52.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnum_bigint-a144dbec313e5e23.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnum_complex-704ef091ce88b7b2.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/liblazy_static-359f5533c970cd71.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnum_iter-50df698bc905252c.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnum_integer-52fdddf28cd8e924.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnum_traits-a6dde7de4ab4b779.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/librand-49a08859d086fffe.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/liblibc-1bd8847afb79f283.rlib" "/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/librustc_serialize-3561541d79c18212.rlib" "/home/oipo/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-c8005792.rlib" "/home/oipo/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-c8005792.rlib" "/home/oipo/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-c8005792.rlib" "/home/oipo/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-c8005792.rlib" "/home/oipo/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-c8005792.rlib" "/home/oipo/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-c8005792.rlib" "/home/oipo/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-c8005792.rlib" "/home/oipo/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-c8005792.rlib" "/home/oipo/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-c8005792.rlib" "/home/oipo/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-c8005792.rlib" "-l" "SDL2" "-l" "SDL2" "-l" "util" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util" "-l" "compiler-rt" 
note: /home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__bindTexture':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:276: undefined reference to `glBindTexture'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__stencilMask':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:288: undefined reference to `glStencilMask'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__stencilFunc':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:305: undefined reference to `glStencilFunc'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__deleteTexture':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:356: undefined reference to `glDeleteTextures'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__dumpShaderError':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:368: undefined reference to `glGetShaderInfoLog'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__dumpProgramError':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:378: undefined reference to `glGetProgramInfoLog'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__checkError':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:388: undefined reference to `glGetError'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__createShader':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:405: undefined reference to `glCreateProgram'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:406: undefined reference to `glCreateShader'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:407: undefined reference to `glCreateShader'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:409: undefined reference to `glShaderSource'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:411: undefined reference to `glShaderSource'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:413: undefined reference to `glCompileShader'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:414: undefined reference to `glGetShaderiv'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:420: undefined reference to `glCompileShader'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:421: undefined reference to `glGetShaderiv'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:427: undefined reference to `glAttachShader'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:428: undefined reference to `glAttachShader'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:430: undefined reference to `glBindAttribLocation'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:431: undefined reference to `glBindAttribLocation'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:433: undefined reference to `glLinkProgram'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:434: undefined reference to `glGetProgramiv'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__deleteShader':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:450: undefined reference to `glDeleteProgram'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:452: undefined reference to `glDeleteShader'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:454: undefined reference to `glDeleteShader'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__getUniforms':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:459: undefined reference to `glGetUniformLocation'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:460: undefined reference to `glGetUniformLocation'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:463: undefined reference to `glGetUniformBlockIndex'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__renderCreate':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:659: undefined reference to `glGenVertexArrays'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:661: undefined reference to `glGenBuffers'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:665: undefined reference to `glUniformBlockBinding'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:666: undefined reference to `glGenBuffers'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:667: undefined reference to `glGetIntegerv'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:673: undefined reference to `glFinish'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__renderCreateTexture':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:701: undefined reference to `glGenTextures'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:708: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:710: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:711: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:712: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:723: undefined reference to `glTexImage2D'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:730: undefined reference to `glTexImage2D'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:734: undefined reference to `glTexParameteri'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:736: undefined reference to `glTexParameteri'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:738: undefined reference to `glTexParameteri'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:741: undefined reference to `glTexParameteri'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:743: undefined reference to `glTexParameteri'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o):/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:746: more undefined references to `glTexParameteri' follow
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__renderCreateTexture':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:750: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:752: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:753: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:754: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:760: undefined reference to `glGenerateMipmap'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__renderUpdateTexture':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:785: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:788: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:789: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:790: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:802: undefined reference to `glTexSubImage2D'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:807: undefined reference to `glTexSubImage2D'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:810: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:812: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:813: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:814: undefined reference to `glPixelStorei'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__setUniforms':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:921: undefined reference to `glBindBufferRange'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg(float, int, long, long)':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:949: undefined reference to `glEnable'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:952: undefined reference to `glColorMask'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:958: undefined reference to `glStencilOpSeparate'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:959: undefined reference to `glStencilOpSeparate'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:960: undefined reference to `glDisable'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:962: undefined reference to `glDrawArrays'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:963: undefined reference to `glEnable'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:966: undefined reference to `glColorMask'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:973: undefined reference to `glStencilOp'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:976: undefined reference to `glDrawArrays'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:981: undefined reference to `glStencilOp'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:982: undefined reference to `glDrawArrays'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:984: undefined reference to `glDisable'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__convexFill':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:996: undefined reference to `glDrawArrays'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1000: undefined reference to `glDrawArrays'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__stroke':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1011: undefined reference to `glEnable'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1016: undefined reference to `glStencilOp'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1020: undefined reference to `glDrawArrays'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1025: undefined reference to `glStencilOp'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1027: undefined reference to `glDrawArrays'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1030: undefined reference to `glColorMask'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1032: undefined reference to `glStencilOp'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1035: undefined reference to `glDrawArrays'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1036: undefined reference to `glColorMask'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1038: undefined reference to `glDisable'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1047: undefined reference to `glDrawArrays'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__triangles':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1056: undefined reference to `glDrawArrays'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__renderFlush':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1075: undefined reference to `glUseProgram'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1077: undefined reference to `glBlendFunc'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1078: undefined reference to `glEnable'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1079: undefined reference to `glCullFace'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1080: undefined reference to `glFrontFace'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1081: undefined reference to `glEnable'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1082: undefined reference to `glDisable'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1083: undefined reference to `glDisable'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1084: undefined reference to `glColorMask'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1085: undefined reference to `glStencilMask'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1086: undefined reference to `glStencilOp'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1087: undefined reference to `glStencilFunc'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1088: undefined reference to `glActiveTexture'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1089: undefined reference to `glBindTexture'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1100: undefined reference to `glBindBuffer'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1101: undefined reference to `glBufferData'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1106: undefined reference to `glBindVertexArray'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1108: undefined reference to `glBindBuffer'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1109: undefined reference to `glBufferData'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1110: undefined reference to `glEnableVertexAttribArray'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1111: undefined reference to `glEnableVertexAttribArray'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1112: undefined reference to `glVertexAttribPointer'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1113: undefined reference to `glVertexAttribPointer'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1116: undefined reference to `glUniform1i'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1117: undefined reference to `glUniform2fv'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1120: undefined reference to `glBindBuffer'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1135: undefined reference to `glDisableVertexAttribArray'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1136: undefined reference to `glDisableVertexAttribArray'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1138: undefined reference to `glBindVertexArray'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1140: undefined reference to `glDisable'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1141: undefined reference to `glBindBuffer'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1142: undefined reference to `glUseProgram'
/home/oipo/Documents/Programming/nanovg-rs/examples/demo/target/debug/deps/libnanovg.rlib(nanovg_shim.o): In function `glnvg__renderDelete':
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1421: undefined reference to `glDeleteBuffers'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1424: undefined reference to `glDeleteVertexArrays'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1427: undefined reference to `glDeleteBuffers'
/home/oipo/Documents/Programming/nanovg-rs/nanovg/src/nanovg_gl.h:1431: undefined reference to `glDeleteTextures'
collect2: error: ld returned 1 exit status

Code to reproduce: https://gist.github.com/anonymous/7a6ac71d99a9c1fe162c20fa1739c94c

Borrowing error due to closure bounds on Context::frame(...)

I ran into a somewhat complex borrow checker issue with this snippet:

https://gist.github.com/ennis/eadedc8120b731aa869dc4a5ab53f36d

At line 79, the compiler emits this error:

error: borrowed data cannot be stored outside of its closure
  --> src\main.rs:78:46
   |
42 |     let cache = ImageCache::new(&context);
   |         ----- ...so that variable is valid at time of its declaration
...
46 |         context.frame(unimplemented!(), unimplemented!(), |frame| {
   |                                                           ------- borrowed data cannot outlive this closure
...
78 |             let mut renderer = Renderer::new(frame, &cache);
   |                                ------------- ^^^^^ cannot be stored outside of its closure
   |                                |
   |                                cannot infer an appropriate lifetime...

With help from the folks over at #rust , I tried to provide an explanation (I put it in the gist).
In short, it seems that bounds on the callback passed to Context::frame() are too restrictive in some cases.

nanovg-rs/src/lib.rs

Lines 110 to 115 in e42928f

pub fn frame<F: FnOnce(Frame)>(
&self,
(width, height): (i32, i32),
device_pixel_ratio: f32,
handler: F,
) {

Changing the function signature to

pub fn frame<'ctx, F: FnOnce(Frame<'ctx>)>(
        &'ctx self,
        (width, height): (i32, i32),
        device_pixel_ratio: f32,
        handler: F,
)

seems to fix the issue for me.

Long Pause While Pressing Keys on Example

I am curious about what may be causing long pauses when pressing keys while the example is running. FPS drops from 700+ to a pause while a key press is processed.

OS: Ubuntu 13.10
Memory: 15.6 GiB
Processor: Intel Core™ i7-2600K CPU @ 3.40GHz × 8
Graphics: GeForce GTX 560/PCIe/SSE2
Arch: x86_64

Current state of the API

I'd like to collect information on how far the API has come along and what is left to be done, so that we know when we can release a new version of the crate to crates.io.

  • What things are left open / missing?
  • Is the API stable enough to allow every valid NanoVG program to be ported?
  • Any known bugs?

cc @KevinKelley, @Zxey

When compiling demo on windows there are undeclared GL_* things

Compiling nanovg-rs by itself works fine, but compiling the demo gets this result:

C:\Users\David\Documents\NanoVGDemo\nanovg-rs\examples\demo>cargo build
   Compiling png-sys v1.6.16 (https://github.com/servo/rust-png#3c310567)
   Compiling nanovg v0.2.0 (https://github.com/KevinKelley/nanovg-rs#cdec9798)
Build failed, waiting for other jobs to finish...
failed to run custom build command for `nanovg v0.2.0 (https://github.com/KevinK
elley/nanovg-rs#cdec9798)`
Process didn't exit successfully: `C:\Users\David\Documents\NanoVGDemo\nanovg-rs
\examples\demo\target\debug\build\nanovg-99622cc133a783b6\build-script-build` (e
xit code: 101)
--- stdout
TARGET = Some("x86_64-pc-windows-gnu")
TARGET = Some("x86_64-pc-windows-gnu")
CARGO_MANIFEST_DIR = Some("C:\\Users\\David\\.cargo\\git\\checkouts\\nanovg-rs-5
276542ec75a7f99\\master")
OUT_DIR = Some("C:\\Users\\David\\Documents\\NanoVGDemo\\nanovg-rs\\examples\\de
mo\\target\\debug\\build\\nanovg-99622cc133a783b6\\out")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
debug 0
TARGET = Some("x86_64-pc-windows-gnu")
HOST = Some("x86_64-pc-windows-gnu")
CC_x86_64-pc-windows-gnu = None
CC_x86_64_pc_windows_gnu = None
HOST_CC = None
CC = None
TARGET = Some("x86_64-pc-windows-gnu")
HOST = Some("x86_64-pc-windows-gnu")
CFLAGS_x86_64-pc-windows-gnu = None
CFLAGS_x86_64_pc_windows_gnu = None
HOST_CFLAGS = None
CFLAGS = None
TARGET = Some("x86_64-pc-windows-gnu")
HOST = Some("x86_64-pc-windows-gnu")
CC_x86_64-pc-windows-gnu = None
CC_x86_64_pc_windows_gnu = None
HOST_CC = None
CC = None
running: "gcc" "-O0" "-c" "-ffunction-sections" "-fdata-sections" "-mwin32" "-m6
4" "-fPIC" "-I" "nanovg/src" "-I" "nanovg/example" "-DNANOVG_GL3_IMPLEMENTATION"
 "C:\Users\David\.cargo\git\checkouts\nanovg-rs-5276542ec75a7f99\master\nanovg/s
rc/nanovg.c" "-o" "C:\Users\David\Documents\NanoVGDemo\nanovg-rs\examples\demo\t
arget\debug\build\nanovg-99622cc133a783b6\out\nanovg/src\nanovg.o"
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
debug 0
TARGET = Some("x86_64-pc-windows-gnu")
HOST = Some("x86_64-pc-windows-gnu")
CC_x86_64-pc-windows-gnu = None
CC_x86_64_pc_windows_gnu = None
HOST_CC = None
CC = None
TARGET = Some("x86_64-pc-windows-gnu")
HOST = Some("x86_64-pc-windows-gnu")
CFLAGS_x86_64-pc-windows-gnu = None
CFLAGS_x86_64_pc_windows_gnu = None
HOST_CFLAGS = None
CFLAGS = None
TARGET = Some("x86_64-pc-windows-gnu")
HOST = Some("x86_64-pc-windows-gnu")
CC_x86_64-pc-windows-gnu = None
CC_x86_64_pc_windows_gnu = None
HOST_CC = None
CC = None
running: "gcc" "-O0" "-c" "-ffunction-sections" "-fdata-sections" "-mwin32" "-m6
4" "-fPIC" "-I" "nanovg/src" "-I" "nanovg/example" "-DNANOVG_GL3_IMPLEMENTATION"
 "C:\Users\David\.cargo\git\checkouts\nanovg-rs-5276542ec75a7f99\master\src/nano
vg_shim.c" "-o" "C:\Users\David\Documents\NanoVGDemo\nanovg-rs\examples\demo\tar
get\debug\build\nanovg-99622cc133a783b6\out\src\nanovg_shim.o"


command did not execute successfully, got: exit code: 1



--- stderr
C:\Users\David\.cargo\git\checkouts\nanovg-rs-5276542ec75a7f99\master\nanovg/src
/nanovg.c:1:0: warning: -fPIC ignored for target (all code is position independe
nt) [enabled by default]
C:\Users\David\.cargo\git\checkouts\nanovg-rs-5276542ec75a7f99\master\src/nanovg
_shim.c:1:0: warning: -fPIC ignored for target (all code is position independent
) [enabled by default]
In file included from C:\Users\David\.cargo\git\checkouts\nanovg-rs-5276542ec75a
7f99\master\src/nanovg_shim.c:13:0:
nanovg/src/nanovg_gl.h: In function 'glnvg__createShader':
nanovg/src/nanovg_gl.h:406:24: error: 'GL_VERTEX_SHADER' undeclared (first use i
n this function)
nanovg/src/nanovg_gl.h:406:24: note: each undeclared identifier is reported only
 once for each function it appears in
nanovg/src/nanovg_gl.h:407:24: error: 'GL_FRAGMENT_SHADER' undeclared (first use
 in this function)
nanovg/src/nanovg_gl.h:414:22: error: 'GL_COMPILE_STATUS' undeclared (first use
in this function)
nanovg/src/nanovg_gl.h:434:23: error: 'GL_LINK_STATUS' undeclared (first use in
this function)
nanovg/src/nanovg_gl.h: In function 'glnvg__renderCreate':
nanovg/src/nanovg_gl.h:667:16: error: 'GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT' undec
lared (first use in this function)
nanovg/src/nanovg_gl.h: In function 'glnvg__renderCreateTexture':
nanovg/src/nanovg_gl.h:743:53: error: 'GL_CLAMP_TO_EDGE' undeclared (first use i
n this function)
nanovg/src/nanovg_gl.h: In function 'glnvg__setUniforms':
nanovg/src/nanovg_gl.h:921:20: error: 'GL_UNIFORM_BUFFER' undeclared (first use
in this function)
nanovg/src/nanovg_gl.h: In function 'glnvg__fill':
nanovg/src/nanovg_gl.h:958:50: error: 'GL_INCR_WRAP' undeclared (first use in th
is function)
nanovg/src/nanovg_gl.h:959:49: error: 'GL_DECR_WRAP' undeclared (first use in th
is function)
nanovg/src/nanovg_gl.h: In function 'glnvg__renderFlush':
nanovg/src/nanovg_gl.h:1088:19: error: 'GL_TEXTURE0' undeclared (first use in th
is function)
nanovg/src/nanovg_gl.h:1100:16: error: 'GL_UNIFORM_BUFFER' undeclared (first use
 in this function)
nanovg/src/nanovg_gl.h:1101:79: error: 'GL_STREAM_DRAW' undeclared (first use in
 this function)
nanovg/src/nanovg_gl.h:1108:16: error: 'GL_ARRAY_BUFFER' undeclared (first use i
n this function)
thread '<main>' panicked at 'explicit panic', C:\Users\David\.cargo\registry\src
\github.com-0a35038f75765ae4\gcc-0.3.8\src\lib.rs:497

More Rust-y wrapping

@KevinKelley, first, thank you for the library! It really is great!

I noticed, however, that the wrapping is pretty low-level. For example, there are public functions which expect raw pointers; also some structures exposed as-is, with libc-typed fields.

Here is the list of things I have found:

  • NVGcolor is exported without any wrapping, and global functions create its instances;
  • NVGcontext is not a proper opaque type; moreover, Ctx contains public pointer to it;
  • NVGpaint, NVGglyphPosition and NVGtextRow are exported directly;
  • fonts and images handles are exposed directly as i32;
  • transformation matrices are represented by raw pointers;
  • a lot of functions accept raw pointers, either for input or output (too many, won't list all of them).

These things need to be fixed to provide safe, libc types-free and raw pointer-less API.

If you don't mind, I'm willing to work at least on some of these items. It shouldn't be too hard, but some new abstractions will be needed. You can track my progress in my fork.

Replace usage of static keyword with const

This RFC was merged in recently, and today when I went to build nanovg I found that it wouldn't build with the following error:

/home/nick/.cargo/git/checkouts/nanovg-rs-84b890ac0c756c09/master/src/lib.rs:69:9: 69:15 error: no rules expected the token `static`
/home/nick/.cargo/git/checkouts/nanovg-rs-84b890ac0c756c09/master/src/lib.rs:69         static LEFT         = ffi::NVG_ALIGN_LEFT,
                                                                                        ^~~~~~
Could not compile `nanovg`.

Judging from the RFC, the solution is to replace this particular usage of static with const.

Provide Eq implementation for Alignment

Hello,
I founds this to be a small problem while digging though some old code of mine. It seems like this used to work, but doesn't anymore.

Sometimes, it might be useful to compare alignments for equality. A bonus would be the ability to compare the horizontal and vertical alignments separately as well.

nanovg-rs does not compile on Windows 7

Hi,
I get the following error messages when I compile nanovg-rs on Windows 7.

Both premake4 and mingw are installed.

cargo build
the [[lib]] section has been deprecated in favor of [lib]
   Compiling nanovg v0.2.0 (file:///D:/users/p/Documents/DocRust/projects/nanovg-rs)
Process didn't exit successfully: `make -f nanovg.mk` (status=2)
--- stdout
mkdir -p "D:\users\p\Documents\DocRust\projects\nanovg-rs\target\native\nanovg-    7364b1892e5d2924"
#cd "D:\users\p\Documents\DocRust\projects\nanovg-rs\target\native\nanovg-7364b1892e5d2924" && ([[ -d "nanovg" ]] && (cd nanovg; git pull) || git cl
one https://github.com/KevinKelley/nanovg)
cd "D:\users\p\Documents\DocRust\projects\nanovg-rs\target\native\nanovg-7364b1892e5d2924" && ([ -d "nanovg" ] && (cd nanovg; git pull) || git clone
 https://github.com/memononen/nanovg)
Already up-to-date.
cd "D:\users\p\Documents\DocRust\projects\nanovg-rs\target\native\nanovg-7364b1892e5d2924/nanovg" && premake4 gmake
Building configurations...
Running action 'gmake'...
Generating build/Makefile...
Generating build/nanovg.make...
Generating build/example_gl2.make...
Generating build/example_gl3.make...
Generating build/example_gl2_msaa.make...
Generating build/example_gl3_msaa.make...
Generating build/example_fbo.make...
Generating build/example_gles2.make...
Generating build/example_gles3.make...
Done.
cd "D:\users\p\Documents\DocRust\projects\nanovg-rs\target\native\nanovg-7364b1892e5d2924/nanovg/build" && CFLAGS='-fPIC' make config=release verbose=1 

==== Building nanovg (release) ====
Creating obj/Release/nanovg
mkdir -p obj/Release/nanovg
nanovg.c
cc -fPIC -MMD -MP -D_CRT_SECURE_NO_WARNINGS -DNDEBUG -I../src  -O2 -Wall -o "obj/Release/nanovg/nanovg.o" -c "../src/nanovg.c"
Linking nanovg
ar -rcs ./libnanovg.a obj/Release/nanovg/nanovg.o
make[1]: Leaving directory `/d/users/p/Documents/DocRust/projects/nanovg-rs/target/native/nanovg-7364b1892e5d2924/nanovg/build'
cp "D:\users\p\Documents\DocRust\projects\nanovg-rs\target\native\nanovg-7364b1892e5d2924/nanovg/build/libnanovg.a" "D:\users\p\Document
s\DocRust\projects\nanovg-rs\target\native\nanovg-7364b1892e5d2924"
mkdir -p "D:\users\p\Documents\DocRust\projects\nanovg-rs\target\native\nanovg-7364b1892e5d2924"
cd "D:\users\p\Documents\DocRust\projects\nanovg-rs\target\native\nanovg-7364b1892e5d2924" && ([ -d "shim" ] || cp -r "/d/users/p/Documents/DocRust/projects/nanovg-rs/shim" .)
cd "D:\users\p\Documents\DocRust\projects\nanovg-rs\target\native\nanovg-7364b1892e5d2924/shim" && premake4 "--nanovg-out=D:\users\p\Documents\DocRust\projects\nanovg-rs\target\native\nanovg-7364b1892e5d2924" "--nanovg-root=D:\users\p\Documents\DocRust\projects\nanovg-rs\target\native\nanovg-7364b1892e5d2924/nanovg" gmake
Building configurations...
Running action 'gmake'...
Generating build/Makefile...
Generating build/nanovg_shim.make...
Done.

cd "D:\users\p\Documents\DocRust\projects\nanovg-rs\target\native\nanovg-7364b1892e5d2924/shim/build" && CFLAGS='-fPIC' make config=release verbose=1

make[1]: Entering directory `/d/users/p/Documents/DocRust/projects/nanovg-rs/target/native/nanovg-7364b1892e5d2924/shim/build'
==== Building nanovg_shim (release) ====
Creating obj/Release
mkdir -p obj/Release
shim.c
cc -fPIC -MMD -MP -DNDEBUG -I../src -ID:/users/p/Documents/DocRust/projects/nanovg-rs/target/native/nanovg-7364b1892e5d2924/nanovg/src -ID:/users/p/Documents/DocRust/projects/nanovg-rs/target/native/nanovg-7364b1892e5d2924/nanovg/example  -O2 -Wall -o "obj/Release/shim.o" -c "../src/shim.c"
make[1]: Leaving directory `/d/users/p/Documents/DocRust/projects/nanovg-rs/target/native/nanovg-7364b1892e5d2924/shim/build'

--- stderr
../src/nanovg.c:1:0: warning: -fPIC ignored for target (all code is position independent) [enabled by default]
 //
 ^
../src/shim.c:1:0: warning: -fPIC ignored for target (all code is position independent) [enabled by default]
 #define NANOVG_GL3_IMPLEMENTATION
 ^
../src/shim.c:14:24: fatal error: GLFW/glfw3.h: No such file or directory
 #include <GLFW/glfw3.h>
                    ^
compilation terminated.
make[2]: *** [obj/Release/shim.o] Error 1
make[1]: *** [nanovg_shim] Error 2
make: *** [D:\users\p\Documents\DocRust\projects\nanovg-rs\target\native\nanovg-7364b1892e5d2924/libnanovg_shim.a] Error 2

Support for multiple OpenGL API simultaneously

As I see, currently it is not possible to select appropriate GL renderer at runtime (between GL2/GL3/GLES2/GLES3). I develop app which tries to get OpenGL context in different ways. So I can get supported GL API and version only at runtime.
I would like to have possibility select rendering API at runtime say when multiple features was selected simultaneously at compilation time.

`text_break_lines` gives different results based on most recend call to `text`

This is unexpected behavior and should at least be documented, but preferably changed.
I assume, it just has been forgotten to add, since almost all other functions take a font and some text options, which are passed to private function text_prepare. So just adding a font and text options as parameters here as well should solve this issue.

100% crash with release builds on 64-bit Windows (MSVC)

Binaries (like our demos) always crash a 100% of the time when building for release, targeting 64-bit Windows (MSVC). Debug builds work for some reason.

Error message dump:

C:\Users\danie_000\Desktop\nanovg-rs>cargo run --release --example demo-glutin --features=gl3
    Finished release [optimized + debuginfo] target(s) in 0.0 secs
     Running `target\release\examples\demo-glutin.exe`
thread 'main' panicked at 'gl function was not loaded', C:\Users\danie_000\Desktop\nanovg-rs\target\release\build\gl-74ca7608d1db5a39\out/bindings.rs:20624:13
stack backtrace:
   0: std::sys::windows::backtrace::unwind_backtrace
             at C:\projects\rust\src\libstd\sys\windows\backtrace\mod.rs:65
   1: std::sys_common::backtrace::_print
             at C:\projects\rust\src\libstd\sys_common\backtrace.rs:71
   2: std::sys_common::backtrace::print
             at C:\projects\rust\src\libstd\sys_common\backtrace.rs:59
   3: std::panicking::default_hook::{{closure}}
             at C:\projects\rust\src\libstd\panicking.rs:207
   4: std::panicking::default_hook
             at C:\projects\rust\src\libstd\panicking.rs:223
   5: std::panicking::rust_panic_with_hook
             at C:\projects\rust\src\libstd\panicking.rs:402
   6: std::panicking::begin_panic<str*>
             at C:\projects\rust\src\libstd\panicking.rs:365
   7: gl::missing_fn_panic
             at .\target\release\build\gl-74ca7608d1db5a39\out\bindings.rs:20624
   8: gl::ClearColor
             at .\target\release\build\gl-74ca7608d1db5a39\out\bindings.rs:1619
   9: demo_glutin::main
             at .\examples\demo-glutin.rs:27
  10: std::rt::lang_start::{{closure}}<()>
             at C:\projects\rust\src\libstd\rt.rs:74
  11: std::rt::lang_start_internal::{{closure}}
             at C:\projects\rust\src\libstd\rt.rs:59
  12: std::panicking::try::do_call<closure,i32>
             at C:\projects\rust\src\libstd\panicking.rs:306
  13: panic_unwind::__rust_maybe_catch_panic
             at C:\projects\rust\src\libpanic_unwind\lib.rs:102
  14: std::panicking::try
             at C:\projects\rust\src\libstd\panicking.rs:285
  15: std::panic::catch_unwind
             at C:\projects\rust\src\libstd\panic.rs:361
  16: std::rt::lang_start_internal
             at C:\projects\rust\src\libstd\rt.rs:58
  17: main
  18: invoke_main
             at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  19: __scrt_common_main_seh
             at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283
  20: BaseThreadInitThunk
  21: RtlUserThreadStart
error: process didn't exit successfully: `target\release\examples\demo-glutin.exe` (exit code: 101)

Avoid linking libGL at compile time

I see that OpenGL library linking with nanovg-sys at compile time:

if target.contains("linux") {
println!("cargo:rustc-link-lib=GL");
} else if target.contains("darwin") {
println!("cargo:rustc-link-lib=framework=OpenGL");

Why we need to do it so?
I think we may and should avoid to do it because usually OpenGL API procedures initializes dynamically at runtime by requesting addresses to it after initializing context.

Unable to compile in Rust 1.1

After running cargo build I get this output:

C:\Users\David\Documents\NanoVGDemo\nanovg-rs>cargo build
   Compiling nanovg v0.2.0 (file:///C:/Users/David/Documents/NanoVGDemo/nanovg-rs)
src\lib.rs:116:15: 116:17 error: expected identifier, found keyword `fn`
src\lib.rs:116     pub const fn rgb_f(r: f32, g: f32, b: f32) -> Color {
                             ^~
src\lib.rs:116:18: 116:23 error: expected `:`, found `rgb_f`
src\lib.rs:116     pub const fn rgb_f(r: f32, g: f32, b: f32) -> Color {
                                ^~~~~
Could not compile `nanovg`.

This seemed a simple fix so I removed the const keywords and then was told that optin features builtin_traits and slice patters may not be used in the release channel.

I don't know enough about Rust to go about fixing the code to work in 1.1. Any help would be appreciated

Cannot include as dependency in Rust 1.1

In Cargo.toml:

[dependencies.nanovg]
version = "*"
features = ["gl3"]

The error:

Package `nanovg v0.2.0` does not have these features: `gl3`

Rust version:

rustc --version
rustc 1.1.0 (35ceea399 2015-06-19)

WebGL support

Hi! It might be a long shot, but have you thought at all about what it would take to get this crate running within a WASM context, targeting WebGL? I know NanoVG itself has received minor attention on this question. I've been working a bit on recoding NanoVG in Rust with a particular focus on targeting WebGL, but I think this is silly given how much is already done here.

Personally I'm a bit lost on how emscripten re-targets GLES2 code to WebGL (see the linked issue), so I'm not sure yet what would be the best way to attack this problem... Just wanted to see if anyone has had any thoughts!

Update gcc crate

gcc crate got renamed to cc and have 1.0 stable release, we should update to that instead of using old version.

Subpath usability

While porting #44, I encountered few usability problems concerning drawing paths and their subpaths:
The first problem is when i only wanted to draw line, I needed to write:

frame.path(|path| {
    path.sub_path((move_x, move_y), |sub_path| {
        sub_path.line_to((to_x, to_y));
    });

    path.stroke(...);
}, Default::default());

This seems quite cumbersome, but the first thing I though would work is just to call move_to and line_to on the path itself.

The second, more concerning problem is regarding creating holes in paths.
For example, I want to draw rectangle and then cut a hole in that rectangle using another rectangle, like this:
cutout
(the black rectangle is the first rectangle, the second one is rounded and cuts hole into the first one)
The way you would do it in c version of nanovg is as follows (parameteres excluded for clarity):

nvgBeginPath(...);
nvgRect(...); // first rect
nvgRoundedRect(...); // second rect to cutout from the first rect (with ofset x and y)
nvgPathWinding(NVG_HOLE);
nvgFillColor(black);
nvgFill(...);

The way you do it now in nanovg-rs:

frame.path(|path| {
    path.rect(...); // first rect
    path.sub_path((0.0, 0.0), |sub_path| {
        path.rounded_rect(...); // second rect to cutout from the first rect (with ofset x and y)
        sub_path.winding(Winding::Solidity(Solidity::Hole));
    });
    path.fill(...);
}, Default::default());

To figure this out, took me embarrasingly long time.
The coordinates when calling sub_path function (0.0, 0.0) are also not needed, which creates more confusion.
So i propose that we remove SubPath struct and move all code back to Path struct.
If it is desired we can keep the sub_path function which would just do move_to and call closure without parameter like this:

frame.path(|path| {
    path.rect(...); // first rect
    path.sub_path((0.0, 0.0), || {
        // these two lines can also be moved outside of this closure if wanted to
        path.rounded_rect(...); // second rect to cutout from the first rect (with ofset x and y)
        path.winding(Winding::Solidity(Solidity::Hole)); // <-- not using sub_path here, only path instance
    });
    path.fill(...);
}, Default::default());

There's the example I created for the screenshot: Link
You need to put it in examples folder and add this to the end of Cargo.toml:

[[example]]
name = "demo-cutout"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.