Best way to port c++ game to web [closed]

允我心安 提交于 2021-02-16 04:02:55

问题


I realize the above question is rather broad so I will narrow it down. I have a simple opengl c++ game engine that lives in a static library (could be converted to a dynamic lib).

I have been thinking of ways of getting it to run in web. From what I can see I could use ActiveX or Google NaCl to run the c++ code in browser. But these technologies do not seem easily cross platform? Or maybe I have misunderstood.

Another option I have seen is converting the engine to javascript and WebGL and running in an HTML5 canvas. Would this be slower than c++? It would be very cross platform though.

What do you think is the best option, or better yet is there any other option I have missed?

EDIT: what about a custom plugin similar to the unity webplayer?


回答1:


There is a library created by @kripken which is still under development. It takes LLVM bitcode and convert into Javascript.

You can see the project page here, with working examples. https://github.com/kripken/emscripten/




回答2:


I would strongly suggest porting to NaCl.

Advantages:

  1. Performance: You can use the full power of the CPU to render your game. If your game uses good 3d graphics or physics, you can make it look smooth even on old system configs. The performance of NaCl is comparable to Native OS applications, it only looses nearly 5 to 10% of FPS when I compared the same game to Win32 version.
  2. There are a lot of already ported examples, games for NaCl that can help you do it easily.
  3. It is already cross-platform. Chrome runs on Windows, Linux, Mac OSX.

Disadvantages:

  1. Might take you around a week to port. You have to port to OpenGL ES 2.0 (However, it should be the same with any browser based methods, especially HTML5)
  2. Runs only on Chrome.



回答3:


If you want something portable in a browser, then it has to rely on Javascript (and likely WebGL, although IE does not support that).

ActiveX and NaCL are just not portable in any way, shape or form.

I can't say which is easier, but you have an option of rewriting your game in Javascript, or using a tool like Emscripten to compile your C++ to JavaScript.

Note that if you use the latter, it's still not a silver bullet. You'll likely have to make lots of changes to your code (for example because the libraries and APIs used in your C++ game won't be available on the browser)



来源:https://stackoverflow.com/questions/11683521/best-way-to-port-c-game-to-web

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!