NanoVGo NanoVGNanoVGo is pure golang implementation of NanoVG. The same author maintains the NanoGUI.go project mentioned above.

Related tags

Images tools nanovgo


Pure golang implementation of NanoVG. NanoVG is a vector graphics engine inspired by HTML5 Canvas API.


API Reference

See GoDoc

Porting Memo

  • Root folder .go files

    Ported from NanoVG.

  • fontstashmini/fontstash_mini.go

    Ported from fontstash. It includes only needed functions.

  • fontstashmini/truetype

    Copy from (Public Domain)


zlib license

Original (NanoVG) Author



  • Moriyoshi Koizumi
  • @hnakamur2
  • @mattn_jp
  • @hagat
  • @h_doxas
  • FSX
  • Creating multiple windows with separate contexts

    Creating multiple windows with separate contexts


    Thanks for this great library!

    I'd like to have two different windows with different stuff drawn on them. I'm struggling with this. Is there a small example of how to handle multiple windows/multiple contexts?

    Here's what I'm trying to do looks like in pure OpenGL:

    foreach w in windows:
        foreach ctx in w.contexts:

    It's not clear how to define multiple contexts. I assume NewContext() uses current current context, so I tried

    w1, _ := glfw.CreateWindow(...)
    ctx1, _ := nanovgo.NewContext()
    w2, _ := glfw.CreateWindow(...)
    ctx2, _ := nanovgo.NewContext()
    for {
            for i := 0; i < len(windows); i++ {
                    gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT
                    gl.ClearColor(255, 255, 255, 255)
                    drawText(ctx[i], "HELLO")

    But it didn't work. The text is drawn only in the first window.


    opened by medvednikov 1
  • Fix memory leak in (*nvgPathCache).allocVertexes()

    Fix memory leak in (*nvgPathCache).allocVertexes()

    Hi, this is a really awesome project. Thanks for porting nanovg to Go. :)

    When I tried the sample code my laptop run out of memory and started swapping. I found the leak with the profiler and ported the code from memononen/nanovg/nanovg.c:1111 (nvg__allocTempVerts).

    Memory usage is stable and the sample code still works.

    opened by FSX 1
  • truetype.go: fix index out of range panic

    truetype.go: fix index out of range panic

    I was getting the following panic when certain corrupt characters were rendered:

    panic: runtime error: index out of range
    goroutine 1 [running, locked to thread]:*FontInfo).GetGlyphHMetrics(0xc420052150, 0x10194, 0xf, 0x200)
    	/Users/alex/src/ +0x12d*Font).buildGlyphBitmap(0xc42006a240, 0x10194, 0x3c5a5f59, 0x4346580, 0x100, 0x4b, 0xd, 0xf, 0x200)
    	/Users/alex/src/ +0x3c*FontStash).getGlyph(0xc4200f00e0, 0xc42006a240, 0xfffd, 0x168, 0x0, 0x4526e9a545936000)
    	/Users/alex/src/ +0x1b5*TextIterator).Next(0xc4203e0700, 0x0, 0x0, 0x0, 0x0, 0xc4203e0701)
    	/Users/alex/src/ +0xd5*Context).TextRune(0xc42000a700, 0x44a640004503e000, 0xc42009ee10, 0x21, 0x24, 0x24)
    	/Users/alex/src/ +0x381*Context).Text(0xc42000a700, 0x44a640004503e000, 0xc4200c60a2, 0x32, 0x459c6000)
    	/Users/alex/src/ +0x86

    It turned out the u16() function was not checking array bounds.

    opened by medvednikov 0
  • Opengl 3.2?

    Opengl 3.2?

    Hi, is this library on compatible with opengl 3.2?

    I get this error when trying to set the opengl version other then 2.1

    fatal error: unexpected signal during runtime execution [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x0]

    runtime stack:
    runtime.throw(0x419f76c, 0x2a)
            /usr/local/Cellar/go/1.10.3/libexec/src/runtime/panic.go:616 +0x81
            /usr/local/Cellar/go/1.10.3/libexec/src/runtime/signal_unix.go:372 +0x28e
    goroutine 1 [syscall, locked to thread]:
    runtime.cgocall(0x4110b60, 0xc420055b60, 0x0)
            /usr/local/Cellar/go/1.10.3/libexec/src/runtime/cgocall.go:128 +0x64 fp=0xc420055b30 sp=0xc420055af8 pc=0x4003d24, 0x0)
            _cgo_gotypes.go:11517 +0x49 fp=0xc420055b60 sp=0xc420055b30 pc=0x40c37a9
            /Users/henrique/go/src/ +0x2d fp=0xc420055b80 sp=0xc420055b60 pc=0x40c6b5d
            /Users/henrique/go/src/ +0x22 fp=0xc420055b98 sp=0xc420055b80 pc=0x40c80b2*glShader).createShader(0xc4200a6000, 0x4192b3b, 0x6, 0x41a0182, 0x33, 0x0, 0x0, 0x41a0ba0, 0x199, 0x41a0d39, ...)
            /Users/henrique/go/src/ +0x34 fp=0xc420055c50 sp=0xc420055b98 pc=0x40e0224*glParams).renderCreate(0xc420010350, 0xc4200be000, 0x100)
            /Users/henrique/go/src/ +0x212 fp=0xc420055cd0 sp=0xc420055c50 pc=0x40e2062, 0xc420010350, 0x0, 0xc4200a2000, 0x4627770)
            /Users/henrique/go/src/ +0x3ca fp=0xc420055ee0 sp=0xc420055cd0 pc=0x40e68fa, 0x1f4, 0x4192b2f, 0x6)
            /Users/henrique/go/src/ +0x91 fp=0xc420055f20 sp=0xc420055ee0 pc=0x40e01b1
            /Users/henrique/Documents/Dev/go/kitos_app/kitosMain.go:43 +0x159 fp=0xc420055f88 sp=0xc420055f20 pc=0x40e8769
            /usr/local/Cellar/go/1.10.3/libexec/src/runtime/proc.go:198 +0x212 fp=0xc420055fe0 sp=0xc420055f88 pc=0x402ac72
            /usr/local/Cellar/go/1.10.3/libexec/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc420055fe8 sp=0xc420055fe0 pc=0x4050f81
    exit status 2``` 
    opened by Hperigo 0
  • Help Needed: Android Port

    Help Needed: Android Port

    I am trying to Port Nanovgo example to Android using andrioid-go and EGL

    I modified Nanovgo to support GLES2 library from , see modified version here nanovgo-gles

    func init() {
    	// Initialise gl bindings using the current context.
    	// err := gl.Init()
    	// if err != nil {
    	// 	log.Fatalln("gl.Init:", err)
    	// }
    func main() {
    	log.Println("NativeActivity has started ^_^")
    	log.Printf("Platform: %s %s", runtime.GOOS, runtime.GOARCH)
    	nativeWindowEvents := make(chan app.NativeWindowEvent)
    	var displayHandle *egl.DisplayHandle
    	ctx, err := nanovgo.NewContext(0)
    	if err != nil {
    	//demoData = LoadDemo(ctx)
    	app.Main(func(a app.NativeActivity) {
    		for {
    			select {
    			case event := <-a.LifecycleEvents():
    				switch event.Kind {
    				case app.OnCreate:
    					log.Println(event.Kind, "handled")
    					log.Println(event.Kind, "event ignored")
    			case event := <-nativeWindowEvents:
    				switch event.Kind {
    				case app.NativeWindowRedrawNeeded:
    					draw(displayHandle, ctx)
    					log.Println(event.Kind, "handled")
    				case app.NativeWindowCreated:
    					expectedSurface := map[int32]int32{
    						egl.SurfaceType: egl.WindowBit,
    						egl.RedSize:     8,
    						egl.GreenSize:   8,
    						egl.BlueSize:    8,
    					if handle, err := egl.NewDisplayHandle(event.Window, expectedSurface); err != nil {
    						log.Fatalln("EGL error:", err)
    					} else {
    						displayHandle = handle
    						log.Printf("EGL display res: %dx%d", handle.Width, handle.Height)
    				case app.NativeWindowDestroyed:
    					log.Println(event.Kind, "event ignored")
    func initGL() {
    	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
    func draw(handle *egl.DisplayHandle, ctx *nanovgo.Context) {
    	//fps := perfgraph.NewPerfGraph("Frame Time", "sans")
    	//t, _ := fps.UpdateGraph()
    	pixelRatio := float32(handle.Width) / float32(handle.Height)
    	gl.Viewport(0, 0, int32(handle.Width), int32(handle.Height))
    	fmt.Println("view port")
    	gl.ClearColor(0, 0, 0, 0)
    	fmt.Println("clear color")
    	ctx.BeginFrame(int32(handle.Width), int32(handle.Height), pixelRatio)
    	fmt.Println("begin frame")
    	demo.RenderDemo(ctx, 0, 0, 300, 600, 0, false, &demo.DemoData{})
    	//fps.RenderGraph(ctx, 5, 5)

    demo.go :

    func RenderDemo(ctx *nanovgo.Context, mx, my, width, height, t float32, blowup bool, data *DemoData) {
    	// Widgets
    	drawWindow(ctx, "Widgets `n Stuff", 50, 50, 300, 400)
    	var x float32 = 60.0
    	var y float32 = 95.0
    	fmt.Println("Draw Window")
    	drawSearchBox(ctx, "Search", x, y, 280, 25)
    	y += 40
    	fmt.Println("Draw Search")
    	drawDropDown(ctx, "Effects", x, y, 280, 28)
    	//popy := y + 14
    	y += 45
    	fmt.Println("Draw DropDown")
    	// Form
    	drawLabel(ctx, "Login", x, y, 280, 20)
    	y += 25
    	fmt.Println("Draw Label")
    	drawEditBox(ctx, "Email", x, y, 280, 28)
    	y += 35
    	fmt.Println("Draw Edit Box")
    	drawEditBox(ctx, "Password", x, y, 280, 28)
    	y += 38
    	fmt.Println("Draw Password")
    	drawCheckBox(ctx, "Remember me", x, y, 140, 28)
    	fmt.Println("Draw  Checkbox")
    	drawButton(ctx, IconLOGIN, "Sign in", x+138, y, 140, 28, nanovgo.RGBA(0, 96, 128, 255))
    	y += 45
    	fmt.Println("Draw Button")
    	// Slider
    	drawLabel(ctx, "Diameter", x, y, 280, 20)
    	y += 25
    	drawEditBoxNum(ctx, "123.00", "px", x+180, y, 100, 28)
    	drawSlider(ctx, 0.4, x, y, 170, 28)
    	y += 55
    	drawButton(ctx, IconTRASH, "Delete", x, y, 160, 28, nanovgo.RGBA(128, 16, 8, 255))
    	drawButton(ctx, 0, "Cancel", x+170, y, 110, 28, nanovgo.RGBA(0, 0, 0, 0))
    	fmt.Println("finished rendering")
    	// Thumbnails box
    	//drawThumbnails(ctx, 365, popy-30, 160, 300, data.Images, t)


    i am getting a blank screen with these errors

    06-08 11:37:00.885 23648-23666/? I/GolangExample: NativeActivity has started ^_^
    06-08 11:37:00.885 23648-23666/? I/GolangExample: Platform: android arm
    06-08 11:37:00.887 23648-23666/? I/GolangExample: Shader shader/vert error:
    06-08 11:37:00.888 23648-23667/? I/GolangExample: onCreate handled
    06-08 11:37:00.890 23648-23666/? I/GolangExample: onStart event ignored
    06-08 11:37:00.893 23648-23666/? I/GolangExample: onResume event ignored
    06-08 11:37:00.894 23648-23648/? D/ActivityThread: EYE startEyeVerifyBroadcast packagename=com.go_android.minimal;
    06-08 11:37:00.903 23648-23648/? V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = null, this = [email protected][],statusBarBackground visible =false,statusColor: 0xff000000->
    06-08 11:37:00.919 23648-23648/? D/WindowClient: Add to mViews: [email protected][NativeActivity], this = [email protected]
    06-08 11:37:00.934 23648-23648/? V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = ViewRoot{5b9d95c com.go_android.minimal/,ident = 0}, this = [email protected][NativeActivity],statusBarBackground visible =false,statusColor: 0xff000000->
    06-08 11:37:00.968 23648-23648/? I/lulingjie--screenshot--observer--: observer is [email protected][NativeActivity]
    06-08 11:37:00.994 23648-23648/? V/InputMethodManager: onWindowFocus: null softInputMode=272 first=true flags=#10100
    06-08 11:37:01.027 23648-23666/? D/Surface: Surface::setBuffersUserDimensions(this=0xe663a000,w=0,h=0)
    06-08 11:37:01.040 23648-23666/? D/Surface: Surface::connect(this=0xe663a000,api=1)
    06-08 11:37:01.042 23648-23666/? W/libEGL: [ANDROID_RECORDABLE] format: 2
    06-08 11:37:01.047 23648-23666/? D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000
    06-08 11:37:01.051 23648-23666/? I/GolangExample: EGL display res: 640x1070
    06-08 11:37:01.052 23648-23664/? I/GolangExample: draw
    06-08 11:37:01.052 23648-23664/? I/GolangExample: view port
    06-08 11:37:01.052 23648-23664/? I/GolangExample: clear color
    06-08 11:37:01.066 23648-23666/? D/GraphicBuffer: register, handle(0xe91913c0) (w:640 h:1070 s:640 f:0x2 u:0x000b00)
    06-08 11:37:01.068 23648-23664/? I/GolangExample: begin frame
    06-08 11:37:01.068 23648-23664/? I/GolangExample: Draw Window
    06-08 11:37:01.068 23648-23664/? I/GolangExample: Draw Search
    06-08 11:37:01.069 23648-23664/? I/GolangExample: Draw DropDown
    06-08 11:37:01.069 23648-23664/? I/GolangExample: Draw Label
    06-08 11:37:01.069 23648-23664/? I/GolangExample: Draw Edit Box
    06-08 11:37:01.069 23648-23664/? I/GolangExample: Draw Password
    06-08 11:37:01.069 23648-23664/? I/GolangExample: Draw  Checkbox
    06-08 11:37:01.070 23648-23664/? I/GolangExample: Draw Button
    06-08 11:37:01.070 23648-23666/? D/MALI: gles_state_set_error_internal:75: [MALI] GLES ctx: 0xa6680008, error code:0x502
    06-08 11:37:01.070 23648-23666/? D/MALI: gles_state_set_error_internal:76: [MALI] GLES error info: OpenGL ES API version mismatch
    opened by darmie 6
  • Added message to stroke failure panic

    Added message to stroke failure panic

    First, thanks so much for all of your hard work on this library, I truly appreciate your careful implementation, design and documentation.

    I've bumped into this panic a few times in the past few weeks and I suspect there are better ways to handle this case, but in the meantime, thought it might be good to at least improve the error message.

    For the record, I haven't taken the time to get a local dev environment up and running, or to run any tests. I mainly thought I'd send this for your consideration before I forget about it.


    opened by lukebayes 0
  • panic: runtime error: index out of range

    panic: runtime error: index out of range

    goroutine 1 [running, locked to thread]:*Atlas).rectFits(0xc82023ccc0, 0x2a, 0x12, 0x12, 0xffffffffffffffff) +0x14d*Atlas).addRect(0xc82023ccc0, 0x12, 0x12, 0x1c4, 0x34, 0x0, 0x0) +0x11c*FontStash).getGlyph(0xc8202387e0, 0xc8201a5d40, 0x2713, 0xc8, 0x0, 0xbf800000) +0x2d7*FontStash).TextBoundsOfRunes(0xc8202387e0, 0x439a80c442380000, 0xc8212e3020, 0x1, 0x2, 0x0, 0x0, 0x0, 0x0) +0x345*FontStash).TextIterForRunes(0xc8202387e0, 0x4397000042380000, 0xc8212e3020, 0x1, 0x2, 0x8) +0x55b*Context).TextRune(0xc8201b4500, 0x4397000042380000, 0xc8212e3020, 0x1, 0x2, 0x2) +0x409*Context).Text(0xc8201b4500, 0x4397000042380000, 0xc82139d3d0, 0x3, 0xc82139d3d0) +0x8e*CheckBox).Draw(0xc8202240d0, 0x5ec1e08, 0xc8202240d0, 0xc8201b4500) +0x9a4*WidgetImplement).Draw(0xc8201be8c0, 0x5ec09c8, 0xc8201be8c0, 0xc8201b4500)
    opened by shibukawa 0
