How can you embed a C ++ game in a web page?

Without recoding to flash or turning it into a Java applet! Saving it as a C ++ application, is there any way to insert it into a web page so that website visitors can play the game?

We can assume that this is a small game, the size of your average flash game or even thinner.

The game in question was written in the Allegro library with 1000 lines of code.

Is it possible?

+4
source share
4 answers

The quick answer is: no, you cannot.

C ++ applications cannot be embedded in a web page, they must be downloaded, and the user must run them on the client machine.

Details: it is somehow possible, but it is absolutely not portable in browsers . For example, Internet Explorer has ActiveX components (they can be a C ++ application, it will be downloaded, installed and launched on a web page). Other browsers have another mechanism to achieve this (e.g. Chrome has a Native Client ), but you cannot write something really portable, and you will have many limitations that you will use.

+5
source

Try the emscripten project, it is a C ++ compiler based on LLVM Clang and compiles C ++ files into JS files, which can then be run in a browser.

#include <iostream> int main() { using namespace std; cout << "Hello World" << endl; return 0; } 

Assuming you saved this in helloWorld.cpp , use this after installing Emscripten.

 $ emcc helloWorld.cpp -o helloWorld.html 

You are done, open helloWorld.html now in your browser and see for yourself. The good thing about Emscripten is that it supports a wide range of desktop libraries, including SDL, etc.,

http://kripken.imtqy.com/emscripten-site/

+2
source

This is only possible as a plug-in for the Google Chrome browser as a native extension.

0
source

Source: https://habr.com/ru/post/1411474/


All Articles