Making surface opaque?

kamiyasi

Member
Hi. I'm using this surface here:
Code:
////////surf2
surface_set_target(surf2);

draw_set_blend_mode_ext(bm_zero,bm_inv_src_color);  ///cutout
draw_surface(surf1,0,0);
draw_set_blend_mode(bm_normal);

surface_reset_target();
to make a transparent cutout of suf1, allowing the background behind it to show through. The two surfaces are combined here...
Code:
//////surfcomp
surface_set_target(surfcomp);
draw_clear_alpha(c_red, 1);

draw_background_tiled(bck_blood,0,0);

draw_surface(surf2,0,0);

surface_reset_target();
Here's the issue: in parts of the surface, surfcomp, that don't have an alpha of either 0 or 1, the background of the game shows through, meaning that the surface itself is not opaque.
upload_2016-12-27_12-49-43.png
Here you can see, the edges of the blood trail that look purplish are transparent allowing the blue background to show through. How can I make the surface opaque to fix this problem? Thank you.
 

sp202

Member
I can't see any of the posted code being related to opacity, are you handling opacity when actually drawing the surface?
 

kamiyasi

Member
I can't see any of the posted code being related to opacity, are you handling opacity when actually drawing the surface?
I'm not changing the opacity by using draw_set_alpha at all but I am drawing particles with opacity to the masking surface.
 
To fix that you need to understand that whenever you draw something the source and the target always need to be blended. Especially when drawing to a surface you usually notice that the alpha values blend as well. So the semi transparent particles actually reduce the alpha value of your surface. I think you really should learn more about how surfaces and especially drawing on a surface works. Fortunately there's help here:

Here's a tech blog by Mark Alexander on blend modes:
http://www.yoyogames.com/blog/56

And here's an old post of mine on blend modes, masking and premultiplying alpha.
http://gmc.yoyogames.com/index.php?showtopic=636009&hl=

I know it's not an easy read - I need to go through that stuff once in a while as well, but I think you need to work through it to understand why that happens and how you can fix it - sorry.
 

Hyomoto

Member
@Mike is great at this stuff I'm inclined to assume it would work, but at a glance I don't see how it could, that would turn off ALL alpha blending. @The Reverend is right. The base issue, as far as I can tell is it also blends the alpha values, so 1 - 1 = 0. This is what he was talking about in that you need to use a different blend mode to prevent this.

That said, if turning of alpha blending works, let us know. It doesn't seem it should so I'm sure a lot of people could benefit from this knowledge.
 

kamiyasi

Member
@Mike is great at this stuff I'm inclined to assume it would work, but at a glance I don't see how it could, that would turn off ALL alpha blending. @The Reverend is right. The base issue, as far as I can tell is it also blends the alpha values, so 1 - 1 = 0. This is what he was talking about in that you need to use a different blend mode to prevent this.

That said, if turning of alpha blending works, let us know. It doesn't seem it should so I'm sure a lot of people could benefit from this knowledge.
Turning off alpha blending did work for me. I got it to work by not using it before drawing to my surfaces, but instead by using it before drawing the mesh that my surface is mapped to.
draw_enable_alphablend(false);
///draw battle platform
d3d_transform_set_identity();
d3d_transform_add_translation(0,0,0);
d3d_transform_add_rotation_x(90);
d3d_transform_add_rotation_y(180);
d3d_transform_add_rotation_z(180);
d3d_transform_add_translation(room_width/2,room_height/2,0);
d3d_model_draw(global.objdonut,0,0,0,surface_get_texture(obj_control.surfcomp));
d3d_transform_set_identity();
draw_enable_alphablend(true);
 

Attachments

Top