WEBGL Game; things started in C++

Started by
9 comments, last by trowtlip 10 years, 1 month ago

I posted two questions almost exactly two years ago, and have since done a bit of work on game logic and database interaction with C++ and mysql. I have python in there as well and I repeat some of the functionality with it, but for what I am doing, C++ seems ok and magnitudes faster than messing with data in PHP. Additionally and since two years has passed, I'm happy that I have chosen languages (C++, Python) that are stable and not here today, gone/forked/changed tomorrow.

I'm no expert in C++ or Python yet, but things are coming along and I want to start spitting out something visual. I'm seeing WEBGL as something viable, but I'm not sure how C++ fits, aside from a long chain of interpreters/compilers/converters - which sounds terribly messy and vulnerable to obsolescence as my development slowly chunks along year after year.

Language really doesn't matter at this point, as I'm not invested very heavily into anything library specific; I just don't to go back to PHP. I can do Python, would prefer C++ and understand JS is required, but I will compromise if the chain to WEBGL/JS is short.

I work on a remote VPS Debian/Ubuntu build, if that is any help in commenting. So I'm either going to start serving up web pages (the plan) or I need to start working on a client (huge downer, with added complication network-wise).

Any advice on moving forward?

Thank you!

Advertisement

I'm a little confused. You mention doing programming with C++ and want to create something visual; do you mean 2D or 3D game?

You can use WebGL for that, but you'll have to create everything using Javascript, C++ has no place there.

However if you wish to use C++ with graphics then you need to look into OpenGL or DirectX. There's also SFML and other options but internally they use OpenGL or DirectX.

3D.

I have read of some options, which kind of get's me to this post. I learned about asm.js which will take C++ and make a sort of complied JS that works for WEBGL. Though further reading, adds further middle steps to truly make it work.

OpenGL, SFML.. Are these becoming web technologies so-to-speak?

Sounds like I'll still be stuck with client/server solution instead of a web interface. And realistically, I could spend many months moving onto network/multiplayer stuff, so I guess I still don't need anything visual. Would be nice though - maybe flesh out some of the creative concpts.

Thanks for your reply!

Just so you understand...WebGL is not c++...it is JavaScript and GLSL with calls to OpenGL ES2 running in an HTML5 canvas. If you are going to code CPP then use full OpenGL.

OpenGL ES2 has a reduced feature set targeted at lower end hardware. It it designed to run in a browser which means you have to pander to people with crappy hardware and all resources have to be loaded asynchronously (ex. textures, 3d models, shader files). It is not designed to compete with full OpenGL on performance or quality. However...it works on most peoples machines...portability is it's strength. Does that clear anything up for you?

I'd like the browser to be my entry point. I'd like something other than JS or PHP be handle backend work, and with my VPS configured how I choose, it seems I could come up with something better than just JS. Couldn't I have C++ handle the database and backend work, with the interface in WEBGL?

Right now, I just want to place some objects in 3D space that I can assign data to, interact with and provide feedback through the WEBGL interface. I don't really want to deal with a client per say right now. It's a matter of convenience I suppose; I can write code through SSH as opposed to setting up a dev environment on every computer I may be at, so I can develop client. I'm figuring WEBGL in a webpage allows essentially an instant client wherever.

Any suggestions with all of that? Is my post in the right category?

Thanks for the reply btw!

You can have a 100% c++ solution using Emscripten (C++ -> Javascript compiler (including loads of open-source tech like SDL, GL, libpng etc...))

For the backend you can use Wt (http://www.webtoolkit.eu/wt) which allows you to code logic (in a similar way to PHP) but also provide an entire web server (or can be used as a cgi plugin for Apache).

I use both these technologies for my own projects and they work great. The only annoying bit is that even though you can code in C++, you are still constrained to what can be done in a web browser such as your client can only connect to a web socket server and you cannot write to the local filesystem using things like std::ofstream.

http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers :)

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.

Thank you!

WT looks pretty interesting in itself. I've installed it and I think I'm going to read about that. WT is probably a good foundation for what I'd like to do, so I need to get connected to SQL and get some query output from what I have going. I suppose I need some node.js or IO library of some sort, to help with the WEBGL end of it.

If you have any tidbits on what you've done/experienced though WT, please let me know if you can; I'd certainly appreciate bridges over any upcoming pitfalls.

Well, to communicate the frontend C++/Emscripten/HTML5 to the backend C++/Wt server I needed to use websockets (since the underlying Javascript that the browser interprets cannot use raw sockets).

It is pretty tricky to find a decent websocket library so if you have the time, I highly recommend implementing your own. However the best one I found was (http://websocketserver.de) which once you cut the Lua out of it is much cleaner than the rest.

With minimal changes this websocket server can work alongside the Wt library. As for communicating with a database (which is pretty necessary for players to save their game / scores etc since javascript is unable to save locally*), I used sqlite and there were no complexities getting it working alongside websocketserver.de or Wt. I imagine something like MariaDB or Postgres will have no issues either.

*HTML5 might be able to store data in cookies or even using a certain API that a couple of the latest browsers support but I don't know if Emscripten can access that directly without inlining some Javascript into your program.

http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers :)

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.

I've been using Dart (https://www.dartlang.org/) for a webgl project over the last couple of weeks and i can really recommend it. It has a really clean syntax that is easy to pick up if you're coming from a c++ or java background. Also, it compiles into native (super optimized) javascript which makes browser compability a non-issue.

Thanks Karsten_,

I'll get the websocketserver running next. I don't think I will be rolling my own socket server too soon though.

This topic is closed to new replies.

Advertisement