views:

605

answers:

8

My client wants her website to have an application that renders 3D (light 3D stuff, we are drawing only flat squares in 3D world) but web programming is not my thing. So I am looking for something that can run a C++ program from a web browser. But I think, if this is the case, then the client side must download the program first, and that's not what I want. The client should only be able to use this application only on the website.

I came across Google Native Client, which claims that it can run x86 native code in web applications. I haven't decide whether it is worth it or not and I don't know whether this is what I want or not, so I decided to ask experienced people about this.

If I want to have something like this, is what I said above possible? Or I completely need other languages like Flex because it does not worth the trouble? Or is Google Native Client suitable for doing something like this?

+3  A: 

Your only stable bet to display C++ in the browser is to make the user download an plug-in.

Otherwise you could look at a Javascript solution instead, maybe O3D could be what you're looking for?

Silfverstrom
O3D looks tempting. Let me give it a try.
unknownthreat
+1  A: 

The only thing that can "run" inside a browser is an ActiveX control. So no matter what way you go (a COM object written in C++, a Silverlight app, even a Flash program), they all have to be hosted inside a downloadable ActiveX. So if the requirement is that you must not download anything, you're out of luck.

Now this being said, Flash is pretty much available everywhere and I'm fairly certain it can do what you want, and Silverlight, while not quite as popular yet, is tailor made for this sort of thing, and is rapidly gaining acceptance in the web programming world. You could get away with using either of them.

Blindy
really? i can run activeX in Firefox and Google chrome? Cause IE sure ain't a browser, more like a dedicated virus delivery platform.
Tim
Firefox, Chrome, et. al., support the NPAPI framework. Firefox (and other Gecko-based browsers) support XPCOM-based plugins. Only IE supports ActiveX.
greyfade
but you get the idea, you still have to download SOMETHING, regardless of what you call it.
Blindy
+1  A: 

A Java applet may also be an option. Might be easier to convert your code to Java, since it has similar syntax to C++, and the Java3D API may prove very useful. Apparently it's quite easy to use, although I haven't worked with it myself. The Java3D.org website is a good place to start.

Most people have Java and Flash already installed, so both are fairly safe.

Java Applet? I'm not sure. I have a feeling that I no longer see Java Applet these days. I see Flash, Flex, and such. Are Java Applets still around?
unknownthreat
Yea, depending on the context. Processing vs. looks. You probably wouldn't use Java if you just wanted a shiny button, or a media player. You probably wouldn't use Flash if you want something with more intense code, like a 3D simulation or a fractals calculator. One of the more recent things with Java is WebStart, which basically allows the Java program to be installed via web onto the host computer (although this is probably beyond your needs). Two major recent Java programs are Geogebra (geometry/drawing, popular educational tool) and Centra (web conferencing, presentations and classrooms).
+1  A: 

Google's NativeClient framework supports what you want to do. It's a plugin that users will have to install, but it runs a sandboxed C++ application as if it were a browser plugin. It seems to be exactly what you're looking for.

As others have pointed out, your other options are a Silverlight applet, a Flash applet, a Java applet, the HTML5 Canvas tag, or an actual plugin (ActiveX for IE, NPAPI for all other browsers).

greyfade
A: 

No, NativeClient is not what you want. It won't let you run SDL+OpenGL -- it may be C++ code, but it's run inside a sandbox.

Running SDL in a browser is difficult in general. OpenGL somewhat less so, but it's no cakewalk either. Any such native code solution is difficult if you want it to work across browsers and platforms -- you'll have to develop NPAPI plugins for multiple platforms (which will all be fairly different), as well as an ActiveX control. You are looking at four separate projects.

Almost assuredly, the correct answer here is to use Flash in one form or another.

aaa
A: 

If you decide to go the plugin route, FireBreath is a project that lets you create a plugin (that you could do rendering from) that will compile to be both an NPAPI plugin (firefox, google chrome, apple safari) and an ActiveX control (IE)

Taxilian
A: 

You could also take a look at OSAKit. It's a set of browser plugins plus a set of tools to wrap an existing native executable into a package that the plugin can run inside the browser. The wrapping process is really easy, can be done in 5 minutes. The whole thing looks a bit unprofessional, but actually works. (I'm not sure about security though, and this may be a concern for your client.)

imre
A: 

Ricardo Cabello has done a Javascript 3d software-rendering engine called three.js. It's a good fit for you because you only require lightweight graphics, and Javascript lacks some Flash problems (like focus-stealing, slow loading and nasty context menus).

Unfortunately there doesn't seem to be any documentation. There are examples and demos though.

One of the demos: here

Stefan Monov