Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyGaul committed Oct 1, 2024
2 parents 2801d7d + 73399cc commit 2623134
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 35 deletions.
75 changes: 45 additions & 30 deletions samples/scratch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,68 @@ using namespace Cute;

// This isn't really a sample, but a scratch pad for the CF author to experiment.

#define STR(X) #X
const char* s_shadow = STR(
vec4 shader(vec4 color, vec2 pos, vec2 screen_uv, vec4 params)
{
return vec4(vec3(min(color.r, 0.15)*color.a), color.a);
}
);

int main(int argc, char* argv[])
{
float w = 640;
float h = 480;
make_app("Development Scratch", 0, 0, 0, (int)w, (int)h, APP_OPTIONS_WINDOW_POS_CENTERED_BIT, argv[0]);
CF_Shader shadow_shd = make_draw_shader_from_source(s_shadow);
float w = 320, h = 240;
float sx = 2, sy = 2;
make_app("Development Scratch", 0, 0, 0, (int)(w * sx), (int)(h * sy), APP_OPTIONS_WINDOW_POS_CENTERED_BIT, argv[0]);
CF_Canvas plain = make_canvas(canvas_defaults((int)w, (int)h));
CF_Canvas shadows = make_canvas(canvas_defaults((int)w, (int)h));
cf_clear_color(0,0,0,0);

while (app_is_running()) {
app_update();
draw_push_antialias(false);
draw_scale(sx, sy);
draw_rotate(CF_PI * CF_SECONDS / 16.0f);

draw_circle(V2(-200,100), 30, 5);
draw_push_color(color_red());
draw_circle(V2( 200,100), 30, 5);
draw_pop_color();
render_to(plain, true);
draw_arrow(V2(0, 0), V2(20, 0), 1, 5);

draw_push_shader(shadow_shd);
draw_canvas(plain, 0, 0, w, h);
draw_pop_shader();
render_to(shadows, true);

draw_canvas(shadows, 5, -5, w, h);
draw_push();
//draw_scale(-1,-1);
//draw_translate(0,0);
//draw_rotate((float)CF_SECONDS);
draw_push_color(color_blue());
draw_bezier_line(V2(8, -10), V2(10, 15), V2(20, 10), 16, 1);

draw_push_color(color_yellow());
draw_box(V2(0, 0), 10, 10);

draw_push_color(color_green());
draw_box_rounded(make_aabb(V2(0, 0), 50, 50), 1, 3);

draw_push_color(color_orange());
draw_capsule(V2(0, -20), V2(0, 20), 8, 1);

draw_push_color(color_cyan());
draw_circle(V2(0, 0), 10);

draw_push_color(color_magenta());
draw_line(V2(-35, 28), V2(100, 9), 1);

Array<v2> points = { V2(0,0) };
draw_push_color(color_purple());
draw_polyline(points.data(), points.count());

points.add(V2(12, 18));
draw_push_color(color_grey());
draw_polyline(points.data(), points.count());

points.add(V2(-27, 35));
points.add(V2(-40, 5));
draw_push_color(color_white());
draw_polyline(points.data(), points.count(), 1, true);

draw_push_color(cf_make_color_hex(0xDEADBEEF));
draw_quad(make_aabb(V2(0,0), 37, 42), 1.0f, 4);

draw_push_color(cf_make_color_hex(0xDADB0D));
draw_tri(V2(13, 48), V2(27, 16), V2(15, 30), 1.0f, 2.0f);

render_to(plain, true);
draw_canvas(plain, 0, 0, w, h);
draw_pop();
render_to(app_get_canvas(), true);

app_draw_onto_screen();
}

destroy_shader(shadow_shd);
destroy_canvas(plain);
destroy_canvas(shadows);
destroy_app();

return 0;
Expand Down
8 changes: 4 additions & 4 deletions src/cute_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ void cf_draw_tri_fill(CF_V2 p0, CF_V2 p1, CF_V2 p2, float chubbiness)

void cf_draw_line(CF_V2 p0, CF_V2 p1, float thickness)
{
s_draw_capsule(p0, p1, 0, thickness, true);
s_draw_capsule(p0, p1, 0, thickness * 0.5f, true);
}

void cf_draw_polyline(CF_V2* pts, int count, float thickness, bool loop)
Expand All @@ -919,9 +919,9 @@ void cf_draw_polyline(CF_V2* pts, int count, float thickness, bool loop)
if (count <= 0) {
return;
} else if (count == 1) {
cf_draw_circle_fill2(pts[0], radius);
cf_draw_circle_fill2(pts[0], thickness);
} else if (count == 2) {
cf_draw_capsule_fill2(pts[0], pts[1], radius);
cf_draw_line(pts[0], pts[1], thickness);
}

// Each portion of the polyline will be rendered with a single triangle per spritebatch entry.
Expand Down Expand Up @@ -1261,7 +1261,7 @@ void cf_draw_arrow(CF_V2 a, CF_V2 b, float thickness, float arrow_width)
v2 n = norm(b - a);
v2 t = skew(n) * arrow_width;
n = n * arrow_width;
cf_draw_capsule_fill2(a, b - n, thickness * 0.5f);
cf_draw_line(a, b - n, thickness);
cf_draw_tri_fill(b, b - n + t, b - n - t, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/cute_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ void main()
v_uv = in_uv;
v_col = in_col;
v_radius = in_radius;
v_stroke = in_stroke;
v_stroke = in_stroke * 0.5;
v_aa = in_aa;
v_type = in_params.r;
v_alpha = in_params.g;
Expand Down

0 comments on commit 2623134

Please sign in to comment.