temporary_user_name
temporary_user_name

Reputation: 37058

How can you embed a C++ game into a webpage?

Without recoding in flash or making it into a java applet! Keeping it as a C++ app, is there a way to embed it into a web page so site visitors can play the game?

We can assume it's a small game, the size of your average flash game or even thinner.

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

Is it possible?

Upvotes: 4

Views: 7380

Answers (4)

Sri Harsha Chilakapati
Sri Harsha Chilakapati

Reputation: 11940

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 the browser.

#include <iostream>

int main()
{
    using namespace std;

    cout << "Hello World" << endl;
    return 0;
}

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

$ emcc helloWorld.cpp -o helloWorld.html

You will be 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.github.io/emscripten-site/

Upvotes: 3

Adriano Repetti
Adriano Repetti

Reputation: 67090

Quick answer: no you can't.

C++ applications cannot be embedded inside a web page, they need to be downloaded and the user has to run them on the client machine.

Details: it's somehow possible but it's absolutely not portable across browsers. For example Internet Explorer has ActiveX components (they can be a C++ application, it'll be downloaded, installed and will run inside the web-page). Other browsers have different mechanism to achieve this (Chrome has its Native Client, for example) but you can't write something really portable and you'll have many limitations whatever you'll use.

Upvotes: 5

Denis Ermolin
Denis Ermolin

Reputation: 5546

It's possible only as plugin for Google Chrome browser as native extension.

Upvotes: 0

Related Questions