Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this a library for use with webassembly? #13

Closed
dicecko opened this issue Mar 5, 2019 · 5 comments
Closed

Is this a library for use with webassembly? #13

dicecko opened this issue Mar 5, 2019 · 5 comments

Comments

@dicecko
Copy link

dicecko commented Mar 5, 2019

Hi,

Can this library be used to directly draw on a HTML5 Canvas when writing a Webassembly program?

@tfriedel6
Copy link
Owner

Hi, at the moment that is not possible. At some point I would like to try it, but probably not soon.

@dicecko
Copy link
Author

dicecko commented Mar 5, 2019

I'm just new to webassembly and only have read about GO, sorry if don't really understand the languages yet.
Maybe I was a bit strict with 'directly'.
Can you create a Webassembly with this library to create a canvas and then in one JS call draw that entire canvas in the DOM?

@tfriedel6
Copy link
Owner

No worries. So this library doesn't do anything with HTML or JS at the moment, it is pure Go and uses the system OpenGL driver to render. This is not available in a Webassembly context, so it won't work there. To make it work would require a separate implementation for Webassembly, which would be possible but I just have not started it yet.

@dicecko
Copy link
Author

dicecko commented Mar 6, 2019

Okay clear and thank you. I read into GO a couple of hours yesterday and it looks really cool!
I found that they now have https://golang.org/pkg/syscall/js/
This basically let's you import the DOM objects and directly call the JS functions and therefor also Canvas objects which solves the problem I had with Emscripten.

I would like to check if I understand it correctly now.

  1. If you would've used WebGL instead of OpenGL it did work in Webassembly right?

  2. With this library it only works if you compile it for that specific OS platform. So if I want to run it on Linux I have to use a Linux compiler, Windows a Windows compiler and Android/iOS "The GO Mobile" project?

Thanks in advance

@tfriedel6
Copy link
Owner

Sure thing.

  1. Yes, that would have worked. Although of course with Webassembly you have access to the 2D Canvas as well, so it could have used that directly. I used OpenGL here only because I didn't really see an alternative, and the whole reason I wanted this library was that I used the canvas a lot but preferred to use Go rather than JS

  2. The library is pure Go, but you will need to supply an OpenGL context. The code that does that will probably have to be compiled on the specific platform, just as you said. But I'm not sure, the go-sdl project for example seems to include precompiled libraries, so it may be possible to cross compile for all platforms using that. I must admit I'm not sure about this though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants