Quake Tech Talk
Getting Direct with Microsoft
by loonyboi, QuakeLab: Multimedia
Remember the early days of DOS gaming?
Remember when you had to have the right driver just to hear the cool sounds in Wolfenstein 3D (you do remember that, don't you?) Remember VESA drivers? Remember lower DOS memory (Doom must have crashed a million times on my old computer because of that one...) Well, in 1994, Microsoft decided they were going to make life easier for the average game player (and boost sales of the Win95 platform while they were at it).
Enter DirectX. DirectX is the name for a group of Application Programming Interfaces (API). They are: Direct3D, DirectPlay, DirectSound, DirectDraw, DirectSetup, and DirectInput. So what are these things? Well, an API is basically a group of tools that a programmer (or game developer in this case) has to work with. By knowing that the user already has these APIs installed on their system, the developer can program directly for them specifically. But why would anyone want to do that? Well, for starters they are a programmer's dream come true. With DirectX, you know that your target audience has all the drivers they need. It works like this: the user (that's us gaming nerds) downloads Direct X (or installs it off of a game CD-ROM). Direct X now works as the driver for your sound card, video card, etc. for programs that work with DirectX. Basically this means that the programmer can program for DirectSound, and not have to worry about putting in your own sound code for several different sound cards.
Unfortunately, while DirectX might be a great concept, it has (more than) a few problems. For starters, if you don't have a DirectX compatible driver for any piece of your hardware....you're screwed. For example: I have a non-compatible sound card. What does this mean? Well, for games that let me disable DirectSound, nothing. They work just fine. However, games like Mechwarrior 2 hate my computer. If you're seeing General Protection Faults more often then Mechs, you probably have the same problem as I do. This isn't the only problem that can be caused by non-compatible hardware. Strange video errors, weird choppy sounds, and other strange things can happen if your card isn't 100% DirectX compatible. To check this, download DirectX (the link is below) and run DXSetup.exe. You'll see a list of drivers, followed by that particular driver's status on your system. Hopefully, you'll see "certified" next to all of them. If you see "no hardware support" then contact the manufacturer of your hardware, and ask for an updated driver (of course, if your manufacturer no longer exists, like mine, well then you're out of luck).
Jason "loonyboi" Bergman
Another problem is the fact that some games require different versions of DirectX than others. If you play a lot of Win95 games, be sure you know what version of DirectX you have on your system. A lot of the time, installing an older version of DirectX will cause many games to stop working. To check this, run DXSetup.exe again, and check the numbers on each of the drivers. If the game you're trying to run requires an out of date driver, try contacting the publisher. There may be an update patch to make the game compatible with more recent drivers.
Another problem, is that the DirectX setup system has actually been known to overwrite graphics drivers. So basically (and I know this one well) your computer might be fine and dandy until you install DirectX 3 only to discover a million and one General Protection Faults. What can you do about this? Well, not much. It sounds freakish, but memorize your system config. Hey, it'll help. If a program changes it, I know immediately. Basically, just make sure you know what each and every piece of hardware on your computer is, and what driver it runs. Trust me, it's a lot easier to reinstall a particular driver if you know it's been changed than to restore your whole friggin' system from scratch. If you find that DirectX overwrote a particular driver, download it from the manufacturer's web site (or if you have it backed up, just restore it). But bear in mind, that just because DirectX changed a driver, doesn't mean that it's necessarily a bad thing. Only do this in the extreme case where DirectX's setup program has your hardware confused (I.E., it thinks you have a different sound card than you do). Otherwise, you may do more harm than good to your system.
Oh. Yeah. I almost forgot about Direct3D.
Okay. Maybe you're not up on Direct3D, but a lot of people are (lord knows John Carmack is...). And yes, Direct3D is not what Microsoft promised. You see, while independent software acceleration may work for sound systems, and modems, and other hardware, the gaming world is moving very quickly towards hardware acceleration. Add to this the fact that Microsoft's Direct3D requirements are well...not very impressive, and you get some very angry developers.
John Carmack specifically has been especially vocal in this matter and rightly so. GLQuake, as I'm sure you know does not use Direct3D. It uses OpenGL (of course). What is OpenGL? Well frankly, OpenGL is a system so nice that a few years ago to even imagine owning a system that supported it would have been a drunken fantasy. Actually, it still is, kinda. While you can play GLQuake on a 3DFX based board, it does not support full OpenGL (you still need one of them $80,000 Intergraph Realizms for that). But I'm getting off of my point here. What the heck is OpenGL? Well, like Direct3D it is hardware non-specific. But that's about where the similarities end. Hang on to your pocket-protectors, we're gonna get technical.
Direct3D works within layers. The top layer is the API itself. Underneath that, are the HAL (Hardware Abstraction Layer) and HEL (Hardware Emulation Layer). The HAL is different for each board, and changes with the driver for the hardware in question. The HEL acts as the translator between the HAL and the API. Basically, this means that an instruction has to be filtered through three separate places before it can get to down to the rendering system.
OpenGL on the other hand, works directly above the hardware. No filtering, just the Gl system. From a programmers perspective, this is a serious advantage, since you don't have to worry about the translation systems in your code. With Gl, you are working much closer to the actual hardware, thereby making it a much more efficient system.
And this isn't just plain laziness on the part of programmers either. In his .plan a while back, John Carmack was nice enough to explain why there will not be a Direct3D port of Quake. Specifically, he points out:
Ease of use is damn important. If you can program something in half the time, you can ship earlier or explore more approaches. A clean, readable coding interface also makes it easier to find / prevent bugs.
Let's face it this is a huge issue with developers. But before you start accusing Carmack of simply complaining, realize that he backs his case up with actual code. This is the actual code to lock, build, and execute a single triangle (it's just for example purposes, this has no actual use).
(psuedo code, and incomplete)
v = &buffer.vertexes;
v->x = 0; v->y = 0; v->z = 0;
v->x = 1; v->y = 1; v->z = 0;
v->x = 2; v->y = 0; v->z = 0;
c = &buffer.commands;
c->operation = DRAW_TRIANGLE;
c->vertexes = 0;
c->vertexes = 1;
c->vertexes = 2;
I'm not expecting non-programmers to understand that, but just look at the code for a minute. It takes twice as much code to draw a single triangle in Direct3D as it does in OpenGL. So what? Well, let me put that into perspective for you. Quake displays (this is a general estimate) about 15,000 triangles at a time. The Quad Damage object alone contains 105 triangles! Imagine how much work goes into just getting the Quad Damage to display in OpenGL. Now picture trying to have to convert that to Direct3D, where there are twice as many instructions required. Now you understand why Carmack won't be making that Direct3D port anytime soon...
But DirectX isn't all gloom and doom (or lack thereof). Let's face it. Although it sucks when changing CDs during a game, AutoPlay is kinda cool (especially with Armagon). DirectPlay is making it easier to incorporate TCP/IP support into games, (much easier, actually) DirectSound (if I only could use it) is actually a very cool API. It really simplifies sound programming, and allows hardware independent sound systems (hey, even QuakeWorld uses it).
What does all of this mean in the end? Well, even John Carmack admits that this is a temporary problem. Keep in mind that Carmack doesn't hate Direct3D, (as he is quick to point out) he just doesn't see any point to taking more time to support it, when there's no performance difference. A surprising number of companies have announced OpenGL drivers as well, so you may find yourself playing GLQuake before you know what's going on.
Check in next week, when I'll jump into the fray and talk about .DLLs and QuakeC: or How I Learned to Quit Complaining and Love Microsoft. 'Till then, the balcony is closed.