odin_chat_client/src/gfx/gfx.odin

54 lines
1.4 KiB
Plaintext

package gfx;
import "core:strings"
import c "core:c"
foreign import gfx "../../bin/libgfx.a"
GfxFrameFunc :: proc "c" (mouse_x: int, mouse_y: int, mouse_left_down: bool, mouse_right_down: bool)
cx :: struct {}
GpuGlyph :: struct {
atlas_position: [2]f32,
size: [2]f32,
position: [2]f32,
y_offset: f32,
_haha_alignment: f32,
color: [2]f32,
}
@(private)
gfx_string :: struct {
data: [^]u8,
len: c.size_t,
// unused
owned: c.bool,
}
foreign gfx {
keep_running: bool
@(link_name="gfx_init_context") init_context :: proc "c" (frame_func: GfxFrameFunc, width: u32, height: u32) -> ^cx ---
@(link_name="gfx_run_events") run_events :: proc "c" (gfx_cx: ^cx) ---
@(link_name="gfx_add_glyph") add_glyph :: proc "c" (gfx_cx: ^cx, glyph: GpuGlyph) ---
@(link_name="gfx_push_texture_buffer") push_texture_buffer :: proc "c" (gfx_cx: ^cx, width: u32, height: u32, data: [^]u8, len: u32) ---
@(private)
gfx_queue_text :: proc "c" (gfx_cx: ^cx, text: gfx_string, position: [^]f32, max_x: f32, max_y: f32, color: [^]f32) ---
}
queue_text :: proc(gfx_cx: ^cx, text: string, position: [2]f32, max_x: f32, max_y: f32, color: [4]f32) {
text_ := gfx_string {
data = raw_data(text),
len = len(text),
};
p := []f32 { position[0], position[1] }
c := []f32 { color[0], color[1], color[2], color[3] }
gfx_queue_text(gfx_cx, text_, raw_data(p), max_x, max_y, raw_data(c))
}