One-week-game: getting ready

Ok, so if you want to benefit the most from the one-week game I’m going to “live develop”, the best thing you can do is to follow and develop along. You can just read the source code and other materials I post, but nothing beats doing it with your own hands too, and seeing the thing grow from nothing into a cool little game.

Let me review the two most important things now: the previous knowledge you should have, and how to set up your development environment.

Required knowledge

First thing, you need to know some programming. It’s impossible to get up to speed from zero into game development in one week.

But if you have some experience programming in nearly any common language (java, javascript, python, php…), then it should be really easy for you to get up to speed.

We are going to use the C language, in its most basic form, without using pointers. Here is the list of C features we are going to use:

global and local variables: char, int, float, bool

enums

functions and function declarations

expressions, operators, assignments, statements

control-flow: if-else, while, for, break, continue, return

comments

arrays

structs

typedef

preprocessor: #define, #include, #ifdef/#endif

file access (functions open(), read(), write(), close())

Hopefully this should be pretty easy to grasp in a few hours. Here are some link to the online C tutorials that look best after having a quick look at the top Google results:

Now, you should have a bit of basic math knowledge, basically some geometry and algebra. Here is what we are going to use:

2D coordinates and coordinate systems

Vectors, vector addition and subtraction, scaling, distance measures

I will try to completely avoid calculus and trigonometry, but I’m not 100% sure I’ll be able to. If you need it, just understanding sine and cosine should be sufficient.

Although we are going to use it, you don’t need need any previous OpenGL knowledge. We will explain it as it is used.

Development environment: OS X

You can follow along easily on OS X. You need a Mac with a reasonably recent version of OS X. I’ve tested things on 10.7 (Lion) and 10.8 (Mountain Lion), but you should be able to use anything from 10.5 and up.

You need to install the following:

Xcode. It’s free to install from the Mac app store, so you can probably install the latest one (I don’t recommend the Xcode 5 developer preview). I’ve tested versions from 4.3 and up, although it’s likely old versions will also work, since we’re not using anything cutting edge here.

Xcode command-line tools: once Xcode is installed, go to its preferences dialog, select the “Downloads” tab, and install the command line tools.

GLFW library: you need to install the GLFW library, which is one of the best ways to do OpenGL apps on OS X nowadays without using Objective C. It has to be installed from source. We are going to use version 2.7.9, to totally avoid pointers (not doable with GLFW 3.0). Download glfw-2.7.9.zip from http://sourceforge.net/projects/glfw/files/glfw/2.7.9/. Uncompress it in some temporary place, go there with the shell, and type “make cocoa”, then “sudo make cocoa-install”. [NOTE: A reader over at Reddit suggests that if you’re using Hombrew, typing “brew install glfw” will do the whole thing. Haven’t tried, but it looks like it should work, and it’s GLFW 2.7.7, which is fine. Good luck!].

Graphics tool: to generate the type of graphics we will be using (32-bit BMP files with alpha), you need to install the free Paintbrush tool from here: http://paintbrush.sourceforge.net , which is able to generate the format we want. Other tools probably can generate it too.

In Build Settings, and enter “/usr/local/include” for Header Search Paths and “/usr/local/lib” for Library Search Paths (for Xcode to find the GLFW library)

Also add the options “-lglfw” to the “Other Linker Flags” setting

Select the “Build Phases” tab, open “Link Binary With Libraries”, and add the following frameworks: OpenGL, OpenAL, IOKit and Cocoa

Mute your speakers! The sample makes some ugly noise.

Now it’s ready, build with Cmd+B and run with Cmd-R. Be careful as it will make an ugly noise! You should see a rotating square on the screen and hear some noise. If so, you’re ready. If not, check all steps, and if you can’t fix it, post in the comments below.

Development environment: Windows

Windows XP or later will do, on basically any less than 8 years old. You will need the following:

Install a version of Visual Studio with C++ support. Even VS 2003 should work. You can download and install a Visual Studio Express edition for free from Microsoft: http://www.microsoft.com/visualstudio/eng/downloads. I have verified that either “Visual C++ 2010 Express” or “Visual Studio 2010 Express All-in-One ISO” will work. Probably the VS 2012 editions will too, let me know if you try.

Open Visual Studio, select “File, New Project”, “Visual C++”, “Win32 Project”, choose whatever name (I went “SCTest2”), including “Create New Solution”, then “Windows Application” in the settings. Once created, substitute the contents of the main file (SCTest2.cpp in my case) with the following:

In “Configuration Properties”, “General”, setting “Character Set”, set it to “Use Multi-Byte Character Set”.

In “Linker”, “Input”, “Additional Dependencies”, add “opengl32.lib;openal32.lib;” to the front.

Mute your speakers! The sample makes some ugly noise.

We should be done now. Check building it with “Build”, “Build Solution”, and then check running it with “Debug”, “Start Debugging”. You should see a Window with a rotating pattern, and noise coming out from your speakers. If so, congrats! You’re ready.

Development environment: Linux

I haven’t had the time to check this, but it should be simple if you install GLFW (I think with the same instructions as for OS X above), and OpenGL & OpenAL (use your package manager to search, “apt-cache search openal” or “yum search openal” should help, and there is some help on StackOverflow too).

A note on C and C++

C++ is basically an extension of C, adding object-orientation and other advanced features. Anything you code in C can be compiled as C++. I am not going to use any feature of C++, I am going to compile all our code as C++ just to make use of two minor things from C++:

Easy use of inline functions

Use of struct/enum types without typedefs or prepending ‘struct’ or ‘enum’ to all declarations

So, technically, we are already using C++ (although barely so). If you follow down the road we’re setting up, you will be moving to using more and more C++ in the future, so it’s not a bad thing. But you better know the details in case someone asks!

Questions?

If you have any question, or any issue getting this to work, just post a comment below and I’ll try to help. Good luck!

And if you want to be notified when new articles to help you become a games developer are ready, just fill in the form below:

Thanks Ilanders, you actually caught me with an intermediate version of the code, while I was doing tests & last minute changes… bad of me to publish and then review! I will add a more prominent mention about speakers 🙂

This took me all of 5 minutes to get the project set up and build/run the test on Mac OS X Lion. As llanders noted there is the invalid syntax error. The only other minor issue I ran into was that I didn’t know where to find “Build settings” since I am not typically a Xcode user.

Ilanders, antisyzygy, thanks, you were both right, I had fixed the issue in my copy of the source code but not in the one embedded in the article… fixed now.

Indeed follow antisyzygy’s link above to access “Build settings” in Xcode. Hopefully the explanations above are enough without screenshots for every minor step. If there is any other issue, just post a comment and I’ll try to clarify, or edit the article.

No prob, I’m grateful, any extra help you can provide to others is more than welcome! And I really hope that you and others can get from this series the experience to actually get your projects through the finish line afterwards.

When I click on “Include Directories”, it doesn’t edit the box, it highlights the entire thing. So do I replace the string that is in there, or do I just want to place your property at the end of the field?

I tried simply replacing everything and completed the rest of the directions and had tons of errors when I compiled.

