nanovg icon indicating copy to clipboard operation
nanovg copied to clipboard

Drawing and filling irregular geometries

Open isanchoesat opened this issue 6 years ago • 4 comments

Hello,

I am developing a little custom 2D graphic engine and I'm using this API to program some 2D figures. Well, I have the following problem: when drawing simple squares, as you can see with the yellow and blue squares, it's well rendered.

However, when drawing irregular geometries with, for example, lines and bezier curves (blue geometry) or just irregular geometries made with lines (red geometry), it happens that the fill of the figure works bad. I share the following photo to illustrate the explanation:

image

Well, I think I have followed all the steps mentioned in this "readme.md" about the NVG creation with Stencil Strokes, about clearing stencil buffer in "glClear" function... And I don't know what is wrong :S does anyone could help me with this issue?

Thanks in advance (:

isanchoesat avatar Jan 14 '19 18:01 isanchoesat

It's problem with stencil buffer. You will need to initialize opengl with stencil buffer.

memononen avatar Jan 14 '19 20:01 memononen

It's problem with stencil buffer. You will need to initialize opengl with stencil buffer.

Excuse me if I ask but I don't know what do you exactly refer with "initialize OpenGL with Stencil Buffer". Could you give me some additional explanation? I think I'm using it but I'm not sure. I have cleared it to a default zero value and I have enabled the blend test.

I would like to add that I'm rendering the whole geometries of the photo in a secondary framebuffer object.

isanchoesat avatar Jan 14 '19 21:01 isanchoesat

When you create OpenGL context for rendering you can define how many bits are used for color buffer, depth buffer, stencil buffer, etc. The way this is done depends on the framework or library you use to create the opengl context. The example code uses GLFW, which allocates 8 bits for stencil as default.

For example if you were using SDL, this is how you'd set the stencil bits:

SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
...
SDL_GL_CreateContext(...);

memononen avatar Jan 14 '19 21:01 memononen

Well, three weeks later I was finally able to get some free time to fix this bug and I have to say that it was my fault because I was rendering in a secondary framebuffer object without initializing it correctly... Finnally, it works thanks to the stencil :D thank you @memononen !!

captura

isanchoesat avatar Feb 03 '19 17:02 isanchoesat