GMS 2 Problem with alpha blending and surfaces

Discussion in 'Programming' started by AlexMdle, Jan 24, 2019.

  1. AlexMdle

    AlexMdle Member

    Joined:
    Mar 9, 2018
    Posts:
    13
    My game currently has application_surface_draw_enable set to false and I'm manually drawing the surface onto the screen. This works perfectly fine, however seems to clash with alphablending.

    jumble.png

    Code below is supposed to draw a red circle with the 0 alpha circle on top of it. Instead, a sort of a vacuum bubble is drawn, seemingly ignoring any draw code before it, but also not cleaning the values of any draw code after it - the jumble in the picture is the result of the player character moving around in that bubble.

    It draws fine when application_surface_draw_enable draws by default - exception being that sprite_create_from_surface also fails to account for alpha blend(though that might be unrelated).

    Code:
    draw_circle_color(x,y,80,c_red,c_red,false);
    gpu_set_blendenable(false);
    gpu_set_colorwriteenable(false, false, false, true);
    
    draw_set_alpha(0);
    draw_circle(x,y,80,false);
    draw_set_alpha(1);
    
    gpu_set_colorwriteenable(true, true, true, true);
    gpu_set_blendenable(true);
    Anyone know what the problem might be?

    Edit: I have managed to seemingly fix it by prefacing all the surface drawing with
    Code:
    gpu_set_blendmode_ext(bm_one, bm_inv_src_alpha);
    gpu_set_blendenable(false);
    
    It's not ideal but gets the job done. Im not sure if the topic needs to stay up, but I hope it helps anyone with the same problem.
     
    Last edited: Jan 24, 2019
  2. Bart

    Bart Member

    Joined:
    Jun 21, 2016
    Posts:
    197
    If you draw the application surface manually, you have to disable alpha blending before drawing it.
    It's not mentioned in the manual, but there's a related issue in the bugtracker on this: 30191
    It seems to be expected behavior.
     
  3. AlexMdle

    AlexMdle Member

    Joined:
    Mar 9, 2018
    Posts:
    13
    Really wish that was at least documented, it's definitely not expected knowledge. Thanks for sharing!
     
  4. rmanthorp

    rmanthorp YoYo Games Staff Admin YYG Staff

    Joined:
    Apr 15, 2016
    Posts:
    312

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