0
\$\begingroup\$

Hi I'm trying to change from Cairo (2D Vector image library) to NanoVG. I'm using C#, openTK and Nano.VG.NET to make my game.

I'm having issues with alpha? Transparency/Blending is an issue…

Here is an output

Without NanoVG Overlay :

enter image description here

With NanoVG Overlay :

enter image description here

I think it has to do with blending or the nano shader….Not sure. Does anyone knows how to solve this?

My OpenGL Initialization :

GL.DrawBuffer (DrawBufferMode.Back);
GL.Disable (EnableCap.Lighting);
GL.Enable (EnableCap.Texture2D);
GL.Disable (EnableCap.Multisample);
GL.Disable (EnableCap.SampleAlphaToCoverage);
GL.Disable (EnableCap.AlphaTest);
GL.DepthFunc (DepthFunction.Lequal);
GL.Enable (EnableCap.DepthTest);
GL.Disable (EnableCap.ScissorTest);
GL.Enable ( EnableCap.TextureRectangle);

GL.Enable (EnableCap.Blend);
GL.BlendFunc (BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
\$\endgroup\$
1
\$\begingroup\$

Finally found a solution.

For Anyone Having this problem just Add GL.Enable (EnableCap.StencilTest);

internal static void InitializeOpenGL ()
{
GL.DrawBuffer (DrawBufferMode.Back);
GL.Disable (EnableCap.Lighting);
GL.Enable (EnableCap.Texture2D);
GL.Disable (EnableCap.Multisample);
GL.Disable (EnableCap.SampleAlphaToCoverage);
GL.Disable (EnableCap.AlphaTest);
GL.DepthFunc (DepthFunction.Lequal);
GL.Enable (EnableCap.DepthTest);
GL.Enable (EnableCap.StencilTest);
GL.Disable (EnableCap.ScissorTest);
GL.Enable ( EnableCap.TextureRectangle);

GL.Enable (EnableCap.Blend);
GL.BlendFunc (BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
}

And Call InitializeOpenGL before Sprite Rendering (or after drawing GUI).

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.