We have created an OpenGL application in C++ which visualizes some physical simulations. The basic application is contained within a DLL which is used by a simple GUI. It currently runs on a desktop PC, but we have the idea to turn it into a web service.
Since the simulations require dedicated hardware, the idea is that a user, through his/her browser can interact with our application as a service and this service then renders the result to an image (jpg or anything appropriate) that can then be displayed/updated in the browser.
My question:
How can I "easily" turn a c++ application as described into a web-service that runs on some server so that I can approach it over the web? What kind of technologies/APIs should I look at? And are there any real-life examples that tackle a similar problem?
This is possible, but one major difficulty you'll have is trying to use OpenGL from a web service. You'll need to port this to do 100% offscreen rendering and work without a windowing context. That would be my first step, and it's not always a trivial one.
Also, it is very difficult to maintain and manage your opengl contexts from a webservice correctly, and the overhead involved can be quite painful. Depending on the number and types of renderings, you may run into some issues there.
If you need it to scale up well CGI would probably be kind of slow & hacky.
There are some C++ web frameworks out there, see this question.
As far as the OpenGL goes, you'll probably need to use the frame buffer extension as Jay said.
You could then render your image to a texture, and use use glGetTexImage() to grab the pixel data. From there just save into what ever image format you want with the accompanying library.
I had a similar project/question, that although it wasn't a web service, it required OpenGL rendering in a windows service. I had tons of problems getting it to work on Vista, although eventually it did work on XP with regular OpenGL.
I finally tried using Mesa, which I built to work as a private DLL for my service. It was a great decision because I could now actually step into the OpenGL calls and see where things were going wrong. It ran fine in software mode under the service, and while it wasn't hardware accelerated, it worked very well.
If your user-interaction needs are simple, I'd just look at CGI. It should be pretty easy to understand.
As far as getting the output of the OpenGL program, I'd take a look at the framebuffer extension. That should make it easy for you to render into memory, which could then be fed into a JPEG compressor.
I guess you already have access to some webserver, e.g. Apache or similar. In that case you could try out CppServ.
You just need to configure your webserver so it can communicate with CppServ. I'd then propose that you develop a servlet (check the documentation on the site) which in turn communicates with your already existing dll. Since the dll knows everything about OpenGL it should be no problem to create jpeg images etc.
How about using something like Flex to create a web-enabled 'control interface', with a server backend that streams the opengl rendering as video? Basically, you are redirecting keyboard/mouse input via the Flex app, and using it to display 'realtime' 3D activity using a standard movie component.
The devil's in the details, of course....
You can try to use O3D API from google and don't do anysort of service, it would be much more simple.
This answer might sound very basic and elementary, have you tried this approach
Send the vector data from the server to the client or vice versa (just co-ordinates and so on)
Render it on the client side.
This means that the server is only doing the calculations and the numbers are passed to and fro.
I agree that is not a trivial method of trying to vectorize every object/model and texture, but is very fast since instead of heavy graphical images going across, only vector data is being sent across.
Related
Is it possible to write front-end of my application in QML and back-end in C++ and compile it somehow so that I can deploy it to a web-server like Apache or JBoss so that it is accessible from within a web browser ?
If yes, do you have any examples how to perform this ?
Thank you very much for your answers :)
I was trying to find an answer to my question on the Internet but I was not successful.
QmlWeb is a JavaScript library that is able to parse QML-code and create a website out of it using normal HTML/DOM elements and absolute positions within CSS, translating the QML properties into CSS properties.
QmlWeb is a small project started primarily by Lauri Paimen who developed it for a few years and is now a KDE project maintained by Anton Kreuzkamp.
QmlWeb of course doesn’t yet support everything Qt’s implementation of QML does, but it already supports a quite usable subset of it. It supports nearly all of the most basic QML syntax. Moreover it has support for HTML input elements (Button, TextInput, TextArea are currently supported, more to come).
Well, QmlWeb is not finished. I hope Digia help with this project to make it ready with mature features.
The javascript currently sits on top of v8 but serves the purpose of expressing complex bindings and some (preferably small) client logic. But the engine could change (http://blog.qt.digia.com/blog/2013/04/15/evolution-of-the-qml-engine-part-1/).
Like in a browser, the actual graphics are kind of orthogonal to javascript which can only interact (or instantiate) with already existing graphical objects. In a browser, the graphics are described by html/css/svg/dom, and interpreted by the web engine written in C++. In QtQuick, the graphics are written in Qml and interpreted by the qml engine (scengraph) written in C++.
The two stacks are completely different.
Exception made of the Html canvas and the Qml canvas (which almost share the same api). But those are graphics working in immediate mode (opposed to a SVG or Qml scenegraph, working in a Retained mode fashion).
That being said...
There are 3 attempts to port Qml to the web:
A Qt port to Google Nacl (never heard of it from a long time, most likely dead)
Qt port through Emscripten/asm.js (awesome project, but not viable for production, and I don't think QtQuick is even supported... might require a huge effort to be actively maintained)
QmlWeb (Javascript apis to translate Qml files and interpret those on top of the HTML5 stack). Work in progress and only a subset of the whole QtQuick ecosystem might be supported in the long term. But still a really interesting project and maybe the most promising of all three. At least, it is the youngest one, and it might get some traction from the KDE community. http://akreuzkamp.de/2013/07/10/webapps-written-in-qml-not-far-from-reality-anymore/
You might also be interested in other scenegraphs technologies sitting on top of the web stack (amino, cake.js, rapahel.js...).
Last but not least, you might be interested by Wt (http://www.webtoolkit.eu/wt).
No. You cannot compile QML, and in any form it cannot be deployed onto a Java Application server such as JBoss. Qml is strictly for creating applications to run on a local machine. It sounds like you want to build a Web Application out of HTML with some sort of backend like .Net.
I want to create an web application through which i have to access tools like Gimp for my image processing. Is it possible to manage my need with client-server (Gimp at server) approach?
I am not restricting with the Gimp,however i prefer any opensource with basic functionality(zoom out/in,selection tool, cropping tool, transparent tool etc).
Sorry if the question is so wage as i am not much familiar with these kind of architectures.
And i hope this(stackoverflow) is the platform to get help from people.
There are several ways of doing image processing in the server of a web application.
One approach would be to invoke a tool through command-line (I think that is what you are trying to do with gimp).
Second approach would be to use a image manipulation library in the language you are using for developing the application. (Sometimes I did this with Java)
Use a combination of the above depending on the kind of manipulation you wish.
But with today browser capabilities, some processing can be done using HTML5 (canvas) + Javascript in the client itself. For instance you can use something like this for cropping:
http://www.webresourcesdepot.com/jquery-image-crop-plugin-jcrop/
Or something like this for image maniplation in Javascript:
http://pixastic.com/
So, there are plenty of choices. There is no a better approach, it all depends on the kind of processings, the size of the images, the hardware you have, etc.
Wish it helps...
There is some libraries that lets you run C++. So, it is it possible to run a game that uses directx full mode screen?
Google is developing a tool to allow this kind of thing via Chrome. It is called Chrome Native Client, or NACL for short. http://blog.chromium.org/2010/05/sneak-peek-at-native-client-sdk.html
In general, no. Most online games are written with Javascript, Flash, the newly hatchedd HTML5 and similar technologies. Perhaps C++ integration is possible on some level, but you definitely cannot write a browser-hosted game purely and entirely in C++.
it could also be done with an ActiveX control. ActiveX only works in IE. there are Netscape plugins that work in other browsers. so make a solution that contains both. you need a book on ActiveX/COM/OLE. Better yet, take a class if you can find one, you will learn far more, because COM is not an easy subject to just read about and then really do - versioning is a big problem.
nope, not supported in firefox. but read this: http://www.google.com/chrome/intl/en/webmasters-faq.html#activex
some people may have activex controls disabled. if this is the case, your game will not run. you will have to tell the user that they will need to change their security settings in IE. you can get feedback from the object element in javascript as to whether or not the activex loaded. there is code out there for that.
http://msdn.microsoft.com/en-us/library/7sw4ddf8%28v=vs.85%29.aspx
examples are all over the internet.
I am curious to know if there is a way of connecting a flash front-end to a C++ driven backend? I'm not currently working on a project that involves this, but I found out about an application used in the gaming industry, called Scaleform, that requires knowledge on doing such things in order to create menus in games.
Another way to resolve the problem would be to create webservices using C++ and consume them on the flash side. It is a more naive approach and certainly not as good as Scaleform but it is certainly simpler to implement.
You could also have a look at FluorineFx which is an implementation of Flex/Flash Remoting services for the .NET framework. The project is open-source so it could help you get started. Basically, FluorinexFx catches the remote calls in AMF from the flash player and pipes it through the corresponding .NET method and corresponding arguments. It also helps you convert back to flash native .Net objects such as ArrayList, DataTable and even lists of typed objects.
Scaleform implement their own custom Flash Player, thats probably not what you had in mind.
What you can do in a reasonable amount of time is pretending to Adobes flash player that you are a NPAPI-compatible browser - see e.g. here how screenweaver-hx does it.
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.