Porting my C++ app to run in a browser - c++

Is there an easy way to port a C++ OpenGL app to a browser? It's already ported to PC, Mac and iOS. If there is some relatively easy way, would that be portable between computer browsers? I would have to use different binaries for different platforms, of course. I remember hearing something about some sandboxed environment for Chrome some time ago, but that would exclude the other browsers. How did they (id?) do with Quake in the browser?

If you're already targeting ES 2.0 for iOS your shaders should work as-is with WebGL. JavaScript ahoy!
id Software uses a giant plugin for Quake Live.

Try Google's Native Client or NaCl, if you want a lazy port.
But if you want to do a real port - refer to those two examples:
blog series about porting existing C++ game to html5 (sponsored by Opera)
short article about porting existing Objective-C game to html5 (sponsored by Microsoft).
sad example of porting popular copyrighted game from C to JavaScript (sponsored by Mozilla, with extra help of Zenimax)
If you was asking about QuakeLive - that is a custom plugin, made by Id Software. Similar functionality can be achieved with Flash or Unity plugins.

You can use Mandreel if you want the least amount of work. Another option is Emscripten but that only converts your C++, it doesn't provide all the APIs like Mandreel does.

Is there an easy way to port a C++ OpenGL app to a browser? It's already ported to PC, Mac and iOS. If there is some relatively easy way, would that be portable between computer browsers?
You could try to recompile it into JavaScript, that's what browsers execute. If you don't expect the user to install some browser plugin, you can't give them native code. Of course when in a JavaScript environment many of the things you're accustomed from native executables don't work. For examples you no longer can access a file system. You must use either DOM storage, cookies, download/upload resources from a server.

Related

It is possible to just use QT and WebAssembly (instead of HTML + CSS + JavaScript) to develop a front-end web?

I am a C++ programmer, but for some reason, I have to develop a website by myself(My own commercial project). I don't want to take a lot of time to study JavaScript and something else. It is possible to just use QT and WebAssembly (instead of HTML + CSS + JavaScript) to develop a front-end web?
Yes, it's absolutely possible and I'm currently doing it for a project but you should do it carefully based on the project requirements, running environment and your own backgrounds.
Here are some problems you may encounter:
The output .wasm file may get too large. Generally, it won't be suitable for public domain applications.
In low-end devices, maybe you find it laggy if you don't do enough code level optimizations.
Threads are not officially supported yet (as of Dec. 2019) by major browsers but tech-preview is available. This is not a real big problem as it would be a standard feature soon.
Native virtual keyboard won't work on mobile devices but the work is in progress.
These were my own major problems with Qt for WebAssembly.
Despite this, I find it much more flexible than HTML+CSS. QML is really a nice language for UI development. Creating animated UIs is quite easy and straight-forward.
You can also use many JavaScript libraries in your QML code like Lodash and Moment or any other js library that does not refer or manipulate window DOM.
Yes, it is possible. But you should do not do it if only reason is reject for learning new technologies.
For now (I'am writing this answer when Qt 5.14 is present) Qt for webassembly is deployed as official platform. Unfortunately it is young platform support with a lot of problems and possible future changes. Qt team do really good job so next version will be better. 5.14 is much better than 5.13 in webassembly context but still need fixes.
You should know Qt for webassembly will support only a few Qt modules, excluding widget. Yes, you can only use QML for GUI.
Qt for webassembly was created for the purpose of port one code base in other platform (it it generally Qt develop way, please see Qt for MCU). With other technologies in this stack like QRemoteObject is very interesting technologies. It was not created for websites in normal network. Main Qt for webassembly target are internal network systems and remote control of devices. Pay attention about this.
Unfortunately, not all browser will support webassembly right. Please see Qt for weassembly support notes.
Additional, in Qt you can't find build-in rest-API handle or other standard web technologies to integrate with your existing backed.

Is packaged apps preferable over C++ for creating a cross-platform serial read/write application to communicate with my mbed electronics project?

I would like to create a cross-platform serial read/write application to communicate with my mbed electronics project. I cannot decide whether to code this application in Chrome packed app or c++(using the openFrameworks framework). I have more experience coding in html and javascript than I do in c++, but I wouldn't mind learning c++. What drew me to the packed app idea was the ability to write code in html and javascript. Eventually my project will be open-sourced. What are some of the pros and cons of using packaged apps versus c++?
C++ can be used to do chip level programming and to manipulate the chips that require lot of coding in order to implement the functionality of your desire.
Packaged apps deliver an experience as capable as a native app, but as safe as a web page. Just like web apps, packaged apps are written in HTML5, JavaScript, and CSS. But packaged apps look and behave like native apps, and they have native-like capabilities that are much more powerful than those available to web apps.
Packaged apps would be a modern concept and it would be a better option because it gives more importance to your project when the reviewers of your project find that you are using a new concept.
I'm working-on in one app that I need for setting-up embedded devices, the app must be cross plattform because it will be used in Windows, OSX and Linux.
I'm developing it in java using RXTX library that is tested and work fine in the three plattforms.

Cross browser extension development in C++

I am starting to work on a browser extension and because of the nature of the extension I need to develop it in C++. I am currently working with Firefox but would like my code to be portable across browsers. First of all is there a library or an interface (like the NPAPI) that I can use to ensure this for extensions? What are the things I need to worry about?
I am not using XPCOM and instead writing the functionality in C++ so that I can just compile the library for each platform and can bundle it with the extension for each browser. For Firefox, I am using XUL to develop the JS wrapper for my extension and an IDL file generates the c++ interface for me. Can I do something better? I just want to make sure I am not going down the wrong path.
EDIT: Please also suggest if there is a better forum for this type of question.
My background: a few years back, I worked on a cross-platform, cross-browser NPAPI plugin that used OpenGL to do image rendering. I've paid some attention to the space since then, but it's not what I do nowadays. I've written non-plugin extensions for Firefox but not Safari or Chrome.
A lot depends on exactly what you want your extension to do, and what sort of user interface you want to present. Different browsers have different ideas of what extensions may and may not do.
If you just wanted to display images or video in a custom format, NPAPI is probably your best bet. NPAPI is fundamentally a thin wrapper around native platform APIs. As such, cross-platform NPAPI code has to deal with individual platform quirks, as well as different levels of support for NPAPI from browsers. Google has a project called Pepper to fix some of NPAPI's issues, but Pepper doesn't yet have support from any browser besides Chrome.
Google's Native Client project provides an alternative to NPAPI for running native code, but it imposes restrictions on native code. For example, pthreads are allowed, but network access isn't. There is a NaCL subproject called c_salt which appears to address the sort of HTML/JS UI + native code integration you seek. Unfortunately it's still in the design phase, and thus isn't terribly helpful for writing extensions today.
My understanding is that, for now, a cross-browser extension which integrates with the browser UI and also integrates with native code is not feasible. Safari and Chrome both restrict extensions much more than Firefox does, and only allow extensions written in JavaScript. I don't know if it's possible to have an extension in Safari or Chrome interact with a browser plugin written in NPAPI. I'm guessing it's either impossible or incredibly painful.
Overall, you'll find life much, much easier if you carefully restrict which browsers and platforms to target. Exactly which browsers and platforms to choose is something that only you can decide.
Not many know about it, but yes, you can write cross browser plugins using Qt. :-)
You can use the QtBrowserPlugin just for that.
The QtBrowserPlugin solution makes it
easy to write browser plugins that can
be used in Mozilla FireFox, Safari,
Opera, Google Chrome, QtWebKit and any
other web browser that supports the
"Netscape Plugin API", NPAPI.
QtBrowserPlugin is part of the Qt Solutions packages.

