Today I have finally gotten a simple sort of animation working. It looks easy, but I made my life a lot harder by implementing by own math library. So far I have a Vector3D and a Matrix4x4 class almost finished. Well the Vector class is pretty much done. The Matrix class still needs some fleshing out, but I got it working well enough to spin a triangle. I realize I could have used the D3DX library (which is deprecated), or XNAMath (also deprecated), or DirectXMath (safe for now), but I thought making my own math functions would be a good learning experience. I did also have to reimplement D3DXMatrixLookAtLH and D3DXMatrixPerspectiveFovLH, but Microsoft is nice enough to list the equations in their documentation (thanks!).

In addition, I got a lot of help from this book, 3D Math Primer for Graphics and Game Development, which may be one of the best I’ve seen for 3D math. While there are other books, this text has very clear explanations, equations, and actual C++ implementations. I did try my best not to “cheat” and just copy the code, and instead based it on the equations listed. Unfortunately, I got cocky and wrote the length function without checking the reference, and left out the square root function call by accident (resulting in about a hour of debugging). Eventually I figured it out, but not after checking pretty much everything else with a fine-toothed comb. No worries, it’s working now.

Feels nice to see some movement on the screen. For this week I’d like to get a textured cube spinning. Also, I realized that DirectX 11 doesn’t come with a way to import models out-of-box. So pretty soon I will probably have to write a model importer (I’m looking at COLLADA now). Sometimes I wonder if all this work is really worth it, especially with Unreal Engine 4 at $19/month at the moment. I guess I do realize I can likely never hope to compete with the big commercial engines, but I still think this is a great exercise of the mind. We’ll see how long I can keep my faith.

engine zero triangle

So I buckled down and spent the better half of the day actually getting something to show on the screen. Yes, it’s still just a triangle, but it feels pretty satisfying after struggling to get it to work all morning. While there are tons of triangle tutorials online, and it would seem like a 20 minute hack, I ended up having some difficulty for a few reasons.

One, I decided last night to upgrade to Visual Studio 2013 so I could take advantage of C++11 and the 64-bit compiler. Right off the bat, this resulted in a bunch of warnings. I eventually found the instructions to clean this up here, and it ended up not being a big deal.

The second issue was with compiling the HLSL shader (currently, it just passes along the position and color attributes without any fancy math). It turns out the D3DX11CompileFromFile is deprecated as is the whole D3DX library. I guess I could have still used them anyway, but what fun is that? So I decided to remove the D3DX dependency and either move to newer functions, or reimplement certain classes completely.

Luckily there is a function called D3DCompileFromFile, which does the heavy-lifting of compiling a HLSL shader file. However, for some reason shader files from tutorials I was following did not seem to work correctly with the new additions. After tweaking it for a bit, and a lot of trial-and-error, I was able to get something built. I know it seems rather silly to have spent hours on this, but hopefully once I get this foundation built things will become easier. Here is the (dirt simple) shader file if anyone is having similar problems.

