for i: 0 .. glyph.points.count {
p := glyph.points[i];
-
switch state {
case 0 {
- // curr_x = cast(i32) p.x;
- // curr_y = cast(i32) p.y;
+ curr_x = cast(i32) p.x;
+ curr_y = cast(i32) p.y;
array_push(^poly_points, V2i.{ ~~p.x, ~~p.y });
state = 1;
// curr_x, curr_y,
// ~~p.x, ~~p.y);
- // curr_x = cast(i32) p.x;
- // curr_y = cast(i32) p.y;
+ curr_x = cast(i32) p.x;
+ curr_y = cast(i32) p.y;
+
array_push(^poly_points, V2i.{ ~~p.x, ~~p.y });
} else {
case #default {
prev := glyph.points[i - 1];
if p.on_curve {
- // draw_quadratic_line(data, width, height, scale,
- // curr_x, curr_y,
- // ~~prev.x, ~~prev.y,
- // ~~p.x, ~~p.y);
-
- // curr_x = cast(i32) p.x;
- // curr_y = cast(i32) p.y;
- // array_push(^poly_points, V2i.{ ~~prev.x, ~~prev.y });
- array_push(^poly_points, V2i.{ ~~p.x, ~~p.y });
+
+ bp : [3] V2f;
+ bp[0] = V2f.{ ~~curr_x, ~~curr_y };
+ bp[1] = V2f.{ ~~cast(i32) prev.x, ~~cast(i32) prev.y };
+ bp[2] = V2f.{ ~~cast(i32) p.x, ~~cast(i32) p.y };
+ bps := bp[0 .. 3];
+
+ for t: 1 .. 5 {
+ s := bezier_curve(~~t / 4.0f, bps);
+ array_push(^poly_points, V2i.{ ~~s.x, ~~s.y });
+ }
+
+ curr_x = cast(i32) p.x;
+ curr_y = cast(i32) p.y;
+
state = 1;
} else {
- //draw_quadratic_line(data, width, height, scale,
- // curr_x, curr_y,
- // ~~prev.x, ~~prev.y,
- // ~~((prev.x + p.x) / ~~2), ~~((prev.y + p.y) / ~~2));
-
- //curr_x = cast(i32) ((prev.x + p.x) / ~~2);
- //curr_y = cast(i32) ((prev.y + p.y) / ~~2);
- array_push(^poly_points, V2i.{ ~~prev.x, ~~prev.y });
- array_push(^poly_points, V2i.{ ~~((prev.x + p.x) / ~~2), ~~((prev.y + p.y) / ~~2) });
+ bp : [3] V2f;
+ bp[0] = V2f.{ ~~curr_x, ~~curr_y };
+ bp[1] = V2f.{ ~~cast(i32) prev.x, ~~cast(i32) prev.y };
+ bp[2] = V2f.{ ~~(~~(prev.x + p.x) / 2), ~~(~~(prev.y + p.y) / 2) };
+ bps := bp[0 .. 3];
+
+ for t: 1 .. 5 {
+ s := bezier_curve(~~t / 4.0f, bps);
+ array_push(^poly_points, V2i.{ ~~s.x, ~~s.y });
+ }
+
+ curr_x = cast(i32) bp[2].x;
+ curr_y = cast(i32) bp[2].y;
}
}
}
p = glyph.points[contour_start];
if p.on_curve {
- // draw_quadratic_line(data, width, height, scale,
- // curr_x, curr_y,
- // ~~prev.x, ~~prev.y,
- // ~~p.x, ~~p.y);
-
- // curr_x = cast(i32) p.x;
- // curr_y = cast(i32) p.y;
- array_push(^poly_points, V2i.{ ~~prev.x, ~~prev.y });
+ bp : [3] V2f;
+ bp[0] = V2f.{ ~~curr_x, ~~curr_y };
+ bp[1] = V2f.{ ~~cast(i32) prev.x, ~~cast(i32) prev.y };
+ bp[2] = V2f.{ ~~cast(i32) p.x, ~~cast(i32) p.y };
+ bps := bp[0 .. 3];
+
+ for t: 1 .. 5 {
+ s := bezier_curve(~~t / 4.0f, bps);
+ array_push(^poly_points, V2i.{ ~~s.x, ~~s.y });
+ }
} else {
- // draw_quadratic_line(data, width, height, scale,
- // curr_x, curr_y,
- // ~~prev.x, ~~prev.y,
- // ~~((prev.x + p.x) / ~~2), ~~((prev.y + p.y) / ~~2));
-
- // curr_x = cast(i32) ((prev.x + p.x) / ~~2);
- // curr_y = cast(i32) ((prev.y + p.y) / ~~2);
- array_push(^poly_points, V2i.{ ~~prev.x, ~~prev.y });
- array_push(^poly_points, V2i.{ ~~((prev.x + p.x) / ~~2), ~~((prev.y + p.y) / ~~2) });
+ bp : [3] V2f;
+ bp[0] = V2f.{ ~~curr_x, ~~curr_y };
+ bp[1] = V2f.{ ~~cast(i32) prev.x, ~~cast(i32) prev.y };
+ bp[2] = V2f.{ ~~(~~(prev.x + p.x) / 2), ~~(~~(prev.y + p.y) / 2) };
+ bps := bp[0 .. 3];
+
+ for t: 1 .. 5 {
+ s := bezier_curve(~~t / 4.0f, bps);
+ array_push(^poly_points, V2i.{ ~~s.x, ~~s.y });
+ }
}
contour_start = i + 1;
count += 1;
state = 0;
+ // for p: poly_points {
+ // print_vec(p);
+
+ // tx := cast(i32) (~~p.x * scale);
+ // ty := cast(i32) (~~p.y * scale);
- // col := cast(u8) 255;
- // if v2_orientation(poly_points[0], poly_points[1], poly_points[2]) < 0 do col = cast(u8) 0;
+ // if tx >= 0 && ty >= 0 && tx < width && ty < height {
+ // data[tx + (height - 1 - ty) * width] = cast(u8) 255;
+ // }
+ // }
- for p: poly_points do print_vec(p);
for y: 0 .. height do for x: 0 .. width {
if is_inside_polygon(array_to_slice(^poly_points), V2i.{ ~~(~~x / scale), ~~(~~y / scale) }) {
curr := data[x + (height - 1 - y) * width];
// renderer.color = Color4f32.{ 1f, 0f, 0f, 1f };
- // points : [6] V2f;
- // points[0] = V2f.{ 500.0f, 700.0f };
- // points[1] = V2f.{ 600.0f, 200.0f };
- // points[2] = V2f.{ 700.0f, 400.0f };
- // points[3] = V2f.{ 1700.0f, 800.0f };
- // points[4] = V2f.{ 1800.0f, 400.0f };
- // points[5] = V2f.{ 1000.0f, 200.0f };
-
- // for i: 0 .. 200 {
- // pos := bezier_curve(~~i / 200.0f, points[0 .. 6]);
- // draw_rect(^renderer, pos.x, pos.y, 16f, 16f);
- // }
+ points : [6] V2f;
+ points[0] = V2f.{ 500.0f, 700.0f };
+ points[1] = V2f.{ 600.0f, 200.0f };
+ points[2] = V2f.{ 700.0f, 400.0f };
+ points[3] = V2f.{ 1700.0f, 800.0f };
+ points[4] = V2f.{ 1800.0f, 400.0f };
+ points[5] = V2f.{ 1000.0f, 200.0f };
+
+ for i: 0 .. 200 {
+ pos := bezier_curve(~~i / 200.0f, points[0 .. 6]);
+ draw_rect(^renderer, pos.x, pos.y, 16f, 16f);
+ }
// for y: 0 .. glyph_size do for x: 0 .. glyph_size {
// if glyph_data[x + y * glyph_size] != ~~0 {
render_context_flush(^renderer);
texture_use(^font_tex);
- draw_rect(^renderer, 100f, 100f, 64f, 64f);
+ draw_rect(^renderer, 100f, 100f, 512f, 512f);
render_context_flush(^renderer);
}
ttf = ttf_create(ttf_data);
glyph : ^TTGlyph = null;
- glyph_index := ttf_lookup_glyph_by_char(^ttf, ~~ #char "%");
+ glyph_index := ttf_lookup_glyph_by_char(^ttf, ~~ #char "S");
glyph = ttf_read_glyph(^ttf, glyph_index);
if glyph == null do return;
defer ttf_glyph_destroy(glyph);
array_free /usr/share/onyx/core/array.onyx /^array_free :: proc (arr: ^[..] $T) {$/
array_init /usr/share/onyx/core/array.onyx /^array_init :: proc (arr: ^[..] $T, initial_cap := 4) {$/
array_insert /usr/share/onyx/core/array.onyx /^array_insert :: proc (arr: ^[..] $T, idx: u32, x: T) {$/
-array_map /usr/share/onyx/core/array.onyx /^array_map :: proc (arr: ^[..] $T, f: proc (T) -> T) {$/
+array_map /usr/share/onyx/core/array.onyx /^array_map :: proc (arr: ^[..] $T, data: $R, f: proc (T, R) -> T) {$/
array_pop /usr/share/onyx/core/array.onyx /^array_pop :: proc (arr: ^[..] $T) -> T {$/
array_push /usr/share/onyx/core/array.onyx /^array_push :: proc (arr: ^[..] $T, x: T) {$/
array_remove /usr/share/onyx/core/array.onyx /^array_remove :: proc (arr: ^[..] $T, elem: T) {$/
update src/main.onyx /^update :: proc () {$/
useProgram /usr/share/onyx/core/js/webgl.onyx /^useProgram :: proc (program: GLProgram) #foreign "gl" "useProgram" ---$/
v2_add src/vecmath.onyx /^v2_add :: proc (a: V2($T), b: V2(T)) -> V2(T) {$/
+v2_equal src/vecmath.onyx /^v2_equal :: proc (a: V2($T), b: V2(T)) -> bool {$/
v2_lerp src/vecmath.onyx /^v2_lerp :: proc (t: f32, start: V2($T), end: V2(T)) -> V2(T) {$/
v2_mul src/vecmath.onyx /^v2_mul :: proc (a: V2($T), scalar: T) -> V2(T) {$/
v2_on_segment src/vecmath.onyx /^v2_on_segment :: proc (a: V2($T), b: V2(T), c: V2(T)) -> bool {$/