C++ Fast Track for Games Programming Part 1: Getting Started

C++ Fast Track

C++ Fast Track for Games Programming Part 1: Getting Started

Welcome to the first article in the Programming C++ Fast Track tutorial series! These tutorials are designed to take you from zero to a decent entry level in a somewhat smooth fashion. We start at the absolute basics: all that you need to get started is a laptop or PC, a fair bit of time, and quite a bit of dedication.

Previous Part: AINext Part: The Template

Regarding dedication: These tutorials are supposed to take you anywhere between two and four hours each. Aim to complete a minimum of 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, join the Discord channel https://discord.gg/gsxxaxc. You’ll have no problems getting answers to your newbie questions there. Lecturers and experienced programmers also roam this channel.

About the Authors

This course was originally created for the Games programme at Breda University of Applied Sciences (known as IGAD at the previously named NHTV); see https://www.buas.nl/games.
It was recently updated for the students of the Utrecht University as well; see https://www.uu.nl/en/organisation/faculty-of-science/education/bachelors-programmes.

This tutorial was written by Jacco Bikker, Brian Beuken, Nils Deslé, and Carlos Bott and updated for Visual Studio 2019 by Robbie Grigg and Phil de Groot.

Getting the Stuff You Need

For the purpose of these tutorials, I will assume you develop your games on PCs. The preferred development environment is Microsoft’s Visual Studio 2019. A free version (the Community Edition) of this software is available from Microsoft, via https://www.visualstudio.com/downloads.

Checklist:

  • A PC or laptop, pretty much any CPU and GPU will do
  • Windows 10 (32-bit or 64-bit)
  • Visual Studio 2019 Community Edition (Professional and Enterprise more than welcome), installed with default settings
Keep in mind you will want to install Visual Studio and programming projects on your fastest storage device – a super fast Solid State Drive (SSD) is preferred! Some people even go crazy and use RAM disks for their projects. This might not matter now but when you are hitting tens of thousands of Lines of Code (LOCs) it will save you a lot of time.

Starting Visual Studio 2019

When you start Visual Studio 2019 for the first time you are greeted with this window:

Visual Studio installation splash screen to sign in or not to sign in – that is the question…

Selecting not now, maybe later is luckily a perfectly viable option, so let’s go for that (no need to leave any more personal information with a tech giant than strictly necessary, right?). In the next window, you get to choose a theme. As the window says, you can always change this later, so let’s go with dark. Now we finally get into the Integrated Development Environment (IDE)

Create a New Program

Now that you have Visual Studio up and running, select the 4th option Create a new project as pictured:

Your first adventure will be to create a new simple project using Visual Studio.

Your first adventure will be to create a new simple project using Visual Studio.

You then need to select the type of project. Because we are building a very simple project then select Empty project as you can see here:

Starting with an empty project means we do not have to delete as many things later 😉

Starting with an empty project means we do not have to delete as many things later 😉

Even an empty project will create enough directories anyway. With this option you will have x86 (for 32-bit) and x64 (for 64-bit) options – essentially a C++ console application. In selecting an empty project we want to avoid adding any ATL, MFC or SDL stuff.

You now need to change a few things in the following dialog – this is all about where you place your files.

You may choose any folder you want to create your new project.

You may choose any folder you want to create your new project.

Set the Project name to Getting Started

Set the Location to C:\my_projects (or whichever folder you keep all of your programming projects).

It is not recommended to keep your projects in the Desktop folder (C:\Users\[username]\Desktop) folder or in your Documents (C:\Users\[username]\Documents) folder because these folders are indexed by the Microsoft indexing services to improve search performance. The indexing services will have a negative impact on the performance of the build process and for this reason, it is recommended to save your projects in a folder that is not being indexed by the indexing service.

Set the Solution name to C++ Fast Track for Games Programming

Click the Create button to create your new project!

You should see something similar to the screenshot below.

New project in Visual Studio

You should have an empty project.

IDE Tidy-Up

This section is completely optional but it is our preference to tidy up the IDE to make room to view the C++ source code.
Optionally, you can skip ahead to the Hello World section below.

