• Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!

Legacy GM Surface drawing creates a white outline caused by the sprite's alpha

PWL

Member
I am using a surface to draw this cat, so that I can draw the pattern inside him as you can see in the picture. If you watch closely, there is a white outline around the pattern and the character itself (not too visible in this screenshot, unfortunately). I assume that is because of the alpha in the sprite (see screenshot 2).

Is there some settings that I can change to make the white outline go away?

Thank you!



Pattern sprite zoomed in:


Code for drawing the body with the surface:
Code:
surface_set_target(bodySurface);
draw_set_blend_mode(bm_normal);
draw_clear_alpha(c_white, 0);
draw_sprite_ext(sprite_index, image_index, abs(sprite_xoffset), abs(sprite_yoffset), 1, 1, 0, image_blend, 1);
draw_set_blend_mode_ext(bm_dest_colour, bm_inv_src_alpha);
draw_sprite_ext(spr_cat_body_pattern, patternId, abs(sprite_xoffset), abs(sprite_yoffset), 1, 1, 0, image_blend, 1);
draw_set_blend_mode(bm_normal);
draw_sprite_ext(spr_cat_head, 0, abs(sprite_xoffset), abs(sprite_yoffset), 1, 1, 0, image_blend, 1);
surface_reset_target();

draw_surface_ext(bodySurface, x-sprite_xoffset, y-sprite_yoffset - jumpOffset, image_xscale, image_yscale, image_angle, c_white, image_alpha);
EDIT: Zoomed screenshot.
 

hippyman

Member
I don't see any white lines in either picture.

If it's just the AA you don't like you can turn that off in the global game settings > windows > graphics > interpolate color between pixels (or something like that)
 

PWL

Member
Yes, I am talking about the Anti Aliasing, however that is already on the sprite itself, and turning off the interpolate option doesn't help, unfortunately. Which is what messes up the colors. Forgive me for writing "white", but I mean the lighter parts of it.
I want the pixels below to blend between the color of the pattern (the dark swirly part) and the color of the body base sprite (the lighter part). Instead they are now brighter than everything, which I don't understand why they would be.
 

Phil Strahl

Member
I have had some alpha issues with surfaces before when saving the application surface as screenshot. What did it for me as to switch the blending mode to
Code:
draw_set_blend_mode_ext(bm_one,bm_src_alpha_sat)
before drawing the surface. Maybe this helps?
 
It looks like a sharpening issue to me. Did you sharpen the pattern image? Then again it could be the red transparency you have over the pattern. Do you need that red transparency? BTW I tried for about 30 minutes to replicate your problem without success. Perhaps if you uploaded the actual images you are using we could get to the bottom of things.
 

PWL

Member
I have had some alpha issues with surfaces before when saving the application surface as screenshot. What did it for me as to switch the blending mode to
Code:
draw_set_blend_mode_ext(bm_one,bm_src_alpha_sat)
before drawing the surface. Maybe this helps?
No, sorry. That ruins the drawing. With this I get a white square around the sprite and the pattern is no longer inside of the body.
It looks like a sharpening issue to me. Did you sharpen the pattern image? Then again it could be the red transparency you have over the pattern. Do you need that red transparency? BTW I tried for about 30 minutes to replicate your problem without success. Perhaps if you uploaded the actual images you are using we could get to the bottom of things.
Here is the actual images. I do not sharpen the image by any kind. It is a simple sprite with alpha and is drawn with the code provided. And there is no red transparency? If you're talking about the pink, then that is just the background colors I have set for transparency in game maker.
 

PWL

Member
It happens with any image blend really. Aqua, white, orange, whatever it is. And "pre-multiply alpha" doesn't really mean anything to me. Care to explain? :)
 

RangerX

Member
When you open the sprite in GameMaker sprite editor is it looking like that?
If yes, in the sprite that is that way and you need to simply change the colors in it that you don't like.
 

PWL

Member
No, it does not look that way. I have even posted the parts I use for drawin it.

Maybe this explains it better.
Drawn with the surface code above. See how that is a white outline around the character?

