3D Engine Construction and Design Workshop: Lesson 1 – Introduction and Synopsis

The first of a series of tutorials I’ve written covering the creation and design of a 3d height map/terrain editor.

This workshop is intended to be a no frills primer on 3D Engine
Construction and Design. While this topic covers a vast number of
subjects, I am going to attempt to cut it down to the bare minimum so
that everyone will be on the same page as we start developing our own
game. While the techniques described here can be applied to any
language, graphics API, and pre-existing graphics engines it will be
constructed from the ground up using only C++ and the DirectX API.

Lemma 1.1 Engine

Throughout this workshop you will be presented with various lemma’s
which are optional sections of reading. They are intended to give you a
better understanding of the topics discussed, and deal mostly in theory
and less implementation.

When I refer to the term engine it might seem confusing, as it has
multiple meanings depending on context. Many think of engine’s as
/Graphic Engines/ such as Ogre3D or Irrlicht. However, an engine is
actually the framework of code that encapsulates a particular aspect of
a game. For example, we will also have /scripting engines/, /particle
engines/, /sound engines/ etc.

However, “engine” might also refer to the
code that connects all these specifics together into one cohesive /game
engine/. The Torque Engine is a good example of a game engine, as it
encapsulates graphics, physics, network, and more. This workshop deals,
more precisely, in game engines. But we also touch upon graphics engines
as a way to illustrate interconnectivity.

I will be writing this workshop aimed at people with a working knowledge
of some programming language, but I will not assume you are familiar
with C++ or DirectX. I do, however, expect anyone who is not completly
comfortable with C++ to work concurrently with Churroe’s C++ workshop.
While specifically designed for programmers in the dev team, I hope that
any member can gloss through this workshop to get a basic idea of how
games in general are designed and structured for optimal performance.

What will we be doing, and what is the purpose?

Specifically, we will be constructing a very simple terrain loader,
using very basic 3d techniques to implement a custom camera class and a
very simple collision detection algorithm. I hope, however, that this
serves a larger purpose. My goal is to really explain how we, as
programmers, need to think ahead whenever implementing our own game
engine. We want to take advantage of the powerful OOP (object oriented
programming) aspects of C++ such as polymorphism and inheritance to
create robust and expandable code. I also hope to illustrate
encapsulation, reusability, modularity, and other concepts which are
important to help us all work together effectively on the same project.

Some less abstract milestones in this workshop I hope to include are the
following:

  1. Installing and configuring Microsoft Visual C++ Express and
    DirectX 9.0.
  2. Building an Engine class shell which we will continually expand
    upon throughout the workshop.
  3. Interfacing with the Windows API and touch upon some windows
    specific topics like threading and processing.
  4. Covering basic 3D math concepts such as coordinate systems, vector
    algebra, matrix math, quaternions, polygons, 3d spatial
    transformations, etc.
  5. Getting a grasp of basic DirectX systems and operation through
    vertex buffers, index buffers, meshes, etc.
  6. Learning basic 3D graphics techniques like culling, projection, etc.

I’ll do my best to keep the pace depending on your feedback, so it’s not
too slow and boring. (^_^);

Alright! I’m pumped, when do we start?

Right now! Lets dew eet. The first thing we want to do is get you all
setup in our IDE (Integrated Development Environment), which means
you’re going to have to do some downloading. If you’re on a 56k modem
you can start downloading and I’ll let you know when you can get up to
make a sandwich ( or get in touch with your local broadband provider as
56k went extinct around the time of the wooly mammoth ).

First we’ll be
grabbing our IDE Visual C++ Express edition from Microsoft. I chose this
for a few reasons. Firstly, it’s free. Secondly, since I use Visual
Studio this lets me easily port over a lot of code. Don’t worry though,
as throughout this workshop I’ll be using the Express edition with you
guys (so you don’t get weird compile errors or something). Thirdly,
it’ll be good to have everyone on the same compiler that way we avoid
nasty hiccups like #2. And lastly, I’m comfortable with it. And since I
am going to have to answer any questions, it’ll help.

So mosey on over to Microsoft’s Visual C++ Express web page
And
click on the button in the upper right that says “Download”. Scroll down
to the Visual C++ part and click ok. It’ll download quick. Start the
setup. When you come to the screen asking if you want the MSDN I would
recommend it (even though it’s like 300mb). It’s basically the
documentation for the language. There is an online format so you don’t
/have/ to download it. And if you’re short on HD space you can feel safe
to skip it. Alone the IDE is about 70mb. Once you see it start
downloading / installing you can move on to the next step.

