Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

Game From Scratch C++ Edition The Introduction


I have decided to take a quick detour from my primary game development, to illustrate how to create a more simplistic 2D game using C++. I am going to cover it over a number of posts, each building on the last and if you follow along, hopefully at the end you will be well on the road to creating your own games.



Why in C++, I thought you hated C++?



That is a good question with a bad answer. I am writing it in C++ because regardless to all the people say “DON’T DO THAT IN C++!” the vast majority of people still do. The problem is so many of these people follow outdated or just downright bad examples and establish a horrific coding style right from day one.



So often questions come up like “how do I split my code up into multiple files” or people state things like “I hate OOP, I’ll just use functions”. Both of these statements illustrate the failing of many tutorials. Using C++ without objects is like using a hammer only as a nail extraction tool; while functional you are entirely missing the point of the tool. One last thing that many new developers get hung up on… we are writing a game, not a game engine! Don’t overwhelm yourself with unneeded complexity when you are just starting out.



This tutorial is going to span a number of posts so that I can go into the detail necessary. I am going to make some decisions for the sake of readability, but for the most part this should be code that you can take away and develop a success game upon. Along the way I will try to explain things to the best of my ability. With each post I will include a download link with the project, source code, etc. I have this nack for going off topic or into detail and frankly that is part of what I enjoy about writing.  That said, it can be confusing or distracting for people that just want the facts.  In this case I will box such comments into “Optional Information” sections that you can freely skip and still keep up. 



One last thing, this post will not teach you to program. I am going to make certain assumptions about my audience, the biggest of which is that you have a few weeks of learning under your belt. I assume you know the very basics in one language like how to declare a variable or how to use an if statement. If you have absolutely no exposure to programming I suggest you head over here for some getting started advice.




What game are we going to create?


We are going to create a downright amazing game about two intrepid paddles in space, called PANG!



Yeah yeah, we are going to create a Pong clone. Frankly every first game should be something simple and fairly easy to complete. That said, if things in this post go according to plan, Pang should provide us a few interesting opportunities, as with each additional post we can add a few more features like 2 player hot-seat, AI, nuclear missiles, networking, etc.



Doing most of the heavy lifting will be the excellent SFML libraries. They are well designed and do a very good job of keeping you away from a lot of the harmful aspects of C++.




Stuff you need to follow along



Before we begin, there are a few things you need to download and install.



This tutorial is going to work entirely with Microsoft C++ Express 2010. If you have another version or different IDE, you can still follow along, but directions will be explicitly for Visual C++ Express. So if you haven’t already head over here and click the Install Now button.


*** One word of warning, if you already have a Visual Studio 2010 product installed and patched to SP1, you will have to reapply the SP1 after you install Visual C++ Express. It takes a long time, and yes, it’s very annoying ***




Next head on over to SFML and download the SFML Windows - Visual C++ 2008 headers / libraries / external libraries package. This link is a zip file, just save it somewhere on your computer, we will address it again shortly.



One last catch ( explained here ) is that the SFML Visual C++ DLLs simply do not work with Visual Studio 2010. I have compiled them for you and you can download them here. Again, simply save that zip file somewhere and we will use it shortly.



Finally you are going to need a paint program of some form. MSPaint will work in a pinch, but I would recommend Paint.NET or the GIMP instead. Download links for both can be found here.



Ok, now that we have everything we need lets move on to Part 1.



  Forward to Part 1

blog comments powered by Disqus

Month List

Popular Comments

Understanding Apple's Metal graphics library. What does it mean to indie game developers?
Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

Home > >

4. June 2014


I’ve noticed since Apple announced Medal at the WWDC a number of people are quite confused over exactly what Metal is.  This post is an attempt to clear that up without having to dig through marketing speak or fanboy drivel.



There is one very important thing to start with…  Metal is not going to cause OpenGL to go away or for Apple to stop supporting OpenGL.  If you are developing a game using OpenGL today, don’t worry, absolutely nothing about your world changes!  Metal is an alternative to OpenGL, but they push different buttons, we will cover that shortly.


