I am looking to make a 3D FPS that runs inside web browsers. I looked into using WebGL, but it didn't seem far enough along into development. I decided on using RoR because Ruby was a language I knew.

I realize this may seem like a ridiculous question, but is there any way I can port/rewrite/whatever a game engine(Say for instance IrrLicht) to run inside Rails? Or for that matter, any other language on the web.

  • \$\begingroup\$ possible duplicate of Ruby on Rails Browser Based Game Engine \$\endgroup\$ Oct 5 '12 at 17:09
  • 7
    \$\begingroup\$ The way you ask your question makes it seem like you don't really have a solid grip on what Rails is, what WebGL is, and how they can work together. Do you want to write game client code in Ruby? or Support a browser game with Rails as the backend? The suggested duplicate and these two questions can help you learn more about how you can use Ruby in game development. \$\endgroup\$ Oct 5 '12 at 17:13
  • 3
    \$\begingroup\$ C'mon guys, it's not a bad question just because you think the answer is obvious. The FAQ calls for "practical, answerable questions based on actual problems that you face", and this is answerable. Plus [s]he has put in some research effort. So why the downvotes? \$\endgroup\$
    – Kylotan
    Oct 5 '12 at 17:59
  • \$\begingroup\$ jQuery is way better than rails at 3D engines. $('canvas').opengl({gravity: −9.81}). \$\endgroup\$ Oct 5 '12 at 19:13
  • 2
    \$\begingroup\$ @Kylotan, yeah, it kinda is a bad question - but after several draft comments, I will agree that it's not necessarily a useless question (partly based on a good answer). Understanding why something won't work (or at least isn't realistic) can be helpful, and might also point people in the direction of a better approach. (I'm still flagging to close, though). \$\endgroup\$
    – Cyclops
    Oct 6 '12 at 11:31

Server-side web languages such as Ruby on Rails are used to generate/serve HTML, JavaScript and CSS. They receive a request from the browser, act on it to make the HTML response, and then send it to the browser and the transaction is done. With the exception of tricks like long polling, they don't do anything dynamic in the browser; that responsibility is left to JavaScript (or plugins).

It doesn't really make sense to port a 3D engine to Rails. When the browser requests a page, it could certainly fire up the 3D engine and render something... But then two things could happen:

  • Render and send one frame to the browser. This could be useful for an adventure game perhaps, or some other non-realtime format.
  • Render several frames and send them to the browser translated into JavaScript; then those frames would be played back to the user via JavaScript, as a pre-rendered animation.

You could issue multiple requests, but you certainly can't keep up 30 HTTP requests per second (unless you were operating in a LAN environment), nor should you, because the overhead would be ridiculous. So then you could look into something like WebSockets or Flash sockets or long polling to stream those frames. But then that begs the question, why are you doing the 3D rendering on the server?

Essentially it would be an exercise in futility, or purely academic, or useful for a dynamically-rendered web adventure game.

So yes, it does seem like a ridiculous question, but the answer is yes, you can "port/rewrite/whatever" a graphics engine to run in any language. 3D graphics is just math, it's matrices and vectors and... well, at its essence, that's about it. But realtime 3D graphics will not be possible in pure Ruby in Rails without the assistance of something client-side like WebGL. And you would certainly want realtime 3D graphics for a first-person shooter.

  • \$\begingroup\$ As a side note, all the desktop browsers except IE currently support WebGL at least partially, and rather significantly in my experience (and for several versions, too!). Here's a WebGL example - do you see it in your browser? \$\endgroup\$
    – Ricket
    Oct 5 '12 at 18:22
  • 1
    \$\begingroup\$ I am sure you could not actually write a 3D engine in RoR without going through some great ordeal. You could port software rendering code with relative ease. It has been ages since anyone used that. I think this answer is slightly misleading for people who misunderstand the difference between server-side and client-side scripting. It is a good answer that may confuse people who did not know the answer beforehand. ;) \$\endgroup\$
    – AturSams
    Oct 5 '12 at 20:47
  • \$\begingroup\$ @Ricket: while the browsers support WebGL, that support is not universally available. That is, Chrome might support it, but only on some OS versions with some newer driver versions, etc. You can't look just at the browser support to get a good idea of the limitations of the WebGL market. Simply having hardware that should support WebGL does mean that the driver isn't blacklisted due to bugs or compatibility concerns. \$\endgroup\$ Oct 5 '12 at 23:21
  • 1
    \$\begingroup\$ Good answer to a poor question. I think one way of describing the situation is as an impedance mismatch - unrelated software just doesn't always want to connect properly. \$\endgroup\$
    – Cyclops
    Oct 6 '12 at 11:33

The short answer: You need client-side scripting to make real-time games possible.

The long answer:

What is a server?

A server is a computer used to run services for other computers on a network.

What is a web request

A web request is what web servers handle. It is a request, often created by a user from home on a home computer, netbook or a smartphone, generally asking for a certain page. The server receives this request, runs the script (unless a static html file is requested) and returns a response that is normally a html file. The nature of this request is that it is like a short handshake, it happens and then it's over.

What is Ruby on Rails?

Ruby on rails is a scripting language, designed to run on a server and handle web requests. This is used to design web application much like this website.

Meaning, I want to read page: Is it possible to make/translate a 3d engine to ruby on rails?

The server(s) at the domain gamedev.stackexchange.com take my request and send me back the textual data I wanted formed into a html file that my browser can render. They run some sort of server-side script to collect all the pears of wisdom related to this question and organize them. This kind of script could be written in Ruby on Rails.

What is a 3d engine

It is software that provides real-time 3D rendering capabilities - if you ever played any of these 3d games you know that unlike a short handshake the games provide a constant steam of imagery directly to your monitor. This is very expensive in processing power, namely in GPU power. Most modern games demand enough graphical processing power to occupy one modern computer*. You do not want to pay for that power nor do you have the software tools to attempt something like this. Ruby on Rails was not designed for that purpose. It is designed for the short handshake situation where the server sends one page and forgets about the client while moving on to the next request.

3d game engines run on the home computer, you RoR never runs or gets near a home computer. You need client-side scripting to make real-time games possible. You could start with Unity or ActionScript with Stage3D if you have some aversion towards webGL.

To be honest, if porting a 3d engine to some language is practical, someone has already done it and a 3d engine that is used with that language already exists.


Yes you can.

I always find it odd how good programmers think in terms of what can not be done. Anything is possible.

Porting a 3d Engine to rails may not be how this would work. Using Rails to handle the backend and organize code certainly would work. Like previously mentioned you could use WebGL in the HTML Rails supplies to the client. Rails has a nice MVC model so you could use Rails to generate and organize Views and Controls for the game.

Now that I am thinking about it, you could also use Rails to do the graphics processing server side, compress into a video stream, and stream it to the client. Which may be a viable solution for clients without WebGL support. But most Servers are CPU heavy, not GPU heavy. But it depends on the server and how many clients you need to support blah blah blah.


Not the answer you're looking for? Browse other questions tagged or ask your own question.