While this is going lets grab the DirectX SDK (Software Developer’s Kit).
This is a little larger, (okay more like eight times larger) and is set
at a whopping 441mb. So get that going. Now you can go make a sandwich.
While you do that, I’m going to clear some room on my hard drive (~.~);;.

Lemma 1.2 – Why is it so damn HUGE?

DirectX SDK is ginormous because it comes with a lot more than just the
API. Tons of samples, documentation, helper programs (like converters,
debug tools, stuff like that). They don’t make a lite version of it, so
you’ll just have to get the whole thing. Don’t worry, it’s worth it!
Honest =].

Mm pastrami. Okay, so you’re at the Setup complete screen on Visual C++,
lets go ahead and register that now. I already have a Windows ID
thingy-job because I have an MSN account. Fill out the little survey and
then check your email. Click the link and you now have your Registration
key.

Go ahead and launch the Visual C++ program. Click Help | Register
Product, drop your key in, and done. You’re officially ready to start
running some C++ codes (>^o^)9 But, lets get DirectX up and running
first. This actually is a little bit more complicated, so stay with me.

Track down and run the dx file you downloaded (should be something like
dxsdk_apr2007.exe). Run it and wait for it to extract, then continue
with the install. I will be installing to the default directory of
C:Program FilesMicrosoft DirectX SDK (April 2007)
It’s important you make a note of where you install these files as we
will need this location to setup MSVC (Microsoft Visual C).

So lets launch Visual C++, it’ll take a few moments to initialize and
you’ll be presented with a start page. I usually disable this because it
just makes it load slower and I don’t really care about whats new.
Anyway, What we want to do right now is tell MSVC where our DirectX
files are located, so that when we compile our programs it knows where
to look for the required files. So follow along with this fancy image I
cooked up:

Click to Enlarge

  1. Tools | Options
  2. Projects and Solutions | VC++ Directories
  3. Show Directories For (Drop Down box) and select “Include Files”

Click to Enlarget

  1. Click the manilla folder.
  2. On the new edit line that appears click on the ellipsies (that “…”).
  3. In the dialog that appears navigate to where you installed DirectX 9.
  4. Then click on the include file inside there. My include files are
    located here: C:Program FilesMicrosoft DirectX SDK (April
    2007)Include
  5. Click the open button. The Options dialog should now have the path
    to the include files in it.
  6. Go back to the “Show Directories For” menu, and select “Library
    Files”.
  7. Click the ellipsies again, navigate to your DirectX folder, click
    on the lib folder
  8. Depending on your processor select x86 or x64. I have an x86 so my
    libraries are located here: C:Program FilesMicrosoft DirectX SDK
    (April 2007)Libx86

Lemma 1.3 – x64, x86, what now?

If you’re not sure which library to select, there is a quick way to find
out. In your start menu select run, and in the prompt type cmd. At the
command prompt type the following: “set PROCESSOR_ARCHITECTURE” (without
the quiotes). If the program returns “PROCESSOR_ARCHITECTURE=x86″ use
the x86. If it says “PROCESSOR_ARCHITECTURE=AMD64″ use x64. Double check
if you’re not exactly sure, I’m using an AMD Athalon64, but I still have
x86 architecture.

If you want more information on what all this means I recommend reading
Wiki’s article on the subject.

You /should/ be all ready to start running DirectX programs in C++! Lets
do a little test. Go to File | New… | Project. Then Under “Visual C++”
select General (at the bottom of the list), then Empty Project. Type in
a name for your project and a default directory. Then click ok. On the
left of the screen is a solution explorer, with 3 folders in it: Header
Files, Resource Files, and Source Files. Right click Source Files Then
select Add | New Item… . Select Code | C++ File (.cpp). Name it
main.cpp. You’ll be presented with a blank space. Type the following:

#include “d3dx9.h”

#pragma comment(lib, “d3dx9.lib”)

int main( )

{

system(”PAUSE”);

return 0;

}

Press F5. You’ll get a warning about not setting your debugger, continue
debugging anyway. If it compiles and you get a console that says “Press
any key to continue…” *Congrats!* You’re officially ready to start
making some shiny graphics.

It’s going to be a little bit while I get things organized for the next
few lessons. Hopefully, Churroe will keep you busy while I figure how I
want to go about talking about this. Till next time, have code will travel.

Leave Your Response