Drawn with plain draw_sprite_ext(). No white outline! (However, the pattern breaks here. That's why I need the surface.)


So it definitely is my surface drawing causing this. And since I haven't been using surfaces that long, I'm basically just scratching my head.

Again, thanks for your time.
 

Yal

GMC Memer
GMC Elder
On close inspection of the side-by-side comparison, the white outlines are pixels that are semitransparent in the actual sprite... that gave me an idea. Try doing a
Code:
draw_clear_alpha(c_black,0)
call right after setting the drawing target to the surface, perhaps? If the white outlines is due to the surface's background color actually being white, this should solve the issue.
 

PWL

Member
Thank you!
draw_set_blend_mode_ext(bm_one, bm_inv_src_alpha) did the trick with the head and the body's outline (in my last screenshots). In addition to this I moves the image_blend part to the surface itself. It seems like the blended pattern drawn over a blended body doesn't work that well.

It now looks like this:
upload_2016-7-9_18-14-24.png
No more white outline, and no bright color outline on the pattern!

This is the code I ended up with:
Code:
surface_set_target(bodySurface);
draw_set_blend_mode(bm_normal);
draw_clear_alpha(c_black, 0);
draw_set_blend_mode_ext(bm_one, bm_inv_src_alpha);
draw_sprite_ext(sprite_index, image_index, abs(sprite_xoffset), abs(sprite_yoffset), 1, 1, 0, c_white, 1);
draw_set_blend_mode_ext(bm_dest_colour, bm_inv_src_alpha);
draw_sprite_ext(spr_cat_body_pattern, patternId, abs(sprite_xoffset), abs(sprite_yoffset), 1, 1, 0, c_white, 1);
draw_set_blend_mode_ext(bm_one, bm_inv_src_alpha);
draw_sprite_ext(spr_cat_head, 0, abs(sprite_xoffset), abs(sprite_yoffset), 1, 1, 0, c_white, 1);
surface_reset_target();

draw_set_blend_mode_ext(bm_one, bm_inv_src_alpha);
draw_surface_ext(bodySurface, x-sprite_xoffset, y-sprite_yoffset - jumpOffset, image_xscale, image_yscale, image_angle, image_blend, image_alpha);
draw_set_blend_mode(bm_normal);
Thanks everyone for your help! :)
 

DukeSoft

Member
A little different from the other solutions... this is what worked for me.

draw_set_blend_mode_ext(bm_one, bm_inv_src_alpha)

I think I also used draw_clear_alpha(c_black,0) on the surface first too.

Details from my issue: http://gmc.yoyogames.com/index.php?showtopic=682514&hl=+surface++alpha++problem
Thank you - this solved some issue for me too. I'm trying to draw a piece of a texture over another texture ( https://forum.yoyogames.com/index.php?threads/drawing-alpha-blended-sprites-on-surface.11442/#post-74340 ).

Also, can I say, i used your game as an example of what wonderful things can be made with GM? I've shown it a couple of times a few months ago. Love your work!
 

DanMunchie

Member
Sorry to resurrect an old thread - but @PWL - what result do you get if you change the draw_clear_alpha(c_black, 0); to c_white (or any colour other than c_black)?
I am curious if this solution only works because your sprite has a black outline.
 
S

Sabo

Guest
Thank you - this solved some issue for me too. I'm trying to draw a piece of a texture over another texture ( https://forum.yoyogames.com/index.php?threads/drawing-alpha-blended-sprites-on-surface.11442/#post-74340 ).

Also, can I say, i used your game as an example of what wonderful things can be made with GM? I've shown it a couple of times a few months ago. Love your work!
A little different from the other solutions... this is what worked for me.

draw_set_blend_mode_ext(bm_one, bm_inv_src_alpha)

I think I also used draw_clear_alpha(c_black,0) on the surface first too.

Details from my issue: http://gmc.yoyogames.com/index.php?showtopic=682514&hl=+surface++alpha++problem
Thanks so much you helped me solve my issue :D
 
Top