SFML community forums
General => General discussions => Topic started by: Dragnalith on July 12, 2012, 07:26:04 am
-
Some weeks go I fell in love of Go (golang.org), and because I really like SFML I would like to use it with Go.
There is no binding yet, so instead of waiting for someone doing, I should do it myself.
Right now, the only way to bind C++ to Go is using SWIG. I have read an old post (http://en.sfml-dev.org/forums/index.php?topic=5260.0) speaking about SWIG. Are PySFML and rbSFML using SWIG ?
Is there some work used for the previous binding I can use ?
-
as i remember, GO can link with C libraries, i think you can make binding on top of C libs
check this : http://golang.org/doc/articles/c_go_cgo.html
-
That's true, it's another possibilities, doing the Go binding from the C binding.
But it's a bit weird to do a binding from another binding, isn't? Seems not very clean… (maybe it's still the best idea)
-
But it's a bit weird to do a binding from another binding, isn't? Seems not very clean…
C has a standard ABI (binary interface), C++ doesn't. Therefore is it common that bindings require an intermediate C binding; not all languages support being linked to C++ directly.
In fact SWIG will probably generate this intermediate C binding automatically for languages that can't link to C++.
-
In fact SWIG will probably generate this intermediate C binding automatically for languages that can't link to C++.
Yes that's true. But SWIG will detect a class and bind it to go using interface and not giving the object struct pointer as first arguments.
Anyway, I'm sure the best is doing it by hand. I will try.
-
I begin to bind some function, just the Window functions for testing.
But I have an error Cannot create a window from a worker thread. (OS X limitation). I sure is because of the thread go use for his runtime. But that mean on Mac OS X the binding can be hard to do because I can't force Go to execute my app in the main thread.
-
I wrote Go bindings some time ago in order to get familiar with Go. Maybe you'd like to check out my repository.
Binding: https://bitbucket.org/krepa098/gosfml2 (https://bitbucket.org/krepa098/gosfml2)
Samples: https://bitbucket.org/krepa098/gosfml2-samples (https://bitbucket.org/krepa098/gosfml2-samples)
I'm not sure whether I did it right as I'm quite new to the Go language, but at least it seems to work. :)
-
That's great! I'm also new on Go universe, so I don't know either if my binding would follow the right convention. I check out your work, is really great. Did you write it by hand or is it generated?
You follow the same convention as me, so I like it!
-
Yes it's all handwritten (with a lot of copy-pasting involved). Do you actually cast Go-structs to C, like in toCPtr()? I don't think it's safe because the compiler could decide to add padding. :-\ Any ideas?
-
No… I guess it's possible but I didn't find any document for Go to C. But where do you need to cast Go struct to C ?
-
I was actually referring to this file (https://bitbucket.org/krepa098/gosfml2/src/5ef81ca3cae6/rect.go) (line 44). I know that I can work around it but I'm not sure if I really have to. Anyway, the bindings should be almost complete by now.
-
I don't find a way to do that. But you can convert it to a C.Rectf, then copy the four attribute.
-
It really looks great, and I'm eager to try it - but how do you build the library ?
I "go get"ed it, but when I try go build I get these errors :
1: error: 'sfJoystickConnectEvent' undeclared (first use in this function)
... and 8 other similar errors, with other Event types.
I have the last SFML sources (from 2012-11-24) ; is this a problem ? Do I need to put them somewhere specific ?
EDIT : just noticed I also might need csfml. I have version 1.99 from 2012-05-04. Is it too old ?
EDIT2 : Ow, grabbed csfml from git, and it works ! :D Quite impressive...
-
I'm trying to keep up with SFML git. That's why you need the latest version of SFML and CSFML. I hope you'll enjoy it. Feedback is welcome. :)
-
The lack of any good gui or graphic library for go really turned me down, so finding this was quite exciting. As soon as I finish the mandatory tetris clone, I'll try some fun thing and let you know how gosfml goes :)
-
rbSFML using SWIG ?
No
Sorry for late answer but no I don't, I have written the binding manually. Using SWIG would easy on the process but the library would become very un-ruby-like. Hard to explain but Ruby is thought of being used in a certain way and if I would just do a a straight port, it wouldn't fit in with how you would work normally in the language. Good example is how events are processed using rbSFML.
I also do it directly against the C++ version of SFML and do not go trough the C binding instead. The reason behind this is because I can give Ruby more stuff from the actual library like proper inheritance and custom drawable. Though if I would have gone with the C binding of SFML I could have written entire rbSFML in Ruby but it would be VERY slow because Ruby DL module would have to translate objects and values between Ruby and C all the time.
-
I have one remark for now : the use of pointer or value in functions is not always coherent (or I miss the logic) : sf.NewViewFromRect takes a *sf.FloatRect, but View.SetViewport, as well as many other methods, take a sf.FloatRect...
EDIT : getris completed, time to try some real stuff...
-
Yes I guess you could consider this as a bug as passing nil would simply lead to a crash. In general: If you can pass a pointer then using nil is perfectly valid. Thank you for pointing this out though. Also keep in mind that there are other standing problems like the need of runtime.LockOsThread() and GC.
-
Yeah, I noticed the LockOsThread in the examples, but didn't add it in my app, and it hasn't crashed yet.
Although I noticed after some time the texture used for the blocks just turned to blank - maybe the GC ?...
-
No, Sprite keeps an internal reference its texture to make sure that it doesn't get removed. Without LockOsThread your application won't run properly as OpenGL doesn't support calls comming from a thread other than the one it was created in (afaik). So maybe you could try if that solves your problem :-\.
-
OpenGL doesn't support calls comming from a thread other than the one it was created in
You can call OpenGL functions in any thread, as long as you have an active context. A context cannot be active in more than one thread at a time.
-
One bug found : you renamed Rect{f,i} to {Float,Int}Rect as in SFML, but struct_test.go still uses the old version.
Added an issue at bitbucket.
Also, I created a package for Archlinux to ease installation :
https://aur.archlinux.org/packages/go-sfml2/
Just tell me if if it's a problem.
I added a temporary fix for structs_test.go.
Also, you might want to think about licensing it. If you don't really care, BSD or ZLIB licenses are a good start.
-
Hi Guys,
Thanks for making the Go wrapper.
I'm getting this error when I try to build the gosfml2 wrapper in Windows:
C:\Go\src\pkg\gosfml2>go build
# gosfml2
circleShape.go:15:39: fatal error: SFML/Graphics/CircleShape.h: No such file or directory compilation terminated.
I found in CircleShape.go that it is searching here:
// #include "SFML/Graphics/CircleShape.h"
I've even tried hard coding straight to this, but that doesn't seem to work.
// #include "C:\sfml\include\SFML\Graphics\CircleShape.h"
I even tried setting the environment path to it:
GOPATH=C:\GO;C:\sfml\include;C:\sfml\lib
GOROOT=C:\Go
For what it's worth I compiled SFML RC version 134 statically beforehand with these commands:
cmake -G "MinGW Makefiles" -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=FALSE C:\sfml
mingw32-make
cmake -G "MinGW Makefiles" -D CMAKE_BUILD_TYPE=Debug -D BUILD_SHARED_LIBS=FALSE C:\sfml
mingw32-make
The compiling went ok.
Is there a way I can get Go or GCC to find the header files? Is there like some parameter I need to add to 'go build', an environment variable to see, or a config file?