[Cuis-dev] Stuck with OpenGL + NanoVG

Mariano Montone marianomontone at gmail.com
Tue Sep 1 13:05:24 PDT 2020


Hello.

I'm trying to draw using NanoVG and OpenGL.

But I get no output from NanoVG (OpenGL works just fine). I thought
perhaps somebody with experience with OpenGL or NanoVG could take a
look, or just mention a couple of ideas for me. I don't have much
experience with OpenGL, so it is difficult for me to debug.

This is what I've done. I've compiled NanoVG as a shared library and
then I rewrote the OpenGL example to use it via a NanoVG FFI.

This is how I'm trying it:

NanoVG>>exampleGL2

	"NanoVG exampleGL2"

	"A very simple NanoVG example"

	| ogl  bounds  nvg |
	
	bounds := 0 at 0 extent: 400 at 400.
	ogl := OpenGL newIn: bounds.
	ogl ifNil:[^self error: 'Unable to create renderer'].
	nvg _ NanoVG createGL2: 1 + 2 + 4.
		
	[[Sensor isAnyButtonPressed] whileFalse:[
		"start counting at second frame since first frame is penalized
		by the upload of the bitmap font outside of ogl."
				
		ogl glClearColor: 1.0 with: 1.0 with: 1.0 with: 1.0.
		ogl glClear: ((GLColorBufferBit bitOr: GLDepthBufferBit) bitOr:
GLStencilBufferBit).
		
		ogl beginFrame.
		
		NanoVG BeginFrame: nvg windowWidth: 400.0  windowHeight: 400.0
devicePixelRatio: 1.0 .
		
		NanoVG BeginPath: nvg;
		             MoveTo: nvg x: 0  y: 0;
		             LineTo: nvg x: 100 y: 100;
		             StrokeWidth: nvg size: 5.0;
		             StrokeColor: nvg color: (NanoVG RGBf:1.0 g: 0.0 b: 0.0);
		             Stroke: nvg.
		
		NanoVG BeginPath: nvg;
				Rect: nvg x: 0  y: 0  w: 100  h: 100 ;
				FillColor:  nvg color: (NanoVG RGBf:1.0 g: 0.0 b: 0.0);
				Fill: nvg.
	
		NanoVG EndFrame: nvg.
		ogl endFrame.
		ogl swapBuffers.
		"(Delay forSeconds: 1) wait."
	]] ensure:[NanoVG deleteGL2: nvg. ogl destroy].


I wrap NanoVG calls between #BeginFrame and #EndFrame, but nothing gets
drawn. I have no errors if I use OpenGL version 2 example; but I get a
segmentation fault error if I try NanoVG over OpenGL v3:

Shader shader/vert error:
0:1(10): error: GLSL 1.50 is not supported. Supported versions are:
1.10, 1.20, 1.30, 1.00 ES, 3.00 ES, and 3.10 ES

That's odd because NanoVG example_gl3 compile and works fine.

My reasoning is that NanoVG is triggering normal OpenGL commands, and so
it should be possible to make this work. At the same time, not sure
about how the OpenGL contexts are handled (there's Balloon3Dplugin in
the middle of all this).

My end goal would be to implement an OpenGL+NanoVG canvas and render the
whole world, as I did with Cairo.

Here's NanoVG FFI package:
https://bitbucket.org/mmontone/mold/src/master/NanoVG.pck.st
And how I'm compiling NanoVG as shared library:
https://bitbucket.org/mmontone/mold/src/master/nanovg/src/

I don't really expect a response to this email, but if anyone has any
ideas that could help me get something drawn with NanoVG, please let me
know!

Thanks!

Mariano


More information about the Cuis-dev mailing list