Yoshiki Shibukawa
Yoshiki Shibukawa
Pure golang image resizing

This package is no longer being updated! Please look for alternatives if that bothers you. Resize Image resizing for the Go programming language with

Jan Schlicht 2.9k Aug 6, 2022
Pure Golang Library that allows simple LSB steganography on images

Steganography Lib Steganography is a library written in Pure go to allow simple LSB steganography on images. It is capable of both encoding and decodi

Rafael Passos 150 Jul 26, 2022
A pure Go package for coordinate transformations.

WGS84 A pure Go package for coordinate transformations. go get Usage east, north, h := wgs84.LonLat().To(wgs84.ETRS89UTM(32)).R

Malte Wrogemann 85 Aug 3, 2022
Simple ANSi to PNG converter written in pure Go

AnsiGo Description AnsiGo is a simple ANSi to PNG converter written in pure Go. It converts files containing ANSi sequences (.ANS) into PNG images. Fo

Frederic Cambus 51 May 17, 2022
Image processing algorithms in pure Go

bild A collection of parallel image processing algorithms in pure Go. The aim of this project is simplicity in use and development over absolute high

Anthony N. Simon 3.6k Jul 29, 2022
Rich TIFF/BigTIFF/GeoTIFF decoder/encoder for Go (Pure Go/Zero Dependencies)

