• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

SOLVED Issue with alpha and surfaces

Hi,
I got an object obj_foo with the following Draw Event:
GML:
draw_set_color(c_green);
draw_set_alpha(scr_wave(.75,1,2,0,0));
draw_rectangle(x,y,x+32,y+32,false);
draw_set_alpha(1);
This code draws a blinking green square (scr_wave is a script that I created that create values following a cos signal)

And I got an objet obj_surf with the following Draw Event:

GML:
if surface_exists(surface) { //in create event : surface = noone;
    surface_set_target(surface);
    draw_clear_alpha(col_purpule, .97); //col_purple a a color that I defined in the create event

    with (obj_foo) event_perform(ev_draw, 0);


    surface_reset_target();
    draw_surface(surface, x1, y1);
} else {
    surface = surface_create(x2 - x1, y2 - y1);
}
The above codes are simplified, but here is the end result :
The surface created is the purple zone and I create the obj_foo at the four corners. Do not pay attention to the objects displayed at the top left, I just did not uncheck the visible option of these objects.
As you can the when the alpha of the obj_foo is low, the transparency makes the background appear directly and not the purple of my surface. How can I resolve this issue?
Thanks !
 

TheouAegis

Member
Just mess around with draw_enable_alphablend() at different times, or play with blend modes.

You don't need the pictures in that post, they weren't very helpful. lol
 
Thanks for answer ! I am moving forward in my problem, but I still have a small problem: It is not necessarily visible in the video, but the "background" is not 100% opaque, (its alpha is 96% ...) .The blendmode adding the alphas of my two components, it is clear that I thus obtain a total alpha always greater than 1. However, I do get the desired effect of "blinking" from my green square. So I would like to find a way to get by with its blendmodes by getting a constant alpha (which is the alpha of my surface, so here 96%). An idea? Thank you.

PS : Because I'm not sure I'm understandable, there is an image with the alpha of my surface lowered at 70% : You can see that the alpha of my squares is higher than the alpha of my surface
1603394115769.png
1603394157973.png
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
Okay, when you have drawn everything to the surface, but BEFORE resetting the draw target call gpu_colourwriteenable(false, false, false, true) and then draw a solid black rectangle over the entire surface. After that call the same function again setteing everything to true, then reset the surface target to normal drawing again. This should correct the issue you are having with the surface alpha. So:

GML:
// DRAW EVENT
surface_set_target(SURFACE);

// Draw everything here

gpu_colourwriteenable(false, false, false, true);
draw_set_alpha(1);
draw_set_colour(c_black);
draw_rectangle(0, 0, surf_width, surf_height, false);
gpu_colourwriteenable(true, true, true, true);

surface_reset_target();
 
Thank you very much!
Your answer helped me solve my problem. I would just like to correct you on one point: the function to use is gpu_set_colourwriteenable and not gpu_colourwriteenable!
Even if I'm not sure I understood exactly this solution, I'm very happy with the result. I'll look into why it works.
 
Top