Can I make a rather native C++ app with Android?

I'm interested in the following features:
Writing an app for Android Market that is written completely in C++ (a port of existing product actually).
Use fast screen-buffer pixel pushing (or rather using OpenGL ES for this).
Grab user input and direct it to C++ code.
Is it legal to write such an app for Market? Is Market policy somehow strict to such things?
As of NDK r5 with Android 2.3 (Gingerbread) this is possible, although I assume only devices to support natives apps must have Gingerbread on them.
From the native-activity sample:
The Android SDK provides a helper class, NativeActivity, that allows you to write a completely
native activity. With a native activity, it is possible to write a completely native application.
NativeActivity handles the communication between the Android framework and your
native code, so you do not have to subclass it or call its methods. All you need to do is declare
your application to be native in your AndroidManifest.xml file and begin creating your native
application.
It is really not my cup of tea but there is something called Android NDK (Native Development Kit) to use if you want to write your program in C. Not sure how the C++ compiler support is though.
As far as I know your app can be almost 100% native code but keep in mind that by walking that way you will probably have a hard time supporting the different CPUs out there in Android hardware. If you need to bootstrap the native code so that it is started from java it is probably not a very big problem for you.
I found a few different tutorials when googling for "Android NDK". This one is a very minimalistic Hello World. Obviously you want something much more than a library that returns a string to java but it is a good first start and you will probably have to do all of the things described. Do a search using NDK and Android as keywords and you get a good selection. I see no reason to list them here as such lists tends to be outdated and broken within a year or so.
I guess the official Android Developer site from Google will stay put and be updated on new releases of the platform, it has a link to the current NDK.
With Gingerbread (Android 2.3) it looks like you can build your entire app in C++.
cf:
http://phandroid.com/2011/01/11/android-developers-blog-awesome-ndk-leads-to-awesome-apps/
"
With the latest version of the NDK, r5, many big improvements have been made to coincide with the release of Gingerbread. The most major is the ability to code a native application for Android 2.3 entirely in C++. This means even programmers and developers with no Java knowledge won’t have to implement a single line of that code..."
Can't vouch for the veracity of this blogger, however, from what I have read, it appears you can do this
There is no 100% native solution but what I think you are looking for is the Android NDK (Native Development Kit)
From their site "Please note that the NDK does not enable you to develop native-only applications. Android's primary runtime remains the Dalvik virtual machine."
I believe it lets you make calls to your own native code from an Android application
I have personally never used it for my games, but I am sure it would help on a lot of things (like being able to manage my own memory and not have "lag" do to the garbage collector)
conversations in this thread can help you.
http://groups.google.com/group/android-ndk/browse_thread/thread/50362904ae0574cf
essence is,
It is possible to make Native only apps and Android Market doesn't restrict you either.
But with limited support for native development, there is high chance of using some of the non standard functionality which might break in future releases.
http://developer.android.com/guide/basics/what-is-android.html
"The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language."
http://arstechnica.com/open-source/news/2009/06/android-goes-beyond-java-gains-native-cc-dev-kit.ars
In general, you don't. There is some limited C++ support through JNI, but it is mostly intended to supplement Java code, not replace it. There's no framework/API support (AFAIK) for C++, so doing this isn't really an option.

