<p>I am trying to implement Web/HTML5 target for my library here <a href="https://github.com/gen2brain/raylib-go" rel="nofollow">https://github.com/gen2brain/raylib-go</a> , original C library supports emscripten.</p>
<p>For now i have this:</p>
<p><code>go generate -tags js github.com/gen2brain/raylib-go/raylib</code> will generate <code>raylib.js</code> file (emcc from emscripten must be in PATH).</p>
<p>Then, I have implemented bindings for <code>raylib.js</code> in GopherJS here <a href="https://github.com/gen2brain/raylib-go/blob/master/raylib/raylib_js.go" rel="nofollow">https://github.com/gen2brain/raylib-go/blob/master/raylib/raylib_js.go</a> .</p>
<p><code>gopherjs build</code> is then used to build project example or game to js. After that, <a href="https://github.com/gen2brain/raylib-go/blob/master/raylib/external/web/index.html" rel="nofollow">https://github.com/gen2brain/raylib-go/blob/master/raylib/external/web/index.html</a> should be edited to include that js file.</p>
<p>If I open that index.html in browser, I can see that InitWindow() works, OpenGL ES is active, etc. but per emscripten docs <a href="https://kripken.github.io/emscripten-site/docs/api_reference/emscripten.h.html#c.emscripten_set_main_loop" rel="nofollow">https://kripken.github.io/emscripten-site/docs/api_reference/emscripten.h.html#c.emscripten_set_main_loop</a>, I need to set update()/mainloop() function there and use that in app, raylib also does that, but in C code (and includes emscripten.h).</p>
<p>Now, I add with generate script this at the end of raylib.js (with emcc --post-js option):</p>
<pre><code>function _emscripten_set_main_loop_go(fps, simulateInfiniteLoop) {
if (_go_update_function !== undefined && typeof _go_update_function == 'function') {
_emscripten_set_main_loop(_go_update_function, fps, simulateInfiniteLoop);
}
}
Module["_emscripten_set_main_loop_go"] = _emscripten_set_main_loop_go;
</code></pre>
<p>And then I use it in Go like this:</p>
<pre><code>func SetMainLoop(fn func(), fps int, infinite bool) {
js.Global.Set("_go_update_function", fn)
js.Global.Get("Module").Call("_emscripten_set_main_loop_go", fps, infinite)
}
</code></pre>
<p>This results in error <code>Invalid function pointer called with signature 'v'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)?</code></p>
<p>I guess it doesn't pass properly Go function, but I am kinda lost here who passes what and to whom. Any help and/or pointers are much appreciated.</p>
<p>Error details are here <a href="https://github.com/gen2brain/raylib-go/issues/28" rel="nofollow">https://github.com/gen2brain/raylib-go/issues/28</a> .</p>
<p>Edit: demo is here <a href="http://81.4.106.254/raylib-go/" rel="nofollow">http://81.4.106.254/raylib-go/</a> , .js files are not optimized/compressed/obfuscated . </p>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传