odin-blend2d

Odin bindings to Blend2D
Log | Files | Refs | README | LICENSE

commit 1b6179d43face34f0e34aafb7316e9d2edd4f111
parent 00c3d948d49b6b6fd8ed66cd9e0b1db471ea19b0
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Sat, 25 Oct 2025 23:20:02 -0300

example: add samples ported from Blend2D

Diffstat:
Aexample/sample_1.odin | 36++++++++++++++++++++++++++++++++++++
Aexample/sample_2.odin | 47+++++++++++++++++++++++++++++++++++++++++++++++
Aexample/sample_3.odin | 46++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 129 insertions(+), 0 deletions(-)

diff --git a/example/sample_1.odin b/example/sample_1.odin @@ -0,0 +1,36 @@ +package main + +import blend2d "../binding" + +main :: proc() { + img: blend2d.ImageCore + + blend2d.image_init(&img) + blend2d.image_create(&img, 480, 480, .PRGB32) + + ctx: blend2d.ContextCore + ctx_cfg: blend2d.ContextCreateInfo + + blend2d.context_init(&ctx) + blend2d.context_begin(&ctx, &img, &ctx_cfg) + blend2d.context_clear_all(&ctx) + + path: blend2d.PathCore + blend2d.path_init(&path) + blend2d.path_move_to(&path, 26, 31) + blend2d.path_cubic_to(&path, 642, 132, 587, -136, 25, 464) + blend2d.path_cubic_to(&path, 882, 404, 144, 267, 27, 31) + + origin: blend2d.Point + + blend2d.context_fill_path_d_rgba32(&ctx, &origin, &path, 0xFFFFFFFF) + blend2d.context_end(&ctx) + + codec: blend2d.ImageCodecCore + codecs: blend2d.ArrayCore + + blend2d.image_codec_array_init_built_in_codecs(&codecs) + blend2d.image_codec_init_by_name(&codec, "PNG", len("PNG"), nil) + blend2d.image_write_to_file(&img, "sample_1.png", &codec) +} + diff --git a/example/sample_2.odin b/example/sample_2.odin @@ -0,0 +1,47 @@ +package main + +import blend2d "../binding" + +main :: proc() { + img: blend2d.ImageCore + + blend2d.image_init(&img) + blend2d.image_create(&img, 480, 480, .PRGB32) + + ctx: blend2d.ContextCore + ctx_cfg: blend2d.ContextCreateInfo + + blend2d.context_init(&ctx) + blend2d.context_begin(&ctx, &img, &ctx_cfg) + blend2d.context_clear_all(&ctx) + + grad: blend2d.GradientCore + grad_values := [4]f64{0, 0, 0, 480} + + blend2d.gradient_init(&grad) + blend2d.gradient_set_values(&grad, 0, &grad_values[0], 4) + blend2d.gradient_add_stop_rgba32(&grad, 0.0, 0xFFFFFFFF) + blend2d.gradient_add_stop_rgba32(&grad, 0.5, 0xFF5FAFDF) + blend2d.gradient_add_stop_rgba32(&grad, 1.0, 0xFF2F5FDF) + + blend2d.context_set_fill_style(&ctx, cast(^blend2d.Unknown)(&grad)) + + rect := blend2d.RoundRect { + x = 40, + y = 40, + w = 400, + h = 400, + rx = 45.5, + ry = 45.5, + } + + blend2d.context_fill_geometry(&ctx, .ROUND_RECT, &rect) + + codec: blend2d.ImageCodecCore + codecs: blend2d.ArrayCore + + blend2d.image_codec_array_init_built_in_codecs(&codecs) + blend2d.image_codec_init_by_name(&codec, "PNG", len("PNG"), nil) + blend2d.image_write_to_file(&img, "sample_2.png", &codec) +} + diff --git a/example/sample_3.odin b/example/sample_3.odin @@ -0,0 +1,46 @@ + +package main + +import blend2d "../binding" + +main :: proc() { + + img: blend2d.ImageCore + + blend2d.image_init(&img) + blend2d.image_create(&img, 480, 480, .PRGB32) + + ctx: blend2d.ContextCore + ctx_cfg: blend2d.ContextCreateInfo + + blend2d.context_init(&ctx) + blend2d.context_begin(&ctx, &img, &ctx_cfg) + blend2d.context_clear_all(&ctx) + + texture: blend2d.ImageCore + blend2d.image_init(&texture) + blend2d.image_read_from_file(&texture, "blend2d/testing/resources/Leaves.jpeg", nil) + + pattern: blend2d.PatternCore + blend2d.pattern_init(&pattern) + blend2d.pattern_set_image(&pattern, &texture, nil) + + rect := blend2d.RoundRect { + x = 40, + y = 40, + w = 400, + h = 400, + rx = 45.5, + ry = 45.5, + } + + blend2d.context_fill_geometry_ext(&ctx, .ROUND_RECT, &rect, cast(^blend2d.Unknown)(&pattern)) + blend2d.context_end(&ctx) + + codec: blend2d.ImageCodecCore + codecs: blend2d.ArrayCore + blend2d.image_codec_array_init_built_in_codecs(&codecs) + blend2d.image_codec_init_by_name(&codec, "PNG", len("PNG"), nil) + blend2d.image_write_to_file(&img, "sample_3.png", &codec) +} +