Chapter 2. 3D Rendering

Rendering is the process of transforming an entity’s data into a visual representation. I hesitate to use the terms “two-dimensional” or “three-dimensional” explicitly because it’s possible to render in more ways than what is viewed through a computer monitor. We cannot limit the theory to a simple computer monitor because it’s now possible to scan a 3D object, as well as sculpt a 3D object. This technology is called 3D printing. For our purposes, though, we’ll be learning about rendering graphics on a monitor. In this chapter, you will learn about the rendering system of a game engine, and you will add the rendering module to the Advanced2D engine (created in the first chapter).

We’re attempting to tackle a rather large and complex subject in a single chapter, so it might seem a bit overwhelming at first. But if you study the code, you’ll see that it just builds on the basic engine project started in the previous chapter. This is called the iterative process of software development, and it is a flexible, robust way to write code. (The inflexible, or brittle, method would be to write an entire engine all up front and then work out its subsequent bugs, also all at once.) When you are writing a lot of code, and especially when you are building a complex system such as a game engine, you want to have a fast iterative process.

What does iterative mean? Iteration is a repetitive action. When building code, a single step of iteration is to write some code, compile, fix any mistakes, and test. That’s right, test. A fast iterative process is helpful only if the code you are writing is free of syntax errors as well as logic errors. One of the best ways to test while building is to have a large-scale project in mind for the test subject, such as a graphics demo or a game.

So, what do we need to do to get started? Let’s begin by opening the Advanced2D project from the previous chapter, and then add to it. This project is the game engine, and you will write a client or test program that will consume the engine’s functionality in order to do something useful. That is the whole point of a game engine, after all—to simplify the front-end code, or rather, the code that you must write for each new game. A game engine separates the programmer from the platform-specific APIs and SDKs (such as Direct3D) as much as possible.

Advice

Everything in this chapter—the text of these pages, the Direct3D source code, the C++ projects, the 3D mesh files, the textures—was developed using completely free open-source software—and I’m not talking about any Express software either. Just to prove that it is possible, I installed Windows XP on a new hard drive and neglected to install any Microsoft tools—not even the DirectX SDK. And believe it or not, it is entirely possible to develop a high-end Direct3D game using free software, without any funky workarounds.

Of course, if you want to use Visual C++ 2005 with Microsoft’s official DirectX SDK, you’re welcome to–the code is all the same. When we get into subjects such as audio, scripting, and level editing, I’ll share with you the free tools used for those purposes as well!


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset