Welcome to the first article of Learning C++ tutorial series, provided by the IGAD program of the NHTV University! These tutorials are designed to take you from zero to block 3 entry level of IGAD's program in a somewhat smooth fashion. We start at the absolute basics: all that you need to get started is some decent equipment, a fair bit of time, and quite a bit of dedication.
Regarding dedication: These tutorials are supposed to take you anywhere between two and four hours each. Students enrolled in IGAD's program are supposed to complete two tutorials per week. That means that you have an extra workload of 4-8 hours. No-one said this was going to be easy, right?
If you need support while going through these articles, please don't hesitate to use the DevMaster.net forums. You'll have no problems getting answers to your newbie questions there. Many experts roam these forums, so chances are that your question will be answered by quickly.
A quick blurb about us: IGAD stands for "International Game Architecture & Design". We are a Dutch accredited course for game development, ran almost exclusively by teachers with game industry experience. We started in 2005, and so far, it's awesome.
About the authors
This tutorial is written by Jacco Bikker, Brian Beuken, Nils Deslé, and Carlos Bott. Look us up on the internet to find out about we did and still do related to games development.
Getting the stuff you need
At IGAD, we develop our games primarily on PCs. The preferred development environment is Microsoft's Visual Studio 2008. If for whatever reason getting the real thing is a problem for you, you can also try Microsoft's free version, Visual Studio Express. Note however that some things may work slightly different in that version. So, while you figure out how to obtain the correct version, download a fully functional trial from Microsoft by following this link: http://go.microsoft.com/?linkid=7701859. This will get you a 3.3GB .iso file (a DVD image). You can burn this image using most DVD burning software, or, alternatively, you can mount the image using e.g. daemon tools: http://www.disk-tools.com/download/daemon.
Apart from Visual Studio, you are going to need the DirectX SDK. At the time of writing, the DirectX SDK could be obtained here: http://msdn.microsoft.com/en-us/directx/aa937788.aspx. Click the first link (March 2009 version). If that link fails, search the microsoft website for the SDK.
- Visual Studio 2008 full or trial (at least for now)
- DirectX SDK March 2009 or later
- Both installed to their default directories
Note that this software will run well on XP 32-bit, Vista 32-bit and Windows 7. Using a 64-bit OS may make some things a little more complex, but you should be OK.
Setting up Visual Studio
If you take some time now to setup Visual Studio properly, it will make your life easier. Have a look at this screenshot:
This is probably quite a bit simpler than what you have right now. To make your VS look like this, first go to Tools ==> Customize. This will open a window, but it will also allow you to drag most elements of the tool bar. Remove anything that you don't see in above screennshot by dragging it away from the tool bar. Then add the stuff that you are missing:
- The box that has 'Release' in it can be found under Commands ==> Build, it's called 'Solutions configurations'.
- The box that has 'Win32' in it can be found under Commands ==> Build as well; it's called 'Solutions platforms'.
- The box with 'checklist' in it is a search box. It can be found under Commands ==> Edit, and is called 'Go to find combo'.
- The remaining icons can be found under Commands ==> Debug.
Close all toolboxes, explorers and windows, Close all toolboxes, explorers and windows, except for the 'Solution Explorer' (again, as in the screenshot above).
Then, change the following settings under Tools ==> Options:
- Environment ==> Fonts and colors: Change the font for the text editor to Lucida Console, size 9. You can change more here, depending on your taste, or lack thereof.
- Environment ==> Startup: Select 'Load last loaded solution' in the 'At startup' box.
- Projects and solutions =>> VC++ directories: Select 'Include files' in the right drop-down box. Now create a new line, and set it to the include directory of the DirectX SDK (e.g., C:\Program Files\Microsoft DirectX SDK (March 2009)\Include).
- Projects and solutions ==> VC++ directories: Select 'Library files' in the right drop-down box. Create a new line, and set it to the lib directory of the DirectX SDK (e.g., C:\Program Files\Microsoft DirectX SDK (March 2009)\lib\x86).
- Text Editor ==> C/C++ ==> Tabs: Set 'indenting' to 'Block'.
You can change some things later, but at least now you know where to find them.
Creating a program
Before we go on:
"This is the first and only article in these series that is this boring. Starting with part 2, you will be coding, not downloading + installing + adjusting settings. Promise."
That being said, let's get coding!
From the File menu, select New, then Project:
You need to change various things in this dialog. Set the name of your project to 'part1' (or use your imagination). Set the location to c:\my_projects (so you can actually find them). Unselect 'create directory for solution'. It will create enough directories anyway. Finally, make sure you selected 'Win32' and 'Win32 Console Application'. Then click OK. In the next window, click 'Next' (not Finish). In the next window, tell VS that you want an empty project, without any ATL or MFC stuff. Now click Finish.
Your 'solution' (you didn't solve anything, but whatever) should look like the image on the right now.
Now, let's delete some stuff we don't need: Select all three folders (Header files, Resource files and Source files) and delete them. Now it's finally time to add a source file to play with. Right-click on 'part1' and select Add ==> New Item. In the dialog, select 'C++ File (.cpp)', and name it 'main.cpp' (or anything else really). Then click 'Add'. The new file is immediately opened, and we're ready for some coding.
A tutorial on C++ is not complete without a 'hello world' example, so here we go. Enter the following program:
printf( "Hello world!
You can start the program by hitting F5.
When you go to c:\my_projects\part1, you will see that VS created a large amount of files for you. The most interesting one is in the 'Debug' folder, and it's called part1.exe. When you start this application, you will see that you created it yourself.
Apart from this file, there are 'manifests', 'program databases' (pdb), 'dependencies' (dep), 'object files' (obj), a buildlog and so on. Quite confusing perhaps, but all that matters right now is the .cpp file in c:\my_projects\part and the executable that it was turned into.
Every article in this series will end with a small practical assignment. To get the most from this tutorial, you will need to complete this assignment, before you continue with the next part. Make sure to ask for help on the forums if you get stuck.
So, here's your task:
Create an executable that prints your name 10 times, then waits for a key, then prints 'IGAD rules!' 10 times, then waits for a key again, then exits.
In the next article, we will go over a project template that we will be using throughout the series. This will help to focus more on the core concepts and game development without being distracted by platform-specific details. Stay tuned!