Go语言QQ群: 102319854, 1055927514 凹语言(凹读音“Wa”)(The Wa Programming Language): TIFF for Go Features: Support BigTiff Support

chai2010 42 Jun 2, 2022
Image resizing in pure Go and SIMD

rez Package rez provides image resizing in pure Go and SIMD. Download: go get Full documentation at

Benoît Amiaux 207 Jul 12, 2022
A pure Go 3D math library.

MathGL This is a Go matrix and vector math library specialized for Open GL graphics capabilities. This package is made primarily with code generation

OpenGL with Golang 445 Jul 29, 2022
Pure Go encoder/decoder of the QOI image format

QOI - The “Quite OK Image” format for fast, lossless image compression package and small utilities in native Go, quite OK implementation See qoi.h for

Xavier-Frédéric Moulet 56 Jun 3, 2022
gumble is a Mumble client implementation in Go (golang)

gumble gumble is a Mumble client implementation in Go Sub-projects gumble (docs) Client library gumbleopenal (docs) OpenAL audio system for gumble gum

null 150 Jul 28, 2022
Golang implementation of the covid certificate QRCode decoder

Golang implementation of the covid certificates. At the moment it only includes DCC signed data decoding but I've planned to add a lot more of features related to certificates processing.

AlexPresso 5 Sep 22, 2021
NoiseGo - Implementation of Improved Perlin Noise in Golang

