• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

draw rectangle on non-transparent background only

bacteriaman

Member
I have an object with a DRAW event that displays a semi-opaque overlay (aka. dimmer) over the entire room. This is used when displaying a dialog in the foreground (just like a browser modal window.)

GML:
draw_set_alpha(0.6);
draw_set_color(COLOR_BROWN);
draw_rectangle(0, 0, 1024, 662, false);
draw_set_alpha(1)
However, I only want the overlay to appear on non-transparent portions of the room. Transparent portions of the room should be unaffected and display the background color.

I believe this can be accomplished with Shaders, but I am not sure how to go about it. I am prepared to do my own experimentation, but I would be grateful for any tips the community would like to share.
 
Last edited:

rytan451

Member
If you're dimming, then you could instead draw everything you're dimming to a second surface (at the beginning of each step, clear it to black and alpha 0). Then, after everything is drawn to the surface, using a multiply blend mode gpu_set_blendmode_ext(bm_dest_color, bm_zero), draw the rectangle over it. Then, using the normal blend mode, draw that surface onto the application surface (which you need to have already cleared to the background color).
 

bacteriaman

Member
@rytan451, thank you for your response.

I like your suggestion, but the solution to my particular challenge turned out to be straightforward.

I actually created a shader to achieve the desired effect, but using a shader turned out to be unnecessary.

I ended up simply using draw_sprite_ext() to draw the background image with the desired blend and alpha values.

That said, I am reminded of how cool shaders are and I look forward to using them more in the future.
 
Top