GM:S 1.4 Surface drawing creates a white outline caused by the sprite's alpha

Discussion in 'Programming' started by PWL, Jul 8, 2016.

  1. PWL

    PWL Member

    Joined:
    Jun 21, 2016
    Posts:
    28
    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!

    [​IMG]

    Pattern sprite zoomed in:
    [​IMG]

    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.
     
  2. hippyman

    hippyman Member

    Joined:
    Jun 20, 2016
    Posts:
    565
    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)
     
  3. PWL

    PWL Member

    Joined:
    Jun 21, 2016
    Posts:
    28
    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.
    [​IMG]
     
  4. Phil Strahl

    Phil Strahl Member

    Joined:
    Jul 3, 2016
    Posts:
    387
    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?
     
  5. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,240
    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.
     
  6. PWL

    PWL Member

    Joined:
    Jun 21, 2016
    Posts:
    28
    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.
    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.
    [​IMG] [​IMG]
     
  7. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,240
    okay, what is the image blend color? Also, have you tried using pre-multiply alpha on your pattern sprite yet?
     
  8. PWL

    PWL Member

    Joined:
    Jun 21, 2016
    Posts:
    28
    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? :)
     
  9. RangerX

    RangerX Member

    Joined:
    Jun 20, 2016
    Posts:
    2,605
    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.
     
  10. PWL

    PWL Member

    Joined:
    Jun 21, 2016
    Posts:
    28
    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?
    [​IMG]
    Drawn with plain draw_sprite_ext(). No white outline! (However, the pattern breaks here. That's why I need the surface.)
    [​IMG]

    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.
     
  11. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    4,157
    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.
     
  12. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,492
    Sabo and DukeSoft like this.
  13. RangerX

    RangerX Member

    Joined:
    Jun 20, 2016
    Posts:
    2,605
  14. PWL

    PWL Member

    Joined:
    Jun 21, 2016
    Posts:
    28
    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! :)
     
  15. DukeSoft

    DukeSoft Member

    Joined:
    Jun 20, 2016
    Posts:
    800
    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.p...-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!
     
    Sabo and obscene like this.
  16. DanMunchie

    DanMunchie Member

    Joined:
    Sep 19, 2016
    Posts:
    121
    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.
     
  17. Sabo

    Sabo Guest

    Thanks so much you helped me solve my issue :D
     
    obscene likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice