memononen / nanovg

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
zlib License
5.12k stars 767 forks source link

NVG_ANTIALIAS doesn't smooth edges #449

Open sasmaster opened 6 years ago

sasmaster commented 6 years ago

Hi, I am rendering a rectangular shape with one side as a diagonal into offscreen frame buffer.Now,from what I understood,I should be able to use NVG_ANTIALIAS flag to antialias edges instead of MSAA. But I can't see any antialiasing. Am I missing something regarding this flag.Here is related texture. test.zip Now,this is single 8bit channel texture attachment, with GL format GL_RED and internal format GL_R8. Thanks.

sasmaster commented 6 years ago

Hi. Have you looked in to this issue?

memononen commented 6 years ago

I have not tested rendering to single channel render target.

I remember that at some point in past alpha blending was supported only for RGB and RGBA targets. Have you tested rendering a simple alpha blended triangle to see what happens?

sasmaster commented 6 years ago

But my issue is not with alpha blending, Are you using some sort of sdf algorithm to smooth curved edges?.In my case I am getting aliasing on geometry edge (straight line) of the polygon. That's why I am asking if I must enable msaa by default. But I will try rendering into RGB attachment. I just wanted save some bandwidth.

On Jan 26, 2018 19:47, "Mikko Mononen" notifications@github.com wrote:

I have not tested rendering to single channel render target.

I remember that at some point in past alpha blending was supported only for RGB and RGBA targets. Have you tested rendering a simple alpha blended triangle to see what happens?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/memononen/nanovg/issues/449#issuecomment-360854797, or mute the thread https://github.com/notifications/unsubscribe-auth/AAawgIuqTFBOTsyzxCj2uXWzUasIwBY4ks5tOg-6gaJpZM4Ri2Qz .

memononen commented 6 years ago

The AA is done by drawing 1px wide strip around the polygon, where alpha=0 outside. So if you are not using MSAA, NanoVG's AA needs alpha blending.

mean-ui-thread commented 6 years ago

@sasmaster it happened to be once that NVG_ANTIALIAS didn't appear to be working, and it was because I wasn't passing the correct devicePixelRatio value to nvgBeginFrame(), where devicePixelRatio must be the framebuffer width / window width. I don't remember what I did wrong back then, maybe I inverted them, but yeah... passing the wrong devicePixelRatio value made jagged edges for me. Maybe your issue is something else. I suggest compiling and running the example/example_gl3.c as-is to see if antialiasing works or not. I hope it helps. Good luck!