struct VS_OUTPUT {
   float4 pos : SV_POSITION;
   float4 color : COLOR0;

VS_OUTPUT VS(float4 pos : POSITION, float4 color : COLOR) {
   VS_OUTPUT output;
   output.pos = pos;
   output.color = color;
   return output;

float4 PS(VS_OUTPUT input) : SV_Target {
   return input.color;

Next up, I want to get in texture mapping, finish the Vector and Matrix classes, and make a spinning cube. Stay tuned.

Beginning D3D11

Beginning DirectX 11 Game Programming by Allen Sherrod is, what I’d consider, a great introduction into DirectX programming. Just to be clear, it’s really only an overview of the DirectX APIs (Direct3D, DirectInput, etc.) and not really a graphics or game programming book (despite the title). So there is very little in the way of actual gameplay type programming, as you never really get to the point of having any sort of game demo. In that same respect, you don’t really deal too much with computer graphics theory, though there is some brief coverage of lighting models in regards to shader programming. That said, what is in the text is a good start to learning the DirectX 11 API and getting some foundation knowledge of the Windows platform.

The book covers basic Win32 window creation, initializing Direct3D, error handling, basic 2D graphics concepts, font rendering, input handling (with Win32, DirectInput, and XInput), fundamental 3D math (vectors, matrices, coordinate systems), cameras, and 3D models. Overall a good amount of topics, and decent coverage of the building blocks for working with the DirectX 11 SDK. While I wouldn’t say the book is for “beginners” (as nothing involving DirectX or Win32 is really for novices), it doesn’t go into as deep a depth as something like the Frank Luna book (which covers more interesting topics like normal mapping and shadow maps). However, I did find the discussion at the end about loading the OBJ 3D file format into Direct3D to be unique, as most books do not go into this.

So do I think Beginning DirectX 11 Game Programming is worth reading? Certainly. It was an approachable read and the Kindle e-book was moderately priced at around $25. For sure, if you are working with the DirectX 11 SDK you will want all the help you can get. Granted, I think some of the other titles I’ve seen had more impressive demos, or deeper coverage, but I felt this was a fine introductory text. I’d even go as far to say that you should read this book first, as it presents the basic knowledge in a way that is much more to the point and not as daunting as some other resources.

The one thing, which is both exciting and sad, is that I believe this was the last DirectX 11 book available on Amazon that I haven’t read. I see there are a few newer books covering DirectX 11.1 or later, but I’d really like to stick to straight 11 due to Windows 7 compatibility. So, at this point, I think I maybe have got as far as the introduction books will take me and I will have to just start developing with it and learning as I go. Not a bad problem to have. Although I still have a few general game engine books in my backlog, I’m feeling more confidant about getting into the trenches of development with my engine and this book has definitely helped.

I know it has been quite some time since the last update, and I thought I would be much further by now. Truth be told, I have been a little distracted the last few months with things totally tangential to graphics programming. In any case, I’ve had some motivation recently to continue on the 3D game engine and began doing further research and reading. However, research doesn’t get results on it’s own. 90% of the time, you just have to start doing whatever it is you want to do whether you think you’re ready or not. So that brings us here, to this totally underwhelming screen shot.

Engine Zero Blank

Yes, it is a blank pink screen. You can calm down. What you are not seeing is some basic boiler-plate code to initialize DirectX 11, clear the back-buffer to a plain color, and the basic Win32 message pump. I have also started to give some structure to the application, with a namespace and class that encapsulates the Direct3D related code. Right now it is a bit hard-coded for a lot of stuff, but I wanted to get it working first and then I can refine and refactor as needed. I’m actually feeling really excited about the prospects of having my own 3D engine, and hope to power through a lot of this foundation stuff so I can get some interactive demos up and running. If everything goes well, I plan to publish updates in this series more frequently as I progress. Thanks for watching.

OGRE Cookbook

OGRE 3D 1.7 Application Development Cookbook by Ilya Grinblat & Alex Peterson was, I guess, what it advertised itself as; a quick cookbook of recipes using OGRE. What is was not was a good inspection of the OGRE engine itself. Really what the book amounted to was a series of short chapters, each tackling a specific programming problem. While there is nothing wrong with that, I felt like the book did not dig deep enough into the actual OGRE software and instead focused on other libraries or APIs you could combine with OGRE.

First of all, this book was heavy into MFC; nearly every chapter relied on it. I am not going to open a debate about MFC as I’m sure it will be heated. What I will say is that MFC is not supported on the free versions of Visual Studio (which is what I use) and obviously won’t work on Linux or Mac, or on mobile platforms, etc. It seems very short-sighted, and somewhat ugly, to take a great cross-platform, open-source tool and then marry it to Microsoft’s proprietary API. This also restricts the user-base significantly as now only Windows users with professional versions of Visual Studio can even run any of the samples. Huge loss here.

Aside from the MFC issue, there are actually some interesting tidbits found in the text. They show how to do basic mouse and keyboard input and move onto voice input and text-to-speech. There’s coverage of creating manual objects and using billboards, working with XML files, using lights and particle effects, scripted movement, animation, some effects like mirrors and video textures, and manipulating objects. So, yes, it does discuss a lot of key topics when working with OGRE, and from a cursory look this would seem just like what a beginner to the engine would need. However, I think the instruction would have been a lot better had they not relied on MFC.

Overall not a particularly long book, and the price was not bad for the Kindle e-book. Seeing as there are not very many books dedicated the OGRE, this is probably still worth getting if you are exploring the engine. That said, the other OGRE books I’ve read were much stronger in terms of actually focusing on the engine API itself and in a cross-platform manner.

Game Engine Design

Alan Thorn’s Game Engine Design and Implementation was quite an interesting read. Overall I thought it was good, but the book struggles at times to find it’s audience. On one hand, it covers a lot of great topics and there are some good code snippets to be found. On the other hand, it seems to jump around between APIs and frameworks and never really culminates with a complete engine. Even so, engine development is no breeze and any help in this area is much appreciated.

The text begins with the basics: downloading Visual Studio or Code::Blocks and configuring a development environment. It shows you how to create and call a DLL. Some brief coverage of the STL. All useful stuff. Then it moves on to some basic engine features, like logging errors and handling exceptions. Again a great place to start. It continues with a resource manager based on XML. Then a 2D scene manager and renderer using SDL. Supporting sound and music with the BASS library. Processing input with OIS. Then a renderer with DirectX 10. Great stuff. Then in the next chapter it throws out everything you just learned and jumps to working with OGRE. Don’t get me wrong, OGRE is a great API. But it seems strange for a book titled “Game Engine Design and Implementation” to use an off-the-shelf library and not code the, erm, implementation themselves. The book follows up with coverage of Bullet physics and ends with a brief overview of DX Studio, which is an all-in-one game engine solution.

While each chapter alone is very interesting and informative, I feel like the book as a whole lost it’s focus somewhere and the engine that you think you are creating at the beginning of the book never materializes. I almost feel bad, it’s like the author started with one premise of creating an engine from scratch, and then gives up half-way. I even agree that using pre-built tools are a good idea in many cases, and most people don’t want to re-invent SDL or OGRE or whatever. But there are other books that focus on these engines and frameworks. People picking up a book like “Game Engine Design and Implementation” probably are more interested in rolling their own engine.

That said, I still feel like the book was a worthwhile read and I did learn a little bit about some stuff and found it useful. Going in I had read the reviews on Amazon, and I knew the author was going to jump around with different libraries. Had I not known this I may have been more upset. As is, Alan Thorn is a competent writer and clearly knows a thing or two about game engines. I guess I just wish there was more of a focus on creating something cohesive and original and not just a jumble of introductions into different APIs. However, if you are on a journey (like me) of creating a 3D game engine you will need as much ammo as possible and this book certainly has a place in the arsenal. Just not the first place.


I decided to break from my 3D game engine book marathon and go to something more fundamental. More Effective C++ by Scott Meyers is one of those books I have  had on my wishlist for years but just hadn’t got around to reading yet.  I had read the original book  Effective C++ some years ago, and this sequel very much follows the same form. Though slightly dated now, it does cover a good amount of C++ design considerations that will show up in almost any decently complex C++ application.

The book covers a lot of OOP (object oriented programming) concepts and designs, and also a lot of the trouble you can get into using C++ without fully understanding what you are doing. Some of the coverage includes how to use abstract base classes and virtual functions. Specifically Meyers talks about memory management issues with construction and destruction, temporary objects, passing by value versus pointer/reference, and overloading copy/assignment constructors. He also discusses problems with using exceptions, explains how to write a smart pointer class (which is now obsolete with C++11, but still good to understand the implementation), using proxy objects, how to do lazy evaluation, and some various odds and ends.

Overall I found this to be a great text and very helpful, especially the discussion on inheritance and abstract base classes. If you really want to understand C++, warts and all, this should be a required text. However, please read the original title first, as it covers some more fundamental concepts than in the second text. Recommended.