As you can see, there is a lot of stuff on the screen. Let’s make some room:

  • Click on Team Explorer, then close it to get rid of it. The Team Explorer can also be hidden by selecting View > Team Explorer from the main menu.
  • Do the same to Toolbox and Properties.
  • Drag the Solution Explorer to the left of the screen.
  • If you don’t like toolbars and their buttons then on the main menu, click on View, go to Toolbars, and deselect Standard.

You should now have something like this:

New project in Visual Studio

Almost there…

I often see people work on the area of a postage stamp (not just when programming) due to all the toolbars: this layout prevents that. We didn’t remove anything that we need (apart from one thing), and we assumed control of the software in the process.

The one thing we are missing is two drop-down boxes (OK, so two things). We can store these next to the menu bar, so they don’t need their own toolbar.

In the main menu, select Tools > Customize and select the Commands tab. Now click on Add Command, select the Build category, and choose the Solution Configurations command. This adds the drop-down box to the left of your menu bar; click the Move Down button a few times, until it is all the way to the right. Repeat this for the Solution Platforms command.

The top of the screen now looks like this:

Now your IDE has some space to breath!

Now your IDE has some space to breath!

And the IDE is as tidy as it gets for now.

Solution Explorer Tidy-Up

Your Solution Explorer should currently look like this:

Solution Explorer

Your ‘solution’ (although you didn’t solve anything, but whatever) should look like this now.

