1
votes

This is how I render my brush in the fragment shader :

gl_FragColor.rgb = Color.rgb;
gl_FragColor.a = Texture.a * Color.a;

With this Blending function on a (0, 0, 0, 0) texture :

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

This is what I see when I draw my texture ADDED to my white background with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) :

My stroke well viewed

But this is what I get in my texture :

Wrong blending in texture

Can someone help me to understand why I got this grayed stroke in my texture ? Because I need to take a screenshot of this texture, and I want to have the same rendering but without white background.

  • [1st picture] When I draw my "view" I have a white background
  • [2nd picture] But I store my stroke in a texture who have a transparent background
1
Is there a question?Columbo
@Columbo : I thought it was clear :) I don't want to store this grayed stroke, but store the stroke I see, "as is".svalsesia

1 Answers

0
votes

You're doing two blending operations, one in your shader, one using the glBlendFunc call. When rendered directly to the screen it doesn't apply the glBlendFunc a second time, however, when rendering to a texture it gets applied when rendering to the texture, and then again when rendering the texture to the screen.

You have two options, 1) don't do blending your shader, 2) use a different blend function (I find glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); to work well). I find option 2 to work the best for me, handling OpenGL blend functions is notoriously annoying.