1. Gosu Wrapper

I have recently written a wrapper for the Gosu library. [https://www.libgosu.org/]

The basic window example works. Though I can't figure out why input or drawing to the screen doesn't work.

[https://www.file-upload.org/rm3imq56kj7x] - Gosu wrapper

EDIT: Added license

include std/ffi.e 
include gosu.e 
 
atom window = Gosu_Window_create(640,480,WF_WINDOWED,60) 
 
Gosu_Window_set_caption(window,"Simple Window Example") 
 
Gosu_Window_destroy(window) 
new topic     » topic index » view message » categorize

2. Re: Gosu Wrapper

Icy_Viking said...

FYI you can upload your own files directly to GitHub using the releases feature. If it's just a snapshot of your current work, tag the release using the current date (e.g. 20240726) and mark it as a pre-release.

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: Gosu Wrapper

ghaberek said...
Icy_Viking said...

FYI you can upload your own files directly to GitHub using the releases feature. If it's just a snapshot of your current work, tag the release using the current date (e.g. 20240726) and mark it as a pre-release.

-Greg

Thanks Greg. I think the reason the input or drawing functions aren't working due to the way Gosu handle's callbacks. I'll have to look more into the callback functions.

GOSU_FFI_API void Gosu_Window_set_update(Gosu_Window* window, void function(void* data), 
                                         void* data); 

public constant xGosu_Window_set_update = define_c_proc(gosu,"+Gosu_Window_set_update",{C_POINTER,C_POINTER,C_POINTER,C_POINTER}) 
 
public procedure Gosu_Window_set_update(atom window,object func,atom data,atom pdata) 
	c_proc(xGosu_Window_set_update,{window,func,data,pdata}) 
end procedure 

}}}

new topic     » goto parent     » topic index » view message » categorize

4. Re: Gosu Wrapper

Icy_Viking said...

I think the reason the input or drawing functions aren't working due to the way Gosu handle's callbacks. I'll have to look more into the callback functions.

GOSU_FFI_API void Gosu_Window_set_update(Gosu_Window* window, void function(void* data), 
                                         void* data); 

This function takes three parameters:

  • Gosu_Window* window - a pointer to a Gosu_Window object
  • void function(void* data) - a pointer to a function that accepts one parameter (this is our "callback")
  • void* data - a generic pointer to any object (this is "user" object, a concept used by most callback-based systems)

If it helps, you can create alias constants to break up the sea of C_POINTER values everywhere. I find this helps weed out a lot of simple errors.

constant C_CALLBACK  = C_POINTER -- pointer to a callback function 
constant C_PVOID     = C_POINTER -- pointer to any object (void*) 
constant GOSU_WINDOW = C_POINTER -- pointer to a Gosu_Window object 
 
constant xGosu_Window_create = define_c_proc(gosu,"+Gosu_Window_create",{C_INT,C_INT,C_UINT,C_DOUBLE},GOSU_WINDOW) 
constant xGosu_Window_set_update = define_c_proc(gosu,"+Gosu_Window_set_update",{GOSU_WINDOW,C_CALLBACK,C_PVOID}) 
 
public function Gosu_Window_create(integer width, integer height, atom window_flags, atom update_interval) 
    return c_func(xGosu_Window_create,{width,height,window_flags,update_interval}) 
end function 
 
public procedure Gosu_Window_set_update(atom window,object func,atom data) 
    c_proc(xGosu_Window_set_update,{window,func,data}) 
end procedure 

And it should come together something like this:

function update_callback(atom data) 
    return 0 
end function 
constant update_callback_id = routine_id("update_callback") 
constant update_callback_cb = call_back(update_callback) 
 
atom window = Gosu_Window_create(800, 450, 0, 1/60) 
Gosu_Window_set_update(window, update_callback_cb, NULL) 

Disclaimer: I have not actually tried any of this to see if it works. I'm not sure how or if the callbacks are supposed to get knowledge about the window object.

-Greg

new topic     » goto parent     » topic index » view message » categorize

5. Re: Gosu Wrapper

Thanks again Greg!

Your help is always appericated. Callbacks fly over my head sometimes, but you make them look so simple.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu