Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drawing thick lines without setting alpha blending (i.e SDL_BLENDMODE_BLEND) #43

Open
galorithm opened this issue Dec 24, 2024 · 2 comments

Comments

@galorithm
Copy link

Hi,

I wanted to draw thick lines without any blending during rendering (SDL_BLENDMODE_NONE), with the intent that if my source alpha channel value is 0, then destination's alpha value should also get set to 0.

But, the current code for thickLineRGBA (

if (a != 255) result |= SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
) would set alpha blending on before rendering, leaving destination alpha value unchanged if the source's alpha channel value is 0.

Should I add a function that allows to draw thick lines without setting the alpha blending mode before drawing ?

Thank you.

@rtrussell
Copy link
Owner

with the intent that if my source alpha channel value is 0, then destination's alpha value should also get set to 0.

That's an unusual requirement. If you are not using alpha-blending, it should not matter what the destination alpha is set to (indeed with the default render target there probably is no alpha channel!), but if you are using alpha-blending you would not normally want the destination alpha to be set to zero, since your line will then not draw if blitted to another texture.

But, the current code for thickLineRGBA (

That is not one of my additions, it's one of the original functions in Ferzkopp's SDL2_gfxPrimitives.c although it has been modified since I forked it. So perhaps you should raise the issue with the author.

@galorithm
Copy link
Author

galorithm commented Dec 25, 2024

Thank you for the reply !

My requirement is that I want to set the alpha value of the pixels along the thick line as 0 (fully transparent) even if the pixels originally had a different alpha value (say some opaque color over them).

The way I am using this is by rendering a foreground texture with transparent pixels over a background texture (with SDL_TextureBlendMode() set to SDL_BLENDMODE_BLEND for the foreground texture so that wherever transparent pixels are drawn in the foreground texture, the background texture's colors should get visible).

(More specifically, I first renderCopy the background texture on the window, then renderCopy the foreground texture on the window. The background texture remains unchanged, the foreground texture is where I want to do the thick line drawing part)

Drawing a thick line over the foreground texture which has the effect of setting alpha channel value to 0 for those pixels would make the background texture pixels underneath those foreground texture pixels visible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants