Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon Join the GFS Discord Server!
13. January 2012

 

 

 

Sadly SFML only included precompiled binaries for 1.6 and even in that case, they don’t support Visual Studio 2010.  If you need to build SFML 2.0 for use with Visual Studio 2010, use the following step.

 

 

Go to this page and download the SFML 2.0 snapshot.

 

 

It’s a tar.gz file, if using 7zip, it means you will have to extract it twice.  Extract it to a folder somewhere on your hard drive, the results should look like this:

 

image

 

 

 

Now you need CMake.  Download and install it from here.

 

 

One installed, the next step is slightly tricky.  CMake needs to be run with the environment variables for Visual Studio properly set so it can locate your compiler.  This means you need to launch if from the command prompt provided by Visual Studio.  If you are using Visual Studio Express, in the start menu launch the Visual Studio Command Prompt.

 

 

image

 

 

 

Now that you’ve launched the command prompt, change directory to your cmake executable folder.  In my case it was c:\Program Files (x86)\Cmake 2.8\bin.  CD to that directory then run cmake-gui.exe.

 

 

 

image

 

 

 

The CMake GUI will now pop up.  Click “Browse Source” and navigate to the folder you extracted SFML2 to.  Then click “Browse Build” and navigate to where you want it to create all the project files, like I have below.  Once done, click configure.

 

 

 

image

 

 

If the directory you selected  doesn’t exist, the following dialog will appear:

 

 

image

 

 

Simply click Yes.

 

 

Now you are going to be prompted for what kind of project to generate, assuming you are using Visual Studio 2010 Express, select Visual Studio 10 then Finish, as follows:

 

 

 

image

 

 

 

If everything went ok, it will look like this:

 

 

image

 

 

 

The default settings are most likely what you want, now click Generate.  If all things go correctly, your project files will have been generated in the folder you specified in “Where to build the binaries”.  Here is mine:

 

 

 

image

 

 

 

Now simply double-click SFML.sln.

 

 

Visual Studio will load, now all you need to do is select the menu item Build->Build Solution in Visual Studio.

 

 

Voila!  You just built SFML 2.0 using CMake and Visual Studio 2010.  Look for the binary files in the lib folder.  Keep in mind the include and extlib files are required too, and are in the directory you extracted to earlier.

 

 

If that didn’t work for you, you can simply download this version I've compiled.  Keep in mind, SFML 2.0 is under constant development, so this version was only current as of 1/13/2012.  This archive also included the Include folder as well as the extlib folder, which is all you should require to get started with SFML2.

Programming


31. December 2011

 

 

As the title says, the 9th part of our C++ game programming using SFML tutorial is now live. In this chapter we implement a caching solution for dealing with SFML game audio files. Along the way we learn a bit about C++ exception handling as well as touch on the subject of C++ templates. We also implement our second paddle and give it the most basic of artificial intelligence.

 

 

 

As the majority of this chapter is audio related, this image really isn’t all that impressive, but here is our current game in action.  We are very near to a complete game at this point and have covered most of the basics of C++!

 

 

pang9b

 

 

 

 

You can access part 9 by clicking here.  If you haven’t read any of the tutorial yet, you can access the table of contents here.  Again, any and all feedback appreciated.

Programming


22. November 2011

 

 

Continuing the long standing ( and very cool ) tradition of releasing id source code a number of years after being released to market, the Doom3 engine/game source code has been made available on GitHub.

 

 

I have only had the chance to peruse it briefly, but I have to say what I saw was very clean, and shockingly enough C++!  After seeing prior id code, I simply figured it would be straight C for some reason.

 

 

Anyways, I highly recommend you check it out.  Clean, complete, professional quality source code isn’t made available every day, and Carmack really is one of our day’s brilliant minds.  I know I will be doing so in more detail shortly!

 

 

Now I cant wait for someone to port Doom 3 to my toaster…

Programming


20. November 2011

 

 

Handling game time is problem that almost all games have to deal with.  A very good question recently came up in my C++ game from scratch tutorial about why I didn’t normalize the players movements which reminded me of a post on the subject.

 

 

