Skip to content

Instantly share code, notes, and snippets.

@gnysek
Created October 13, 2023 16:30
Show Gist options
  • Save gnysek/06f4dad247fad81b30dbbd31099fe593 to your computer and use it in GitHub Desktop.
Save gnysek/06f4dad247fad81b30dbbd31099fe593 to your computer and use it in GitHub Desktop.
rectangle clip/cut
clip_x1 = 10;
clip_x2 = 500;
clip_y1 = 10;
clip_y2 = 100;
draw_set_color(c_white);
draw_set_alpha(1);
// set up shader:
shader_set(shd_clip_rect);
var u_bounds = shader_get_uniform(shd_clip_rect, "u_bounds");
shader_set_uniform_f(u_bounds, clip_x1, clip_y1, clip_x2, clip_y2);
// draw things:
draw_text(mouse_x, mouse_y, "Lorem ipsum dolor sit amet\nLorem ipsum dolor sit amet\nLorem ipsum dolor sit amet\nLorem ipsum dolor sit amet");
// finish:
shader_reset();
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
varying vec3 v_vPosition;
//
uniform vec4 u_bounds;
//
void main() {
vec4 col = v_vColour * texture2D(gm_BaseTexture, v_vTexcoord);
col.a *= float(v_vPosition.x >= u_bounds[0] && v_vPosition.y >= u_bounds[1] && v_vPosition.x < u_bounds[2] && v_vPosition.y < u_bounds[3]);
gl_FragColor = col;
}
// Shader VSH
//
attribute vec3 in_Position;
attribute vec4 in_Colour;
attribute vec2 in_TextureCoord;
//
varying vec4 v_vColour;
varying vec3 v_vPosition;
varying vec2 v_vTexcoord;
//
void main() {
v_vPosition = in_Position;
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * vec4(in_Position.x, in_Position.y, in_Position.z, 1.0);
v_vColour = in_Colour;
v_vTexcoord = in_TextureCoord;
}
@gnysek
Copy link
Author

gnysek commented Oct 13, 2023

obraz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment