Author Topic: Journey into the depths of DirectX  (Read 1852 times)

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2352
  • OPHD Lead Developer
    • LairWorks Entertainment
Journey into the depths of DirectX
« on: September 15, 2004, 12:08:35 PM »
After years of programming under the DOS environment and writting my own video/sound/input device drivers for software that I have written, moving on the Windows platform was more than a difficult task. It was a nightmare.

DOS was strictly linear. In other words, there was only one process. There was only one path a program could take. Multitasking was something unheard of and the very idea of a thread or fiber or whatever made little to no sense in terms of practicality.

Anyway, point being that DOS programming was a lot easier in terms of lightning fast graphic processing because the programmer, in this case me, had direct access to both the video device and memory as well as every other component available to a computer (including the BIOS!!!).

Alas, Windows with its 32-Bit operating environment and multitasking capabilities took over as operating systems evolved. Programmers no longer had direct access to anything in terms of hardware. A program would sit and wait for resources from Windows after asking for them. In order for graphics to work, the programmer had to use the GDI (graphics device interface) built into Windows. GDI was well suited for buisness applications but was far too slow for any practical game use. Windows games became slow and were not as appealing as their older DOS counterparts.

Microsoft, in an attempt to fix this (and make a quick buck at the same time), developed DirectX. Yet, not suprisingly, it was broken. Just like everything else. However, that was then.

Recently, I've been moving into the wonderful world of Win32 programming. It started out mostly when I downloaded the source code to Quake2 and began fiddling around with it just to see what I could do. Sure enough, my fiddling got me interested and I soon started on a project that was long awaiting its birth, "The School from Hell". Remaining incomplete as of this writting, "The School from Hell" introduced me to the ease of use of the OpenGL Graphics API for 3D graphics. Simple call a few statements and POOF -- cool graphics.

Wonderful. Great. I like 3D graphics but not every game is well suited for 3D graphics. Take SimCity for instance. It's just not a 3D game. It's much better suited as an isometric tile-based game and, as history proves, it worked amazingly well for Maxis and Electronic Arts.

Plus, I've had several other projects in mind that simply wouldn't work too well in 3D. I wanted 2D. But, using the OpenGL API wasn't suited for 2D graphics because one needed a hardware accelerator to properly run any games at any decent speed. Argh! What headache!

Needless to say, I was still horrified by the complexity of Win32 programming. With its event driven system and the need for a program to be passive in order to be "Windows Friendly", I continued to work in DOS, this time with C\C++ instead of BASIC (QuickBASIC, what a wonderful language!).

Eventually, I found something called the Simple DirectMedia Layer, more commonly called SDL. It was easy. It was, for all intensive purposes, fast. And, most importantly, it didn't require the WinMain bulls***! All I had to do was initialize the SDL API and blammo, a window with my program would open up!.

Now, this was all fine and dandy. That is, until I began working with more complex and advanced graphics/sound processing routines. That's when the SDL overhead kicked in. SDL makes things simple, but it uses DirectX all around for Windows programs. That means that a call to an SDL Blitting function (blitting means moving a series of data from one area of memory to another. Most commonly it's used for drawing a graphic in memory to the screen) would have to determine which DirectDraw blitting funtion to use. Not to mention, SDL uses DirectX 5 which is a hell of a lot less optimized than the newer versions of the DirectX API. This means that a simple function call from my end went through a series of calls through the SDL system to the Windows system to the DirectX system. This is not a good thing because processing becomes exponetially SLOWER as you call more functions for various reasons.

I took a deep breath and said "screw this. I'm just going to get into DirectX programming!". I almost wish that I hadn't, but then again, I would have had games that required the most recent 64-Bit processors at 500 million megahertz with 12 gigabytes of RAM to run at any decent speed. I sat down and stared at my IDE and thought "Great... what do I do now?".

So I typed in the following:

======================================
// This is the source code for OP:MIA
// Liscenced under the GNU GPL v2

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include <windows.h>
======================================

It was the last line that was of any signifigant value.

I next downloaded the DirectX 9.0 API... all 250MB's of it. And realized that was a dumb decision later on because DX8 dropped all 2D functions in its SDK. It was tied to Direct3D which meant that I was going to be writting progams like I would have if I had used OpenGL. Not very practical.

So I looked around and downgraded to DirectX 7 which was the last version that included DirectDraw, the 2D graphics component of DirectX.

I then downloaded a few sample programs and realized that they were s*** so I looked at the DirectX SDK examples. Again, Microsoft and all of its employees seem to be in the habbit of making things more complicated than necessary and not documenting anything to an understandabe degree so I went looking through all the SDK stuff and some online articles at gamedev.net and found what I was looking for. How to start with DirectDraw!

Ok... now the questions is, who cares?

Well, I've now gone from the idea of purely linear programming to making full use of the Windows threading ability within two weeks. I've also created a series of small and simple examples using DirectDraw and have decided that it's now time to start writting Outpost:MIA.

And so, OP:MIA phase 2 is in its infancy. A complete rewrite of its engine has me working with advanced layering that is far more than what is needed for OP:MIA, but then, I'm writting the engine so I can use it again later. Besides, what's the use of writting a game (or any program for that matter) if you can't later reuse some of the code? Waste waste... tisk tisk...

Anyway, so OP:MIA is in full gear. And so is "The Legend of Mazzeroth" (link in sig).

And that's the story of my journey in DirectX Land.

 :op2: Leeor Dicker

Offline ZeusBD

  • Hero Member
  • *****
  • Posts: 521
Journey into the depths of DirectX
« Reply #1 on: September 15, 2004, 12:41:23 PM »
That was an interesting little story there (being sarcastic on the "little" part)...I actually read it, which I usually don't do on post's that long. I'm glad that you've gotten started and that you've got all the training needed to develop your games.
In the dark I'm at home, in the light I'm on the battlefield. A Dragon's life is a constant struggle for survival. But in the end, we will prevail.
Go check out my site: http://www.frankandami.com
E-mail me: ZeusBD at yahoo.com

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2352
  • OPHD Lead Developer
    • LairWorks Entertainment
Journey into the depths of DirectX
« Reply #2 on: September 15, 2004, 01:17:36 PM »
:lol:

Yes well. I looked back over it again and decided to save it as an article on my computer! So I printed it and I'm going to give it to some friends.

Anyway, I've learend quite a bit in the past few days. I also ordered a book about isometric programming and found out that a lot of the thoughts that I had are actually used in games today (I thought I was nuts and was looking for a very complex answer of sorts).

Thanks for reading!  :)

 :op2: Leeor...