Now, let’s delete some things we don’t need: Select all three folders (Header files, Resource files and Source files and delete them.

From the main menu, select Tool > Options and expand Text Editor > C/C++ > Advanced option or search for “Disable External Dependencies Folder” in the Search Options (Ctrl+E)

Set the “Disable External Dependencies Folder” option to true.

Your solution explorer should now look something like this:

Clean Solution Explorer

Your solution explorer should be totally clean now.

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!

Now it’s finally time to add a C++ source file to play with. Right-click on your project Getting Started in the Solution Explorer and select Add > New Item.

In the Add New Item dialog that appears, select C++ File (.cpp), and name it main.cpp (or anything else really, as long as it ends with .cpp). Then click the Add button.

Add New Item dialog box

We just need the one .cpp file for now.

The new file is immediately opened, and we’re ready for some coding.

Hello World

A tutorial on C++ is not complete without a ‘hello world’ example, so here we go. Enter the following program:

You can start the program by hitting F5. Visual Studio will ask you if you want to build the program; you want this so click yes.

You should see a console window with the text Hello world! printed in it.

Hello world console window

You should see a console window with the text “Hello world!” printed in it.

Press Enter (while the console window has the keyboard focus) to close the console window.

Discussion

When you go to D:\Projects\C++ Fast Track for Games Programming (or wherever you saved your Visual Studio solution files) you will see that Visual Studio created a large amount of files for you. The most interesting one is in the Debug folder, and it’s called Getting Started.exe. When you start this application, you will see that you created it yourself.

Apart from this file, we have:

  • C++ Fast Track for Games Programming.sln: your solution file, which points to
  • Getting Started.vcxproj: your project file, which points to
  • main.cpp: the source code file.

A project can have multiple source files, and a solution can have multiple projects. Other files:

  • Getting Started.vcxproj.filters: stores the references to all of the source files in your project;
  • Getting Started.VC.db and opendb: some internal information for Visual Studio;
  • various other files in the Debug folder: .obj, .ilk, .pdb.

Quite confusing perhaps, but all that matters right now is the .cpp file in Projects\C++ Fast Track for Games Programming\Getting Started folder and the executable that it was built from it.

Solution Folder

It is always good to understand what each file is for – especially when it comes to working out which ones you need on GitHub or Perforce (hint: Never commit compiler generated content to version control!)

If you do not see the .vs folder as shown in the screenshot above, make sure you you select “Show hidden files, folders, or drives” in File Explorer Options in windows control panel.

To change this setting, open the Windows control panel and go to File Explorer Options, then the select the View tab, and select the Show hidden files, folders, and drives radio button.

If you don’t see file extensions (.sln, .ccp, and .h) in the File Explorer, make sure the Hide extensions for known file types is not checked as shown in the screenshot below.

File Explorer Options

Assignment

So, here’s your task:

  1. Every article in this series will end with a small practical assignment. You need to complete this assignment. Feel free to share your solution on the 3dgep.com Discord server: (https://discord.gg/gsxxaxc).
  2. Create an executable that prints your name 10 times, then waits for a key, then prints Coding is awesome! 10 times, then waits for a key again, then exits.

Previous Part: TitlesNext Part: The Template

31 thoughts on “C++ Fast Track for Games Programming Part 1: Getting Started

  1. Are there any restrictions on how the exercise should be resolved? Or can we use everything we want (for example, add some #include for string manipulation)?

  2. I’ve notice two “.vs” folders one on solution level and the other on project level.
    In order to use version control properly should I add the “.vs” folder to my gitignore file?
    Thanks!

    • Isaac,

      Generally, you can safely ignore hidden files and folders and files that are generated by the IDE. The .vs folder both hidden (by default) and generated by the IDE. In this case, I would highly encourage you to ignore the .vs folder by adding it to your .gitignore file.

  3. First of all thank you in advance for the high quality info your are putting here! Second, is it a problem to do the classes/tutorials using a mac, for example on (Visual Studio for Mac)? Thanks in advance!

    • Djakson,

      The tutorials (and the corresponding source code that is provided) are tested on Windows. Using other platforms is not recommended (but may be possible).

  4. Just as Djakson said, thank you so much for the professional content that you’re providing here. While I will follow through with the course without a doubt, I was just wondering if there’s any way for me to get a certificate for it.

  5. i ave just started this course.. and the comment at the end says :
    “Every article in this series will end with a small practical assignment. You need to complete this assignment, and send the result to one of the programming teachers. Once you have done so, you may continue with the next part.”
    how do i do this? or was this part of the original text for the original course : “This course was originally created for the Games programme at Breda University of Applied Sciences (known as IGAD at the previously named NHTV)”

    should i just ignore this “requirement”?

    • just in case.. I thought I would cheat.. and create :

      By the way – this generates one warning because the return value of getchar() is completely ignored.

      • This is not cheating, this is a perfectly valid solution! This is the first time I’ve seen someone solve this with a nested for-loop. It’s a bit convoluted, but it is functional.

  6. I got an LNK2019 Error that I don’t know how to solve. From what I understood this has something to do with the fact that it can’t find the definition for the main symbol anywere. But knowing this has not made me able to resolve a solution.

  7. I will be following this course… Because I’ve wanted to use C++ to put a sprite on the screen for a long time now. That’s always been the hard part and it seems you guys get to sprites VERY quickly in this course!

    Anyway… Besides just… typing out the print command 20 times to do the final task… Here’s some sloppy code I copied from elsewhere to do it with a loop.

    Runs fine on my comp XD

    I think it has some extra includes it doesn’t need, but it runs.

    Thanks for this guys. Once I can control sprites I will be off to the races.

  8. #include <stdio.h>

    void main()
    {
    for (int i = 0; i < 10; ++i)
    {
    printf("Lynn\n");
    }

    getchar();
    for (int i = 0; i < 10; ++i)
    {
    printf("Coding is awesome!\n");
    }

    getchar();
    }

    • erm this doesn’t seem quite right, how do I get it to be formatted as code (like in the other comments)?

      Also my #include disappeared D:

  9. Hi! I was wondering if we can use the version of visual studio code, and if I can use the unreal engine for the assignment?

  10. Hey here is the solution for the assignment.
    #include
    int main() {
    for (int i = 0; i < 10; i++) {
    std::cout << "Suraj\n";
    }
    std::cin.get();
    for (int i = 0; i < 10; i++) {
    std::cout << "Coding is Awesome \n";
    }
    std::cin.get();
    return 0;
    }

  11. The solutuion I found online that some one posted
    #include “stdio.h”

    void main()
    {
    int I = 0;// This is the first value that get printed
    do
    {
    printf(“hello world\n”);
    getchar(); // This enter a new line
    I++; // this will help increase the value , in this context
    }
    while(I < 10); // This 0 – 10, and will print the amount number before 9
    }
    The I++ increase the value meaning the text the that we want to print.
    Do is self explanatory,
    The int I = 0 , the 0 represent the first value, while(I < 10) ,this mean from 0 to 10( First to tenth value) 0 is less than 10 , this declare that each Text(Hello world)
    up to 10 times
    While looking at people response , your response to them, took me to w3 school(which I'm familiar with) and there's version of this which short and simple:

    for (int i = 0; i < 10; i++) {
    std::cout << "Coding is awesome!" << "\n";
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.