Hey Jon,
I’m all set up to start 🙂
I don’t know how difficult the graphics are going to be, but I suggest that everyone uses pinta ( http://pinta-project.com/ ). It’s inspired by paint.net, but it’s available on Windows, Linux and OSX, so you don’t have to do extra work to show how to do something on each platform. Unless, of course, there’s something about pinta that doesn’t go well with your workflow.
Whatever the case may be, I’ll be following you throughout this project, hoping that I’ll finally get to the stage that I can create my own games.

First of all, thanks for this course. I’m a programmer and I’ve always been interested in game programming but I never had the time to learn it properly, so I’m looking forward to learn as much as I can.

Just a little question: could it be possible to use Dev C++ in Windows instead of Visual Studio? It’s not a problem for me to use VS, I was just wondering if I could use Dev C++.

We are not doing anything weird, so I guess it’s usable. I seem to remember someone was trying to and possibly managing to. Unfortunately I’m not familiar with Dev C++ myself so I can’t really help much.

I’ve managed to call OpenGL with the instructions I found on this website: http://www.zeuscmd.com/tutorials/opengl/02-SettingUpYourEnvironment.php I paste the url here in case someone else wants to work with Dev C++, after following these instructions I executed the above sample program and it ran smoothly, with no warnings or errors, and displays the animation correctly,

As for OpenAL SDK I can’t get it to work. I installed the SDK and added the libraries to the project but no sound is played when I run the sample program.

This looks like a fun project to jump on so thanks for doing this. I’m headed back to school in a week, and this is a very engaging way to review material I might not touch otherwise, but I might try to pull in other topics fromC++ in addition to what you are doing.

Jiffygast, that error means VS is not able to find the OpenAL library file.

First thing, locate where the SDK was installed – by default, it’s in a subdirectory under “Program Files”, but it could be “Program Files (x86)” on your system, or something different. Just search for openal32.lib in your hard drive.

Second, we gotta tell VS where to find it. That’s what the modified “Library Directories” entry is in the VC++ Directories area. Make sure the first entry before the first colon is exactly the path where the openal32.lib file is. Copy it with Ctrl-C and paste it in the address bar of an explorer window if necessary, to make sure it’s fine.

Eh, hate to be a bore, but it’s still not working for me 🙁
I’ve got the directory paths in there right, I’m quite sure, and it has no problem finding the include files. I can see the openal32.lib sitting in the libs\Win32 folder in my explorer, but VS isn’t for some reason, it seems.

I’m having the same exact issue. The .lib file is in the right place. The ‘include directories’ and ‘library directories’ both include the correct paths, but I still get the ‘OpenAL32.dll was not found’ error. Any solution to this yet? I’m sure I’ve followed the exact directions specified this far.

Edit:
I uninstalled and reinstalled OpenAL, making sure not to include the helper thing and I also took the spaces out of the “OpenAl 1.1 SDK” part, so that it now looks like “OpenAl1.1SDK”. I rebuilt it and ran the debugger and it worked… Which was weird because I had just uninstalled it and reinstalled it under a new directory and the old solution still had the same properties from my first attempt… (IE the path with the spaces in it) What’s with that? How could that possibly work?

I remade the test project and ran it again and everything worked this time… So unless I’m overlooking something, the problem was with one of the following things:

1. The first time I installed OpenAl I might have included the help files. The second time I did not. (What are these anyway?)
2. I changed the installation directory name to leave out spaces. I then changed the properties accordingly.
3. I might have made a typo or some other error the first time I was changing the properties.

Not working for me still :/ i found the file in the explorer window, and copypasted the path into the VC++ Directories area, and made sure to add the $ at the front and the ; at the end. Im not really sure what else i can do here. any suggestions?

When I attempt compile and run the test program I get an “error C1083: Cannoto open include file ‘al.h’: No such file or directory,” and subsequent errors relating to the missing AL library.

When I installed the OpenAL SDK I made sure to install the redistributable, but a separate installer didn’t pop up after I pressed “next”, so I’m not really sure if that worked. Do I need to manually put the OpenAL header files on a special VS path or something to get it to work? I was under the impression the SDK installer would put them in the right place out of the box.

Similar to the issue Jiffygast has above, this means VS is not able to find the files. On Windows, SDK files are typically installed in their own path (OpenAL defaults to a directory under Program Files), and then you have to configure your compiler to make sure it finds them. This configuration is as simple as a list of directories where the compiler should look for header files and library files. That’s what I am modifying in the “VC++ Directories” above.

So the way to fix it should be simple: find where in your disk drive OpenAL was installed (in the worst case you can resort to searching for al.h in your hard drive), and then making sure that directory is configured in the list “Include Directories”. Hope that helps!

You will get actual errors instead of warnings once we add sound support. The issue is most likely in the “Library Directories” setting, make sure it’s pointing to the directory where OpenAL installed the .LIB files.