GMS 2 Surface blend turns overlapped text black

Andymakeer

Member
Hey guys!

So I was playing with surfaces and blend_modes and found out its possible to customize the blending results.
I was trying to draw text to an alpha-cleared surface, but the result was kinda ugly.
Then, after studying a little, i was able to "ignore" the surface color and alpha blend and draw using only the text color and alpha.

But i encountered another problem:
When a text in drawn above another, then the overlapping parts turn all black!

Here is my code:
GML:
surface_set_target(global.surface_hud);

draw_set_font(text_font);
draw_set_color(image_blend);
draw_set_alpha(1);
gpu_set_blendmode_ext_sepalpha(bm_src_color, bm_zero, bm_one, bm_one);
draw_text(x, y, text);
gpu_set_blendmode(bm_normal);

surface_reset_target();
Help 😥
 

rytan451

Member
I don't get what you're trying to do with that blendmode. If I understand correctly, you're adding alpha values (that's causing the overlapping parts turn black), but also setting the color to the font image with a gamma of 2 (darkening the image). This doesn't seem to be intended behavior.

Perhaps try one of these:

GML:
// Normal color blending; alpha is increased
gpu_set_blendmode_ext_sepalpha(bm_src_alpha, bm_inv_src_alpha, bm_inv_dest_alpha, bm_one);

// Just set color and alpha
gpu_set_blendmode_ext(bm_one, bm_zero);

// Just set color; alpha is partially additive.
gpu_set_blendmode_ext_sepalpha(bm_one, bm_zero, bm_inv_dest_alpha, bm_one);
 

Andymakeer

Member
@rytan451
If I understand correctly, you're adding alpha values (that's causing the overlapping parts turn black), but also setting the color to the font image with a gamma of 2 (darkening the image).
This granted me an insight, "if the surface clear alpha color affects the drawing result, so if i change it to black, which is (0,0,0), then it will not."
Idk if my logic is correct, but i've tried this:

Using my previous blend:
gpu_set_blendmode_ext_sepalpha(bm_src_color, bm_zero, bm_one, bm_one);
myblend.png

Now using your first option:
gpu_set_blendmode_ext_sepalpha(bm_src_alpha, bm_inv_src_alpha, bm_inv_dest_alpha, bm_one);
myblend.png

And this is exactly what i needed!
Thanks very much! 😁😁😁
 
Top