C++ games in browser | Sololearn: Learn to code for FREE!


C++ games in browser

How can I put my c++ games made with sfml library on a website to be playable directly in browser?

4/23/2021 5:46:02 PM

David Dolejsi

20 Answers

New Answer


I can see from your profile that you have completed a large number of courses, congratulations. You may wish to take a look at the Phaser game engine which uses web technologies. https://phaser.io/ Another option is to use a game development system such as CopperCube which targets desktop systems, Android, and browsers. https://www.ambiera.com/coppercube/index.html


You can't, as far as I'm aware. The only way is to use a compiler like emscripten that converts c++ into javascript.


Cryphean If I'm correct, one can make browser games using C++. You can use web assembly.


SFML will not work in a browser. You will need to use WebGL in a browser.


David Dolejší, CopperCube is not as capable as Unity or other heavyweight engines but it is still a capable engine, and uses JavaScript as it's scripting language. It provides a good introduction to using a 3D game engine without overwhelming new developers with too much work and information. If or when you outgrow it you can always switch to a different game engine. A lot of the development skills you learn will carry over to the new engine.


the reverse is quite possible https://duktape.org/ things like duktape allows you to run a javascript code string inside C++. but the problem to do what you want is that C++ is a compiled language, and js/html is served over a http request. the C++ code cannot be compiled on the client side. however, some C++ functions could be transpiled server side and served as webassembly to be executed by the client. but... even if that is possible, the complete sfml library is a lot of functions to compile and is also dependent on the system being used, like it might need X11 to run which the web browser cannot deal with. .... a parallel to this situation: I recently tried Rcpp on my computer which allows to run C++ code inside R interpreter. it works. you define C++ function inside an R script and somehow that function gets compiled to later be executed from an R script. the caveat is that it takes time to compile but then the execution is faster than what R can offer. the interpreter and compiler are on same machine


I found Godot is great option which allows me to export games also into html5 too


🌀 Shail Murtaza شعیل مرتضیٰ yes true. But it's not C++ anymore, instead, as I said, converted binary code from a compiler like enscripten.


Mehran actually I changed my mind, I probably learn WEBGL instead of sfml


Martin Taylor I am recently posting games on sololearn in vanilla js, but I started with c++ and found this amazing library, Btw I never used any game libraries, cause html canvas is enough, but I saw games made in unity playable in browser so I thought this could be possible too... Okay thanks for answers, I check the coppercube, it looks interesting


Use. " iframe"


I've heard that c++ code can be converted to WebAssembly code, but I don't think it's possible to do that with sfml.


David Dolejší You can write your code in c++ then compile it it wasm code which you can attach to the html file to work.


David Dolejší I have used godot game engine. It's simple, easy to use and good game engine. Your Web Game will be exported in Web Assembly. You can export your game for android, windows, linux and other platforms using Godot which really is great. It has not many features as compared to game engines like unity and unreal. That's why it is very light weight too.


🌀 Shail Murtaza شعیل مرتضیٰ I prefer light weight, as I did everything in pure javascript, so thanks for explaining, I see Godot is really something for me


can you show where to get it?


David Dolejší here: https://emscripten.org But as Martin Taylor already mentioned, SFLM cannot be converted into the web, so this will probably not be useful for you.


Shardul Narawade but still how can I upload the game on another website


David Dolejší Yes, webgl is the main way to do this.


The old way was with ActiveX, and you can always create a new browser that runs C flavored code with interpretation, or compiled binaries. A good argument is file sizes and reduced requests. Can you elaborate on the project?