NoiseGo Implementation of Improved Perlin Noise in Golang. NoiseGo is written on

Tada Teruki (多田 瑛貴) 1 Jan 24, 2022
The android-go project provides a platform for writing native Android apps in Go programming language.

android-go The android-go project aims to provide a platform (namely an SDK) for writing native Android apps in Go programming language. All things he

Max Kupriianov 972 Aug 2, 2022
Eth2-MEV project with liquid staking (Flashbots-Lido-Nethermind)

Ray Tracing Eth2-MEV project with liquid staking (Flashbots-Lido-Nethermind). Notes | Slides What you need to setup: Eth2 validator with Rayonism enab

Flashbots 51 Jun 14, 2022
Small project to convert images to grayscale

This is a small http server that will read images from a provided path, convert the image to gray, and then serve back the converted image Usage You c

Wolfgang E Sanyer 0 Nov 5, 2021
OpenStreetMap PBF golang parser

pbf OpenStreetMap PBF golang encoder/decoder A golang based OpenStreetMap PBF encoder/decoder with a handy command line utility, pbf. pbf Command Line

Alan D. Cabrera 36 Jul 7, 2022
golang OpenGL helper functions

glh: golang OpenGL helpers This package contains a number of functions useful for applications using OpenGL. Code Reference Features Textures and Text

go-gl legacy 22 Apr 8, 2022
A library for playing with colors in go (golang).

go-colorful A library for playing with colors in Go. Supports Go 1.13 onwards. Why? I love games. I make games. I love detail and I get lost in detail

Lucas Beyer 972 Jul 29, 2022
Rasterx is an SVG 2.0 path compliant rasterizer that can use either the golang vector or a derivative of the freetype anti-aliaser.

rasterx Rasterx is a golang rasterizer that implements path stroking functions capable of SVG 2.0 compliant 'arc' joins and explicit loop closing. Pat

Steven R Wiley 101 Jul 28, 2022