This has nothing to do with business but I felt it may provide ideas for the game devs on the forum as well as potential insights for others (maybe you want to learn programming).
I recently discovered the "Ruby2D" library and decided to see if I could get it to build on my Windows system.
Although I love programming & software development, my experience with C/C++ is scant, so felt it would be a good way to see if I could gain some insight from trying to get it to work. The following will explain my progress.
As an aside, Ruby2D seems like a very simple way to create 2 dimensional software experiences. I would be partial to doing a tutorial on the mechanisms behind it, if people wanted to gain some insights into game dev (not that I'm an expert by any degree). My ambition would be to attempt to recreate the original "Doom" game, which was a 2D game with simulated perspective.
For the sake of brevity, this is a GIF of my system building the test app I created. The build process creates an EXE which can be used on other Windows systems (hence my interest): -
--
What Is Ruby and Ruby2D?
Ruby is a programming language created by Yukihiro "Matz" Matsumoto in the 90's.
It's most well-known for its use in the "Ruby on Rails" web application framework and has been adopted largely because of this.
There are a number of aspects to Ruby which make it a great programming language, especially for beginners: -
Much like BASIC, Ruby gives programmers the ability to invoke objects and attach functionality to them.
Of course, this works similarly in C/C++ but the process is much more complicated and involved.
I can further extol the virtues of Ruby if people wanted - for now, I'll just say that it's an extremely effective language which has been used (again, thanks mainly to RoR) by the likes of Shopify, Github, Twitter, Stripe and a number of other web application companies.
-
Ruby2D is a library for Ruby...
A library, in terms of software development, is a set of functionality you can include in an application to achieve specific results.
For example, if you wanted to develop a native Windows application which printed a document, you may include a library to help interface with the printer hooks in the OS. This would allow you to offload functionality to the library (rather than having to write it all yourself).
The Ruby2D library seems to be a wrapper for the "Simple2D" library.
Simple2D is written in C and compiled into DLL format when using on a Windows system. The Ruby2D gem seems to interface with this library, allowing you to harness its functionality with the simplicity and extensibility of the Ruby language.
I have no affiliation with it beyond having discovered it some days ago - you're able to add the following objects/elements to a Window: -
These can all be customized and managed inside a Ruby application, which can be run by using
from the command line.
A number of games/experiences have been created with it including: -
-
Building
Building / compiling applications is the difficult part and done at the behest of the system which you're using.
Due to the inability for the likes of PHP, Python or other "simple" languages to be compiled by default, it was interesting to me to see that Ruby2D had its own build pipeline. This makes use of MRuby, which we'll discuss later.
The importance of MRuby is that what you're actually doing with it is using Ruby as a "simple" interpreter for C - there is a lot of functionality missing from MRuby in order to get this to work cross platform.
Whilst this may be considered an issue, it means that you're able to use a build pipeline to create native applications that are coded in Ruby.
In the case of Ruby2D, MRuby is used to create a set of "build" functionality which allows us to deploy .exe applications on Windows (I've not used it on Linux or MacOS, although it could be compiled on there too).
To give an example of MRuby, this guy used it to build a game on Nintendo Switch, which I believe has now been pulled from the Switch store: -
View: https://www.youtube.com/watch?v=o0d4sjcUfCg&ab_channel=RubyKaigi
Ruby2D has a build pipeline which I'll discuss later. I had to hack this to get it to work on Windows, hence my writing this article...
-
What It Means
IF you are interested in developing interactive GUI's which can run on native systems (Windows/Linux/Mac), I think this is a good way to gain experience in making it work. This goes beyond games - there is a lot of scope for "children's" learning apps, interactive native Windows experiences and more. Some of the old 2D apps my Dad bought me in the 90's could be built with it.
I would be interested in doing some sort of tutorial if people wanted it. I'm not an expert in C, so it may be a good way to help me gain experience.
For the next part of the article, I will explain how I managed to get it all to work/build on my system. Anyone involved with software likely has experienced issues with compiling/building apps, so detailing the issues I had to surmount may help others.
--
Installing Ruby, RubyGems and MRuby on Windows
Windows, as most developers will tell you, is extremely difficult to set up an adequate build pipeline.
The reason for this is a lack of central repository, meaning that you have to manually acquire and link the various libraries an application may require. This is tedious and often fraught with difficulty.
Fortunately, a number of projects, namely Chocolatey and MSYS, have been created to address this issue and, generally, do the job extremely well. I use MSYS2 as I picked it up after using RubyInstaller2 some time back.
I will explain how to set up MSYS2 with Ruby & MRuby below. After that, I will detail what I had to do to change the Ruby2D code to compile for a Windows environment. From there, if you want tutorial(s), we can look into that separately.
-
Installing Ruby
Ruby can be installed in a number of ways.
I originally wrote an article explaining that RubyInstaller is the best way to do it. I have since managed to get an MSYS2 version of ruby installed, which is far superior (for me). I'll explain both ways in case people need ideas.
The key (however you do it) is Windows requires a pre-compiled version of Ruby. Whilst you can compile it yourself, its much better to just install a pre-built version so that you don't need to worry about getting your environment sorted for it: -
RubyInstaller
RubyInstaller is a project aimed at providing pre-compiled versions of Ruby for Windows.
You can use either the "installer" version of RubyInstaller or the "zip" version.
The aim is to get the "ruby" command to work in CMD, which is slightly different depending on the version you use: -
ZIP (preferred)
Installer (not preferred)
If you wish to use the RubyInstaller installation package, you need to choose the "without Devkit" version: -
Run the installer and it *should* do everything for you.
You'll still need to install MSYS2, but will not have to add the ruby executable path to your system PATH var.
-
Installing MSYS2
Regardless of how you install Ruby, you need MSYS2 to provide the required build tools.
This is required for all systems: -
If they do, move to the next step. If they don't you should try closing the MSYS2 shell and opening a new one (to see if that will give you access to the various executables).
-
Environment Variables
Finally, we need to update the PATH variable to make the "ruby" executable accessible from the command line.
How you do this depends on which version of Windows you're using. I'll only write for Windows 10 - if you're using a different version, you can ask me and we can look into it separately: -
My recommendation is to use the MSYS2 Ruby, as that allows you to keep it all in the same place. If you installed Ruby via RubyInstaller, we will need to add the path to that specific Ruby installation (as well as the MSYS2 install).
This is which paths you should add: -
-
Installing RubyGems & Bundler
If you've installed Ruby correctly, you should now be able to access the "ruby" command on the commandline.
Now you have ruby, you need to get its package manager (bundler).
Bundler
Bundler helps you install gems from a Gemfile.
Gemfiles are used by Ruby to manage and install dependencies for an application. They work similarly to "package.json" for nodeJS apps.
If you aspire to write any application in Ruby, it's important to have "bundler" installed, as it allows you to process any Gemfile you may need to use for different ruby apps. To do this, we need to install the bundler gem directly to the system, so that it's globally accessible.
Pull up a fresh CMD window and type the following: -
This should process without an issue.
If there is a problem, it likely means that "RubyGems" is not installed (RubyGems is to Ruby what NPM is to NodeJS). If you see an error pertaining to RubyGems, it means you need to install it on your system, which I'll explain below.
RubyGems
RubyGems should work out of the box (IE the bundler command above should just work).
If it does not, there is a tutorial here which explains how to get it set up: -
After that has run, it means you will be able to interact with the RubyGems packages, of which Ruby2D is one.
Run the "gem install bundler" command again and see if it installs without error. If it does, Ruby should now be fully set up.
-
Installing MRuby
Finally, MRuby.
MRuby is required to "build" the application natively (IE to create a portable EXE you can install on other systems).
It seems that MRuby is a slimmed down version of Ruby which, when integrated with C, provides a link between Ruby code and a native application.
Installing MRuby depends on your system. As this is a Windows tutorial, you have two options: -
If you want to install the MSYS2 version, load up the MSYS2 shell and use the above command. This will install the package and make mruby available at cmd level, which will allow the build toolchain to work. Unfortunately, because the standalone MRuby does not include the "dir" package, it won't work for my version of Ruby2D (I had to hack it to get it to run on Windows).
To compile MRuby (as per my version of the Ruby2D library), you need to do the following: -
I keep my development tools in c:/dev, so I put my mruby in that directory: -
This is ONLY if you compiled locally -- from here, you should be able to add the c:/dev/mruby/bin directory to your system PATH variable (instructions above). This will make the "mruby" command available in cmd: -
--
Installing Simple2D, Glew & Other Libraries For Ruby2D
Finally, you need to obtain the libraries required to get Ruby2D to compile.
These include Simple2D and Glew.
We can install these via MSYS2 (one of the immense benefits of having it installed):-
There may be more libraries we need but I don't know them off the top of my head - we can look for them if errors arise later.
The key point is that having MSYS2 installed means we have a means to access libraries that don't need to be compiled. It's extremely important to have this as it fixes one of the biggest issues facing Windows developers.
To be clear, these are ONLY for the "build" part of Ruby2D. If you just want to create a "ruby" app, you don't need the above.
--
Conclusion
IF all of this works, it means you now have your local development environment set up to support building a native version of your Ruby2D app.
I will write another article explaining what I did to change the Ruby2D code to get it to build on Windows below.
This is not an ad. I don't care if you use the information or not - I write this sort of thing to give me perspective on what was done for future purposes. I figured that, as I'd seen some people wanting to make games to sell, R2D could make that ideal more accessible (and cheaper).
After the next article, I may see if I can bring myself to attempt to make a Doom clone with it (or something challenging). I'm not an expert in C, so may be biting off more than I can chew. I do have some time to do it and would be happy to help anyone who wants to start using Ruby, or programming generally, so long as it's evident you're actually trying to do something proactive.
I recently discovered the "Ruby2D" library and decided to see if I could get it to build on my Windows system.
Although I love programming & software development, my experience with C/C++ is scant, so felt it would be a good way to see if I could gain some insight from trying to get it to work. The following will explain my progress.
As an aside, Ruby2D seems like a very simple way to create 2 dimensional software experiences. I would be partial to doing a tutorial on the mechanisms behind it, if people wanted to gain some insights into game dev (not that I'm an expert by any degree). My ambition would be to attempt to recreate the original "Doom" game, which was a 2D game with simulated perspective.
For the sake of brevity, this is a GIF of my system building the test app I created. The build process creates an EXE which can be used on other Windows systems (hence my interest): -
--
What Is Ruby and Ruby2D?
Ruby is a programming language created by Yukihiro "Matz" Matsumoto in the 90's.
It's most well-known for its use in the "Ruby on Rails" web application framework and has been adopted largely because of this.
There are a number of aspects to Ruby which make it a great programming language, especially for beginners: -
- Object Oriented
The entire language is built around objects.
The reason this is important is that you don't have to worry about calling small and obscure functions to achieve simple functionality.
For example, if we wanted to infer the name of a file in Ruby vs C, you'd use the "basename" function in both. However, using it in Ruby is a far simpler process than C: -
Ruby:file_name = File.basename("/home/gumby/work/ruby.rb", ".*") #-> ruby
PHP:file_name = basename("/etc/sudoers.d", ".d"); // -> sudoers
C:file_name = basename("/etc/sudoers.d"); // -> sudoers.d
- Simple
Perhaps the most important aspect of Ruby is that it doesn't have semicolons.
Although this may sound mundane, it's symbolic of the underlying virtue of the language - extremely forgiving and has a lot of inbuilt functionality to make its use as simple as possible.
For example, if you wanted to declare a class and invoke it in Ruby, you'd do the following: -
Ruby:class Test def initialize puts "Test" end end test = Test.new #-> will output 'test' to console
- Canonical
I'm not sure if this is the right word but I've read it somewhere and forgotten which it was.
Ultimately, one of the things that makes Ruby stand out is how you're able to make it read like a sentence.
This gives a lot of scope to making the system perform a range of different tasks without having to configure a huge number of different pieces of functionality. For example, if you wanted to declare a variable if a certain set of criteria is met, you'd use the following: -
Code:variable = X.new if condition.is_met?
Much like BASIC, Ruby gives programmers the ability to invoke objects and attach functionality to them.
Of course, this works similarly in C/C++ but the process is much more complicated and involved.
I can further extol the virtues of Ruby if people wanted - for now, I'll just say that it's an extremely effective language which has been used (again, thanks mainly to RoR) by the likes of Shopify, Github, Twitter, Stripe and a number of other web application companies.
-
Ruby2D is a library for Ruby...
A library, in terms of software development, is a set of functionality you can include in an application to achieve specific results.
For example, if you wanted to develop a native Windows application which printed a document, you may include a library to help interface with the printer hooks in the OS. This would allow you to offload functionality to the library (rather than having to write it all yourself).
The Ruby2D library seems to be a wrapper for the "Simple2D" library.
Simple2D is written in C and compiled into DLL format when using on a Windows system. The Ruby2D gem seems to interface with this library, allowing you to harness its functionality with the simplicity and extensibility of the Ruby language.
I have no affiliation with it beyond having discovered it some days ago - you're able to add the following objects/elements to a Window: -
These can all be customized and managed inside a Ruby application, which can be run by using
Code:
ruby file.rb
A number of games/experiences have been created with it including: -
-
Building
Building / compiling applications is the difficult part and done at the behest of the system which you're using.
Due to the inability for the likes of PHP, Python or other "simple" languages to be compiled by default, it was interesting to me to see that Ruby2D had its own build pipeline. This makes use of MRuby, which we'll discuss later.
The importance of MRuby is that what you're actually doing with it is using Ruby as a "simple" interpreter for C - there is a lot of functionality missing from MRuby in order to get this to work cross platform.
Whilst this may be considered an issue, it means that you're able to use a build pipeline to create native applications that are coded in Ruby.
In the case of Ruby2D, MRuby is used to create a set of "build" functionality which allows us to deploy .exe applications on Windows (I've not used it on Linux or MacOS, although it could be compiled on there too).
To give an example of MRuby, this guy used it to build a game on Nintendo Switch, which I believe has now been pulled from the Switch store: -
Ruby2D has a build pipeline which I'll discuss later. I had to hack this to get it to work on Windows, hence my writing this article...
-
What It Means
IF you are interested in developing interactive GUI's which can run on native systems (Windows/Linux/Mac), I think this is a good way to gain experience in making it work. This goes beyond games - there is a lot of scope for "children's" learning apps, interactive native Windows experiences and more. Some of the old 2D apps my Dad bought me in the 90's could be built with it.
I would be interested in doing some sort of tutorial if people wanted it. I'm not an expert in C, so it may be a good way to help me gain experience.
For the next part of the article, I will explain how I managed to get it all to work/build on my system. Anyone involved with software likely has experienced issues with compiling/building apps, so detailing the issues I had to surmount may help others.
--
Installing Ruby, RubyGems and MRuby on Windows
Windows, as most developers will tell you, is extremely difficult to set up an adequate build pipeline.
The reason for this is a lack of central repository, meaning that you have to manually acquire and link the various libraries an application may require. This is tedious and often fraught with difficulty.
Fortunately, a number of projects, namely Chocolatey and MSYS, have been created to address this issue and, generally, do the job extremely well. I use MSYS2 as I picked it up after using RubyInstaller2 some time back.
I will explain how to set up MSYS2 with Ruby & MRuby below. After that, I will detail what I had to do to change the Ruby2D code to compile for a Windows environment. From there, if you want tutorial(s), we can look into that separately.
-
Installing Ruby
Ruby can be installed in a number of ways.
I originally wrote an article explaining that RubyInstaller is the best way to do it. I have since managed to get an MSYS2 version of ruby installed, which is far superior (for me). I'll explain both ways in case people need ideas.
The key (however you do it) is Windows requires a pre-compiled version of Ruby. Whilst you can compile it yourself, its much better to just install a pre-built version so that you don't need to worry about getting your environment sorted for it: -
RubyInstaller
RubyInstaller is a project aimed at providing pre-compiled versions of Ruby for Windows.
You can use either the "installer" version of RubyInstaller or the "zip" version.
The aim is to get the "ruby" command to work in CMD, which is slightly different depending on the version you use: -
ZIP (preferred)
- Download the RubyInstaller ZIP file from here: -
- You may need to also download 7ZIP to read the file (not sure why they've archived it as .7zip)
- Once it's downloaded, load the archive with 7ZIP and extract its contents to a folder on your hard drive
- I tend to put it in C:/dev, which means the folder would be c:/dev/ruby-3.0.3-x86_x64 (or similar)
- After doing this, you need to add the "bin" directory of this folder to your system PATH (see "Environment Variables" below)
Installer (not preferred)
If you wish to use the RubyInstaller installation package, you need to choose the "without Devkit" version: -
Run the installer and it *should* do everything for you.
You'll still need to install MSYS2, but will not have to add the ruby executable path to your system PATH var.
-
Installing MSYS2
Regardless of how you install Ruby, you need MSYS2 to provide the required build tools.
This is required for all systems: -
- Download and install MSYS2
- From the "Start" menu in Windows, load the MSYS2 shell
- Type "pacman -S mingw-w64-x86_64-ruby" and press enter
- After it installs, type "pacman -S mingw-w64-x86_64-toolchain" and press enter
If they do, move to the next step. If they don't you should try closing the MSYS2 shell and opening a new one (to see if that will give you access to the various executables).
-
Environment Variables
Finally, we need to update the PATH variable to make the "ruby" executable accessible from the command line.
How you do this depends on which version of Windows you're using. I'll only write for Windows 10 - if you're using a different version, you can ask me and we can look into it separately: -
- Click on "Search" (Magnifying glass icon on the taskbar -- if you can't see it, hold the "Windows" key and press "S")
- Type "Environment"...
- "Edit the system and environment variables" should appear
- Click this and let the Window load...
- Click on "Environment Variables"
- Look for "Path" (in the SYSTEM part) and select "Edit"...
- Select "New": -
My recommendation is to use the MSYS2 Ruby, as that allows you to keep it all in the same place. If you installed Ruby via RubyInstaller, we will need to add the path to that specific Ruby installation (as well as the MSYS2 install).
This is which paths you should add: -
- C:/path/to/your/ruby/executable (RubyInstaller only)
- C:/MSYS2/mingw64/bin (this is required for all)
- C:/MSYS2/usr/bin (this is required for all)
-
Installing RubyGems & Bundler
If you've installed Ruby correctly, you should now be able to access the "ruby" command on the commandline.
Now you have ruby, you need to get its package manager (bundler).
Bundler
Bundler helps you install gems from a Gemfile.
Gemfiles are used by Ruby to manage and install dependencies for an application. They work similarly to "package.json" for nodeJS apps.
If you aspire to write any application in Ruby, it's important to have "bundler" installed, as it allows you to process any Gemfile you may need to use for different ruby apps. To do this, we need to install the bundler gem directly to the system, so that it's globally accessible.
Pull up a fresh CMD window and type the following: -
Code:
gem install bundler
This should process without an issue.
If there is a problem, it likely means that "RubyGems" is not installed (RubyGems is to Ruby what NPM is to NodeJS). If you see an error pertaining to RubyGems, it means you need to install it on your system, which I'll explain below.
RubyGems
RubyGems should work out of the box (IE the bundler command above should just work).
If it does not, there is a tutorial here which explains how to get it set up: -
- Download the RubyGems files from this URL - Download RubyGems | RubyGems.org | your community gem host
- Extract the archive to a local folder (it doesn't matter where because you can delete it afterwards)
- Open CMD and cd into that folder
- Run the following command: "ruby setup.rb"
After that has run, it means you will be able to interact with the RubyGems packages, of which Ruby2D is one.
Run the "gem install bundler" command again and see if it installs without error. If it does, Ruby should now be fully set up.
-
Installing MRuby
Finally, MRuby.
MRuby is required to "build" the application natively (IE to create a portable EXE you can install on other systems).
It seems that MRuby is a slimmed down version of Ruby which, when integrated with C, provides a link between Ruby code and a native application.
Installing MRuby depends on your system. As this is a Windows tutorial, you have two options: -
- Install a pre-compiled version (this can be done via MSYS2 using the following command - pacman -S mingw-w64-clang-x86_64-mruby)
- Compile your own
If you want to install the MSYS2 version, load up the MSYS2 shell and use the above command. This will install the package and make mruby available at cmd level, which will allow the build toolchain to work. Unfortunately, because the standalone MRuby does not include the "dir" package, it won't work for my version of Ruby2D (I had to hack it to get it to run on Windows).
To compile MRuby (as per my version of the Ruby2D library), you need to do the following: -
- Clone the MRuby repository to your local system.
This can be done by installing GIT (if you don't have it already), loading up CMD, browsing to an appropriate folder and using the following command: -Code:git clone https://github.com/mruby/mruby
- This will copy the MRuby repo code to a directory with the label "mruby" relative to the directory where you ran the command.
For example, if you ran the command in c:/, you'll get the folder c:/mruby
- From here, cd into the mruby folder ("cd mruby")
- Open the following file in a text editor: "./mruby/build_config/default.rb"
- Add the following to line 16: -
conf.gem :github => 'iij/mruby-dir'
- Save the file and exit the text editor
- In CMD, type "rake" and press enter
- This will proceed through the mruby build process and SHOULD work. If it does not work, it means you don't have appropriate packages installed inside Windows. This will be specific to your machine, so I cannot provide any insight onto what may be missing here.
If you get an error, let me know and we'll see if we can get it to work.
I keep my development tools in c:/dev, so I put my mruby in that directory: -
This is ONLY if you compiled locally -- from here, you should be able to add the c:/dev/mruby/bin directory to your system PATH variable (instructions above). This will make the "mruby" command available in cmd: -
--
Installing Simple2D, Glew & Other Libraries For Ruby2D
Finally, you need to obtain the libraries required to get Ruby2D to compile.
These include Simple2D and Glew.
We can install these via MSYS2 (one of the immense benefits of having it installed):-
- Load up the MSYS2 shell (or just normal CMD if you're able to run "pacman" from it)
- Type the following commands (press enter after inputting each): -
- pacman -S mingw-w64-x86_64-glew
- pacman -S mingw-w64-x86_64-SDL2_mixer
- pacman -S mingw-w64-x86_64-SDL2_image
- pacman -S mingw-w64-x86_64-SDL2_ttf
- pacman -S mingw-w64-x86_64-SDL2
There may be more libraries we need but I don't know them off the top of my head - we can look for them if errors arise later.
The key point is that having MSYS2 installed means we have a means to access libraries that don't need to be compiled. It's extremely important to have this as it fixes one of the biggest issues facing Windows developers.
To be clear, these are ONLY for the "build" part of Ruby2D. If you just want to create a "ruby" app, you don't need the above.
--
Conclusion
IF all of this works, it means you now have your local development environment set up to support building a native version of your Ruby2D app.
I will write another article explaining what I did to change the Ruby2D code to get it to build on Windows below.
This is not an ad. I don't care if you use the information or not - I write this sort of thing to give me perspective on what was done for future purposes. I figured that, as I'd seen some people wanting to make games to sell, R2D could make that ideal more accessible (and cheaper).
After the next article, I may see if I can bring myself to attempt to make a Doom clone with it (or something challenging). I'm not an expert in C, so may be biting off more than I can chew. I do have some time to do it and would be happy to help anyone who wants to start using Ruby, or programming generally, so long as it's evident you're actually trying to do something proactive.
Dislike ads? Become a Fastlane member:
Subscribe today and surround yourself with winners and millionaire mentors, not those broke friends who only want to drink beer and play video games. :-)
Membership Required: Upgrade to Expose Nearly 1,000,000 Posts
Ready to Unleash the Millionaire Entrepreneur in You?
Become a member of the Fastlane Forum, the private community founded by best-selling author and multi-millionaire entrepreneur MJ DeMarco. Since 2007, MJ DeMarco has poured his heart and soul into the Fastlane Forum, helping entrepreneurs reclaim their time, win their financial freedom, and live their best life.
With more than 39,000 posts packed with insights, strategies, and advice, you’re not just a member—you’re stepping into MJ’s inner-circle, a place where you’ll never be left alone.
Become a member and gain immediate access to...
- Active Community: Ever join a community only to find it DEAD? Not at Fastlane! As you can see from our home page, life-changing content is posted dozens of times daily.
- Exclusive Insights: Direct access to MJ DeMarco’s daily contributions and wisdom.
- Powerful Networking Opportunities: Connect with a diverse group of successful entrepreneurs who can offer mentorship, collaboration, and opportunities.
- Proven Strategies: Learn from the best in the business, with actionable advice and strategies that can accelerate your success.
"You are the average of the five people you surround yourself with the most..."
Who are you surrounding yourself with? Surround yourself with millionaire success. Join Fastlane today!
Join Today