What is the best approach to use openGL in the web?

I wrote a program in C++/OpenGL (using Dev-C++ compiler) for my calculus 2 class. The teacher liked the program and he requested me to somehow put it online so that instead of downloading the .exe I can just run it on the web browser. Kinda like java applets run on the browser.
The question is:
How if possible, can I display a C++/OpenGL program in a web browser?
I am thinking of moving to JOGL which is a java interpretation of OpenGL but I rather stay in C++ since I am more familiar with it.
Also is there any other better and easier 3D web base API that I can consider?
There is a lot activity recently with WebGL. It is a binding for Javascript to native OpenGL ES 2.0 implementations, designed as an extension of the canvas HTML5 element.
It is supported by the nightly builds of Firefox, Safari, Chrome and Opera.
Have a look at these tutorials, based on the well known NeHe OpenGL tutorials.
Several projects based on WebGL are emerging, most notably Scenegraphs APIs.
From Indie teams: SceneJS, GLGE, SpiderGL.
From Google: the team behind O3D plugin is trying to implement a pure WebGL backend (source) for the project, so that no plugin will be necessary.
From W3C/Web3D: There is an ongoing discussion to include X3D as part of any HTML5 DOM tree, much like SVG in HTML4. The X3DOM project was born last year to support this idea. Now it is using WebGL as its render backend, and is version 1.0 since March 2010.
I'm almost sure that WebGL is the way to go in the near future. Mozilla/Google/Apple/Opera are promoting it, and if the technology works and there is sufficient customer/developer demand, maybe Microsoft will implement it on IE (let's hope that there will be no "WebDX"!).
AFAIK, there's only 3 options:
Java. it includes the whole OpenGL stack.
Google's Native Client (NaCL), essentially it's a plugin that let's you run executable x86 code. Just compile it and call it from HTML. Highly experimental, and nobody will have it already installed. Not sure if it gives you access to OpenGL libraries.
Canvas:3D. Another very experimental project. This is an accelerated 3D API accessible from JavaScript. AFAICT, it's only on experimental builds of Firefox.
I'd go for Java, if at all.
OTOH, if it's mostly vectorial works (without lots of textures and illumination/shadows), you might make it work on SVG simply by projecting your vectors from 3D to 2D. In that case, you can achieve cross-browser compatibility using SVGWeb, it's a simple JavaScript library that allows you to transparently use either the browser's native SVG support or a Flash-based SVG renderer.
Do you really have the time to rewrite it? I thought students were meant to be too busy for non-essential assignment work.
But if you really want to do it, perhaps a preview of it running as a flash movie is the easiest way. Then it's just a matter of doing that and you could provide a download link to the real application if people are interested.
Outside of Java, in-browser OpenGL is really in its infancy. Google's launched a really cool API and plugin for it though. It's called O3D:
http://code.google.com/apis/o3d/
Article about the overall initiative:
http://www.macworld.com/article/142079/2009/08/webgl.html
It's not OpenGL, but the Web3D Consortium's X3D specification may be of interest.
Another solution is to use Emscripten (a source-to-source compiler).
Emscripten supports C/C++ and OpenGL and will translate the source into html/JavaScript.
To use Emscripten you will need to use SDL as a platform abstraction layer (for getting an OpenGL context as well as loading images).
Emscripten is currently being used in Unreal Engine and will also be used in the Unity 5 engine.
Read more about the project here:
https://github.com/kripken/emscripten
Two approaches:
Switch to Java. However, your application will suffer from a loss of performance as a trade off for portability. But since Java is everywhere, this approach ensures that your code can be executed in most browsers.
Use ActiveX, which allows you to run native binary code for Microsoft Windows. This is not recommended in production because activeX is well known as a potential security hole, but since your lecturer is the one viewing it, security doesn't seem to be a big deal. This is applicable for Microsoft platform (Windows+IE) only.