How do I make a game?

Allegro

Allegro is an open source C++ library that makes it easier for you when you want to program a game. A good introduction for learning this library can be found here. An online Allegro community can be found here.

Information about the Windows 32 API can be found here.

SDL

SDL is a free cross-platform multi-media development API that is used for game programming in C++. For tutorials visit one of these sites:
http://www.sdltutorials.com/
http://lazyfoo.net/SDL_tutorials/index.php.

 

Useful books for making your first computer game

I am reading below books, because I like to know more about game programming, especially 3D DirectX programming. I first read Michael Morrison's book, because that is really very easy to follow and you learn a lot about C++. DirectX is more complex and you need to learn about vectors and matrices for example. I learned about this a long time ago at school during math lessons.

However, DirectX is much fun once you can handle it. For the beginner I would not recommend to start with DirectX right away, you first have to learn the basics of C++ programming and you'd better start with Michael Morrison's book.

Michael's book is oriented towards making 2-dimensional games. It's not explaining DirectX.

For making tiles in a 2D game you probably want a tile editor. Tiled Map Editor is free. I've not used it yet, but I think it's very useful. Another one is Mappy.

When you're new to C++ programming you can learn more about it here or here.

In order to start programming DirectX, you need to have a C++ compiler like Visual Studio, free Visual C++ 2010 Expres, Borland C++ Builder, Microsoft Visual C++ 6.0 or free Dev-C++. It's also possible to program DirectX in another programming language, but I prefer to start first with C++, because of the performance of the compiled code.

For DirectX programming you also need the DirectX SDK. I'm starting out with DirectX 9, but you can also choose a newer version if you like. The SDK is packed with much information, examples and tutorials.

I know there are also other ways of making games like the XNA game development environment and Unity. Unity is a visual game development environment, so I assume it's not as complicated to learn as DirectX. However, I want to learn about DirectX because I want to study the basics first in order to understand other frameworks / environments better maybe later on. Also I like to improve my C++ skills.

I am studying Frank Luna's DirectX 9 book and succeeded making my first spinning cube that is running in DirectX. It's very simple and nowhere near to a game, but I learned a lot while studying. As you can see, the cube is made up of several triangles, because that's the native graphic object being used by DirectX.

directx cube

When building this in Visual Studio at first I was not able to compile it, but the reason for that was that a new project / solution made use of the unicode characterset (see: project properties - configuration properties - general - character set). After I changed this into 'Not Set', I was able to compile and run the example.

I also got an error when compiling a certain example stating: library file libcp.lib could not be opened. This was easily solved by adding libcp.lib to the following project property setting: configuration properties - linker - input - ignore specific default libraries.

Please note you also have to include the SDK library and header paths in your project properties (configuration properties - VC++ directories - include / library directories) in case you use Visual Studio.

For the include path you should add: $(DXSDK_DIR)Include
For the library path you should add: $(DXSDK_DIR)Lib

Further you have to specify the d3d9.lib, d3dx9.lib and winmm.lib files in the in your project properties (configuration properties - linker - input - additional dependencies).

After you specified all these settings you should change the configuration drop down box in your project settings dialog into 'All configurations' before you save your new project settings. By doing this, each time when you create a new project you do not need to specify all this settings again.

By the way, DXSDK_DIR is an environment setting that refers to the directory in which you installed your DirectX SDK. This setting is automatically created for you when you installed the DirectX SDK. You can verify that this is the case when you type in a console window:

set

DXSDK_DIR should be in your list of settings. N.B. A console window can be opened by typing cmd in your Windows searchbox (Windows 7) or Start - Run (Windows XP).

Visual Studio warned me that the project was out of date when I compiled the example, but I just ignored this message. I think it's because of the changed characterset. Unicode is commonly used nowadays for new normal Windows applications, however under DirectX programming using this characterset resulted for me in compile errors.

Programming DirectX is really fun, but it takes a lot of time to learn and making a 3D-game.

Below you see another example of drawing colored triangles in DirectX. I know it's not really very interesting to draw a triangle, but the sourcecode that created this example is really very interesting. It's all in Frank Luna's DirectX 9 book.

directx colored triangles

Here's how you should setup Visual Studio for making use of the DirectX SDK.

On this site you can find more information about DirectX programming.

Creating Meshes

DirectX can read files called mesh-files. For DirectX these files have a filename extension .x. When you want to create a game you need a mesh editor e.g. for creating terrains, game-characters or animations. I found a great tool called Blender, which can be downloaded for free here. I need to learn more about this tool, because it looks like you can do a lot with it. At first sight it looks awesome and probably you don't need paid tools like 3d Studio Max, Maya or Lightwave in order to create meshes. I already found out you can export files to the DirectX .x file format. In order to be able to do that in Blender, you first have to enable the DirectX exporter addon (in Blender: File - User Preferences - Addons).

I'm reading Blender Foundations that guides you through Blender step by step. Blender is a complicated piece of software and without instructions you'll quickly become overwhelmed, but with this book you quickly understand some basics. The book has an online companion: Blender Foundations. I quickly learned that with Blender you can also make animations and games.

 

The Blender Artists Community has a lot of information about Blender. The Blender 3D design course is also a very good site to learn Blender. Blender 3D: Noob to Pro is another great resource to learn using Blender.

In below video you can see some of the capabilities of Blender (David Allen Ward, YouTube user: ward7299, he's got a great collection of Blender tutorial video's).

 

Here's another video in which you can learn how to create a spiral staircase. Really nice and it shows the power of Blender.

 

As I followed the Blender Foundations book, I stumbled upon some problems creating a table. I had a hard time to model the legs of the table. When I was using the array modifier, the legs of the table were behaving strangely as I increased the quantity of legs with the array modifier from one to four. Cause of this problem was that the Empty that I had to use according to the book was rotated not properly. I had to do the following in order to fix it:

1. select the Leg and press Ctrl-A and apply rotation
2. select the Empty and then the Leg and then press Ctrl-C copy location (or do it via 3dCursor positioning - Shift-S)
3. select the Empty and rotate it 90 degrees around the Z-axis

Next, I had another problem: the size of the legs of the table were not equal. I wondered what caused this. Actually, it was easy to solve. I had scaled the size of the original leg, after I modeled the leg. When I looked at the X, Y, Z scale of the leg via the properties panel it showed that these were not equal to 1 anymore. After setting all these scale factors back to 1 and checking the X, Y, Z scales of the Empty making sure these were also all 1, the array modifier worked properly. All legs were the same in size (after rotating the Empty again 90 degrees around the Z-axis). Below you can see the result. I'm happy so far.

blender table modeling

Some people made an animated movie with Blender: Elephants Dream.

The Bullet Physics Library is also something worth investigating further. At the moment of writing I don't exactly understand what it's used for and how to use it, but it seems to be a tool with which you can simulate a game and detect collisions etc.. This is what Wikipedia says about it.

The following are possibly other useful editors:
Gmax
Milkshape (animation)
Wally (texture editor)
Valve Hammer Editor (for creating maps)

OpenGL

OpenGL is an open-source 3D library that can also be used for creating 3D games instead of the DirectX library, which is non open-source. More information about this OpenGL library can be found here:

http://www.opengl.org/
http://en.wikibooks.org/wiki/OpenGL_Programming
http://user.xmission.com/~nate/opengl.html
http://www.3dcodingtutorial.com/

How do I make a game? • DirectX is a registered trademark of Microsoft Corporation in the United States and/or other countries.