I'm in a situation where I already have a working, high-performance C++ program with GTK and OpenGL that renders data as a real-time graph. The data is saved as a report in a database which can be looked up at a later date from a browser. I now need to display those same graphs from the web-based reports (this wasn't in the original requirements).
I've tried generating the graphs from PHP, but drawing the whole thing with GD takes more than 20 seconds. I'm in the process of rewriting this in Javascript using canvas, which seems to be okay, although now I have to transfer all that data to the browser and parse it, which is still problematic.
But the real problem for me is that I'm actually writing the same program twice: in C++ with OpenGL and in Javascript with canvas.
I'm looking for general advice on how to "reuse" code between different platforms that support different languages, such as between a desktop environment and a web page. Are there tools that can help? Is there any way I can avoid maintaining two different codebases that do the same thing?
My ideas so far, none of which are particularly interesting:
Reuse the code. Find a way of to actually share the code, such as using a C++ program as a CGI. This won't work if the language isn't supported by the platform (such as in a browser).
Reuse the output: Write the program once, generate the output (such as an image) and make the other programs "viewers". This won't work if the output is too large to pass around.
Translate the code: Use some automated tool to translate from one language (or a meta-language) to another. If such a tool exists, I could use recommendations.
Reuse the bytecode: Use a language that compiles to bytecode that can run on various platforms. Apart from Java applets (which most people have disabled nowadays), I don't know of anything else that runs in browsers.
Develop my own universal language: Ain't nobody got time for that.