So, what exactly is Metal?  It’s a low level, less portable more optimized graphics layer for doing the same kind of things you would use OpenGL ( and OpenCL ) or Direct3D for.  That is 3D graphics rendering and parallel GPU programming.  Metal attempts to lower the amount of overhead required for performance reasons as well as reduce CPU bottlenecks ( right now GPUs are spending a lot of time waiting around for CPUs and this is bad mkay? ).  Think about it this way, if you took OpenGL or Direct3D and took away years of cruft and supported only a subset of modern hardware, do you think you could make things faster?  Of course you could, assuming programming ability of course.  That is essentially exactly what Metal does.


There is one other very important thing to realize here.  Metal is Apple only!  This may seem obvious, but it really needs to be pointed out.  With DirectX works across a number of video cards and OpenGL works across a number of video cards AND platforms.  Metal on the other hand works only on the newest iOS devices, specifically those with A7 processors ( and assumedly A8, A9 etc… ).  Metal doesn’t even work on Mac OS, but assume all future devices ( such as a console or TV ) from Apple to support Metal.


The idea of Metal is hardly anything new.  In some strange ways it’s actually a throwback to the way things used to be in the bad ‘ole days, where each vendor would ship a custom API to take advantage of their 3D hardware.  Voodoo Graphic’s GLIDE API was probably the most popular example.  It was common for game developers to create versions of their games for specific hardware.  Eventually general APIs like D3D and OpenGL won out as it was a pain in the ass supporting all these different render paths… what’s old is new again!  That said, Apple is hardly the only vendor leading us down this road, AMD recently released Mantle, which is basically the exact same thing ( a low overhead GPU API ) targeting AMD/ATI hardware.  Even Microsoft plans to go lower level in DirectX 12, but unlike Metal, it will still support a number of GPUs.


So, from a Programmer’s perspective, what is Metal?  It’s a new API that is part of the iOS 8 SDK.  It consists of two parts, the ObjectiveC based SDK and a scripting language creatively known as Metal Shading Language.  The Metal shading language is based on C++11 and is used to write code that will run on the GPU.


Should I work with Metal?

I suppose the most important question is… should you care?  To the rank and file indie game programmer truth of the matter is Metal is a bit of a non-issue.  Is it worth re-writing your code to work with Metal?  Probably not.  If you are working cross platform, almost certainly not.  Metal is just too small of a portion of the market to really justify the investment.




Will you benefit from Metal?  Yes, you probably will.  While you writing a renderer that takes advantage of Metal to run as fast as possible on A7 iOS devices really doesn’t make a lot of sense, for middleware providers, that isn’t the case.  Already Unreal Engine, CryEngine and Unity have announced future support for Metal and expect most other iOS game engines to follow suit.  So, if you are using a game engine, there are almost nothing but upsides to Metal’s announcement.  If you are a middleware provider, well, yeah… Apple just created more work for you.


Is there a downside?


Well, other than the work it generates for middleware/engine providers, there is certainly one possible downside to Medal.  Until now, especially with the success/clout of iOS, Apple has been a major influencer on the development of OpenGL.  Now that they have their own vendor locked alternative, and let’s not forget Apple LOVES vendor lock in when they are the vendor, it is possible OpenGL's development becomes much less of a priority to them.  At the end of the day though, Apple simply can’t dump OpenGL as the most likely result would be a mass of people dumping Apple.


The only other major downside I can think of is in regards to shader programming.  Right now most game engines simply use HLSL or GLSL shader languages.  Therefore when Unity, Unreal, CryEngine, et al.  finally do add Metal support, I will be interested in seeing how they handle shaders.  This is one area of work that could be thrust back on the poor indie developers.  In this regard, only time will tell.

blog comments powered by Disqus

Month List

Popular Comments