Sokol Wrapper
- Posted by Icy_Viking 5 days ago
- 138 views
Hi all,
Using help with AI, yes I know, AI. I was able to get a simple example working with my sokol wrapper.
[https://github.com/gAndy50/EuSokol] [https://github.com/ghaberek/libffi-euphoria/tree/main/include/std] - Greg's FFI library for Euphoria
-- SokolApp & SokolGfx Green Background Example include std/ffi.e include sokol_app.e include sokol_gfx.e -- Global handle for our configured render pass atom pass_ptr = 0 function init_cb(atom udata) sapp_set_window_title("OpenEuphoria - Sokol Gfx Green Background") puts(1, "Initializing Sokol Gfx...\n") -- 1. Initialize graphics backend atom sg_desc_ptr = allocate_struct(sg_desc) sg_setup(sg_desc_ptr) if not sg_isvalid() then puts(1, "Error: Sokol Gfx failed to initialize!\n") return 1 end if puts(1, "Sokol Gfx initialized successfully.\n") -- 2. Allocate and configure the sg_pass structure with a green clear action -- libffi-euphoria recursively packs nested sequences matching the defined C structs. pass_ptr = allocate_struct(sg_pass, { 0, -- start_canary 0, -- compute (false) { -- action (sg_pass_action) { -- colors array (SG_MAX_COLOR_ATTACHMENTS = 4) { 1, 0, {0.0, 1.0, 0.0, 1.0} }, -- Color 0: load_action=CLEAR (1), store_action=STORE (0), RGBA=Green { 1, 0, {0.0, 1.0, 0.0, 1.0} }, -- Color 1 (unused) { 1, 0, {0.0, 1.0, 0.0, 1.0} }, -- Color 2 (unused) { 1, 0, {0.0, 1.0, 0.0, 1.0} } -- Color 3 (unused) }, { 0, 0, 1.0 }, -- depth (load_action, store_action, clear_value) { 0, 0, 0 } -- stencil (load_action, store_action, clear_value) }, 0, -- attachments (SG_INVALID_ID / 0) { -- swapchain (sg_swapchain - zeros mean use default window swapchain dimensions) 0, 0, 0, 0, 0, -- width, height, sample_count, color_format, depth_format {0, 0, 0}, -- metal {0, 0, 0}, -- d3d11 {0, 0, 0}, -- wgpu {0} -- gl }, 0, -- label (NULL) 0 -- end_canary }) puts(1, "Pass action configured. Window will clear to green.\n") return 0 end function function frame_cb(atom udata) -- 3. Render Pass Loop: Clear screen to green every frame using our pass structure sg_begin_pass(pass_ptr) -- (Draw calls for geometry would go here) sg_end_pass() sg_commit() return 0 end function function cleanup_cb(atom udata) puts(1, "Shutting down graphics...\n") sg_shutdown() return 0 end function function event_cb(atom event_ptr, atom udata) return 0 end function procedure main() if app = 0 or gfx = 0 then puts(1, "Error: Sokol libraries (sokol_app or sokol_gfx) failed to load.\n") abort(1) end if -- Create FFI callbacks for Sokol lifecycle events atom c_init = call_back(routine_id("init_cb")) atom c_frame = call_back(routine_id("frame_cb")) atom c_cleanup = call_back(routine_id("cleanup_cb")) atom c_event = call_back(routine_id("event_cb")) -- Allocate the window descriptor structure atom desc = allocate_struct(sapp_desc) puts(1, "Starting Sokol application window...\n") -- Run the application loop sapp_run(desc) end procedure main()
The background is supposed to be green, but it shows up as black. I've linked my repo for the wrapper. Any help is appreciated.

