memononen / nanovg

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

Radial Gradient not working #612

Closed MatijaBrown closed 3 years ago

MatijaBrown commented 3 years ago

The title says it all: When running following code, no gradient appears inside the rectangle.


        nvgRect(vg, 900, 100, 300, 500);
        nvgFillPaint(vg, nvgRadialGradient(vg, 1050, 350, 100, 200, nvgRGBAf(1, 0, 0, 1), nvgRGBAf(1, 1, 0, 1)));
        nvgFill(vg);

Is there a reason for this? Am I doing something wrong? Anyway, have a good day.

mulle-kybernetik-tv commented 3 years ago

I tried out your code and got this after I did one weird trick, that I am gonna share with you. Screenshot from 2021-03-17 12-27-44

Trick: I went into the nanovg demo and checked how it's supposed to be done by searching for nvgRadialGradient.

MatijaBrown commented 3 years ago

And how do you suppose I got this nvgRadialGradient(vg, 1050, 350, 100, 200, nvgRGBAf(1, 0, 0, 1), nvgRGBAf(1, 1, 0, 1)) in the first place? I looked at the demo - and other demos I found. To be precise, I used the following example to find the radial gradient code: https://openplanet.nl/tutorials/nanovg-introduction

(scroll down to find it).

mulle-kybernetik-tv commented 3 years ago

I am not clairvoyant and don't know what you did. But if you copy/paste the code from the demo and don't reorder it or leave crucial parts out, it will work.

MatijaBrown commented 3 years ago

Well, that is all the rendering code I'm running per frame apart from calling nvgBeginFrame(vg) and nvgEndFrame(vg) - so it should work. (I have tried moving the rectangle about as well, the paint is definitely not there!)

memononen commented 3 years ago

You're missing nvgBeginPath(vg) before the rect.

On Tue, Mar 16, 2021 at 8:22 PM MatijaBrown @.***> wrote:

The title says it all: When running following code, no gradient appears inside the rectangle.

    nvgRect(vg, 900, 100, 300, 500);
    nvgFillPaint(vg, nvgRadialGradient(vg, 1050, 350, 100, 200, nvgRGBAf(1, 0, 0, 1), nvgRGBAf(1, 1, 0, 1)));
    nvgFill(vg);

Is there a reason for this? Am I doing something wrong? Anyway, have a good day.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/memononen/nanovg/issues/612, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIBXSFAS3KLWFDLZDSH5STTD6OUTANCNFSM4ZJCQE4Q .

MatijaBrown commented 3 years ago

You're missing nvgBeginPath(vg) before the rect. On Tue, Mar 16, 2021 at 8:22 PM MatijaBrown @.***> wrote: The title says it all: When running following code, no gradient appears inside the rectangle. nvgRect(vg, 900, 100, 300, 500); nvgFillPaint(vg, nvgRadialGradient(vg, 1050, 350, 100, 200, nvgRGBAf(1, 0, 0, 1), nvgRGBAf(1, 1, 0, 1))); nvgFill(vg); Is there a reason for this? Am I doing something wrong? Anyway, have a good day. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#612>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIBXSFAS3KLWFDLZDSH5STTD6OUTANCNFSM4ZJCQE4Q .

Well thank you for the answer. I have no idea if I really did forget it, at least I can't remember, but the code is long gone now. Might as well have been the problem though. (but doesn't it usually work for the first render without nvgBeginPath(vg)?, as far as I know EndFrame clears the path cache?)