memononen / nanovg

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

Implement Glow fx #227

Open TronicLabs opened 9 years ago

TronicLabs commented 9 years ago

Which method recommended to adopt a glow fx?

memononen commented 9 years ago

For simple things (rect, rounded rect, circle) you can use gradients, for more complicated things, you can render to texture and spply blur/glow using a shader.

--mikko

Sent from my iPhone

On 19.6.2015, at 3.09, Marco notifications@github.com wrote:

Which method recommended to adopt a glow fx?

— Reply to this email directly or view it on GitHub.

TronicLabs commented 9 years ago

when and if you have time, I like to have a small example of procedure to render to a texture and apply a shader with NVG. thanks for your attention.

memononen commented 9 years ago

Check out the FBO example, it shows how to render to texture.

Sent from my iPhone

On 19.6.2015, at 21.12, Marco notifications@github.com wrote:

when and if you have time, I like to have a small example of procedure to render to a texture and apply a shader with NVG. thanks for your attention.

— Reply to this email directly or view it on GitHub.

dougbinks commented 9 years ago

Geeks3D has some GLSL post process effect shader examples you can use once you're rendered to texture. Normally a Gaussian blur is a good effect to use.

olliwang commented 9 years ago

I've created a project that can easily apply OpenGL filter to an existing texture. Currently there is only one Gaussian blur filter but may generate the effect you want. Check this out: https://github.com/ollix/glfc

A simple example

// Creates and renders to a FBO.
NVGLUframebuffer* fbo = nvgluCreateFramebuffer(vg, width * scale, height * scale);
glViewport(0, 0, width * scale, height * scale);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
nvgluBindFramebuffer(fbo);
nvgBeginFrame(vg, width, height, scale);
// Renders something.
nvgEndFrame(vg);

// Applies the Gaussian blur filter.
glfc::GaussianBlurFilter filter;
filter.Render(fbo->texture, width, height, scale);

nvgluBindFramebuffer(NULL);
TronicLabs commented 9 years ago

olliwang thanks for the example...