Years ago Shawn Hargreaves of XNA ( and Allegro ) fame blogged about how XNA handles the Update and Render loops.  I simply post it here again because it is one of the most succinct posts I have encountered on the subject.  So, if you are looking into creating a game and need to figure out how to implement the game loop, I recommend you give it a read.

 

By default XNA runs in fixed timestep mode, with a TargetElapsedTime of 60 frames per second. This provides a simple guarantee:

  • We will call your Update method exactly 60 times per second
  • We will call your Draw method whenever we feel like it

 

Digging into exactly what that means, you will realize there are several possible scenarios depending on how long your Update and Draw methods take to execute.

 

The simplest situation is that the total time you spend in Update + Draw is exactly 1/60 of a second. In this case we will call Update, then call Draw, then look at the clock and notice it is time for another Update, then Draw, and so on. Simple!

 

What if your Update + Draw takes less than 1/60 of a second? Also simple. Here we call Update, then call Draw, then look at the clock, notice we have some time left over, so wait around twiddling our thumbs until it is time to call Update again.

 

What if Update + Draw takes longer than 1/60 of a second? This is where things get complicated. There are many reasons why this could happen:

 

  1. The computer might be slightly too slow to run the game at the desired speed.
  2. Or the computer might be way too slow to run the game at the desired speed!
  3. The computer might be basically fast enough, but this particular frame might have taken an unusually long time for some reason. Perhaps there were too many explosions on screen, or the game had to load a new texture, or there was a garbage collection.
  4. You could have paused the program in the debugger.

 

We do the same thing in response to all four causes of slowness:

  • Set GameTime.IsRunningSlowly to true.
  • Call Update extra times (without calling Draw) until we catch up.
  • If things are getting ridiculous and we are too far behind, we just give up.

If you think about how this algorithm deals with the four possible causes of slowdown I listed above, you'll see it handles them all rather well:

  1. Even if the computer is too slow to run Update + Draw inside a single frame, chances are that Update + Update + Draw will fit into two frames. The game may look a little jerky, but it will still play correctly. If the programmer is particularly smart they might even notice that we set IsRunningSlowly, and automatically reduce detail or turn off special effects to speed things up.
  2. If the computer is way too slow (ie. if the Update method alone is too slow to fit into a single frame) there isn't really much we can do, other than set IsRunningSlowly, cross our fingers, and hope the game might do something clever in response to that. Most of the time, though, if you find yourself in this situation you just need a faster computer!
  3. If a particular frame happens to take unusually long, we automatically call Update some extra times to catch up, after which everything carries on as normal. The player may notice a slight glitch, but we automatically correct for this to minimize the impact.
  4. Pausing in the debugger will leave the game a long way behind where the clock says it should be, so our algorithm will give up, accept that it has lost some time, and continue running smoothly from the time execution was resumed.

 

 

Shawn’s blog in general is a very good read, but this this post in particular is one that I seem to keep coming back to.

 

For the record, Pang from the C++ tutorial does not gracefully handle hitting a breakpoint ( it adds a layer of unwanted complexity for learning purposes ), so will do downright stupid things when it hits a breakpoint causing it to pause for a while.  I believe on the next frame it will cause your movement to be really really really far.  It would be as simple as adding if(elapsedTime > someReallyBigValue) startTimeOver() if you really wanted to fix this.

 

 

Sorry for digging up the past, now back to your regular broadcast!

Programming


14. November 2011

 

Chapter 8 of the GFS beginner C++ tutorial, Pang! is now live and can be accessed here.

 

 

This chapter represents a bit of a break from the norm, in that it deals with code design more than it does actual SFML and game implementation.  I actually had a great deal of fun writing this chapter, but the end result is very little usable code.  There is a companion post to this one that illustrates much better use of SFML’s audio classes, that should be up shortly.  That said, I think you could learn a great  deal from this post, it may even alter the way you program!

 

 

Instead this post introduces the concept of design patterns and illustrates a way to de-couple  your code, so you don’t end up littered with global and manager classes.  It covers a concept that I have never seen covered by a game tutorial before, but then, there might be a good reason for that! Winking smile

 

 

So give it a read and let me know what you think.  Would you like to see more posts like this, or would you like me to focus on more implementation specific aspects?

Programming


See More Tutorials on DevGa.me!

Month List