Sam04
Member
Hello everyone. I am trying to cut a hole inside a rectangle not using shaders but is seems I am unable to achieve it.
First, as a guide, this is the effect I want to achieve:
Made in paint, and just imagine the white part is completely transparent.
I started experimenting a bit and this is the last thing I've tried:
Keep in mind that I'm trying this on a completely new project and I only have one object and the code I shared is the entirety of the code written in all of the project. Since I am using a new project just to test this I didn't see the need to use surfaces.
First I set the colour to white and the alpha to 1, then I draw my rectangle and all the pixels it covers should be (1,1,1,1). Then I set the alpha to 0 and the color to black and draw the circle I'm trying to cut, everything drawin in the circle should be (0,0,0,0).
Before drawing the circle I change the blendmode to bm_zero (which is a factor of (0,0,0,0)) in both the destination and the source. It shouldn't matter neither the destination pixel nor the source pixel because the factor I'm using converts anything to 0, and two 0 added together also would result in 0. So the ending pixel should be a completely transparent one. But it draws all of the three test circles as completely solid.
The commented "gpu_set_blendmode_ext(bm_inv_src_alpha, bm_inv_src_alpha);" is there as something I tried reading this post, but didn't work.
I also tried reading the mask article by YellowAfterLife but it seems it doesn't work in GMS2. I tried to open it but it didn't show anything it was suposed to show.
I also found this other thread with a working example, but unfortunately it works by using shaders and I am mostly interested in knowing how to make this using the intial method rather than solving the problem at all (That's because I'm mostly doing this to learn, and suddenly changing to shaders would make the learning I have so far useless).
Any help would be appreaciated. Thanks in advance.
First, as a guide, this is the effect I want to achieve:
I started experimenting a bit and this is the last thing I've tried:
Code:
/// @description Test
if (keyboard_check_pressed(vk_escape)) {game_end();}
//draw_clear_alpha(c_black, 0);
draw_set_colour(c_white);
draw_set_alpha(1);
draw_rectangle(0,0, room_width/2, room_height, false);
gpu_set_blendmode_ext(bm_zero, bm_zero);
//gpu_set_blendmode_ext(bm_inv_src_alpha, bm_inv_src_alpha);
//gpu_set_colorwriteenable(0,0,0,1);//This one does not make any difference at all
draw_set_colour(c_black);
draw_set_alpha(0);
draw_circle(room_width/2, room_height/4, 48, false);
draw_set_alpha(0.5);
draw_circle(room_width/2, room_height/2, 48, false);
draw_set_alpha(1);
draw_circle(room_width/2, room_height*0.75, 48, false);
//I drew 3 different circles to see if trying with different alphas would make a difference
//Spoiler: It doesn't
//gpu_set_colorwriteenable(1,1,1,1);
gpu_set_blendmode(bm_normal);
First I set the colour to white and the alpha to 1, then I draw my rectangle and all the pixels it covers should be (1,1,1,1). Then I set the alpha to 0 and the color to black and draw the circle I'm trying to cut, everything drawin in the circle should be (0,0,0,0).
Before drawing the circle I change the blendmode to bm_zero (which is a factor of (0,0,0,0)) in both the destination and the source. It shouldn't matter neither the destination pixel nor the source pixel because the factor I'm using converts anything to 0, and two 0 added together also would result in 0. So the ending pixel should be a completely transparent one. But it draws all of the three test circles as completely solid.
The commented "gpu_set_blendmode_ext(bm_inv_src_alpha, bm_inv_src_alpha);" is there as something I tried reading this post, but didn't work.
I also tried reading the mask article by YellowAfterLife but it seems it doesn't work in GMS2. I tried to open it but it didn't show anything it was suposed to show.
I also found this other thread with a working example, but unfortunately it works by using shaders and I am mostly interested in knowing how to make this using the intial method rather than solving the problem at all (That's because I'm mostly doing this to learn, and suddenly changing to shaders would make the learning I have so far useless).
Any help would be appreaciated. Thanks in advance.