02.06 - Introducing DirectX

Started by
54 comments, last by Teej 20 years, 11 months ago
The Windows Shortfall If you’ll recall in 02.04 - Game Anatomy 101, I made the distinction between internal and external game elements. In this article, we’re going to take a look at a technology that does it all. You might be wondering, “Aren’t there already ways to read the keyboard, play sounds and draw on the display right in Windows?” Sure there are, but they aren’t up to the task for games. For instance, GDI drawing routines are far too slow for the kind of frame rates we expect – heck, GDI was designed for business presentation graphics! Windows has no native support for all of the fancy things that sound cards are capable of these days, and you’re going to be fumbling to try and keyboard, mouse and joystick input in a proper and orderly fashion. Enter: DirectX Microsoft has long been aware of this, and has responded with a set of software components that interact with the hardware on a lower level, thereby drastically increasing performance. They’re called DirectX components, and address your sound, music, input, output and network needs. Here’s a list of the components (as of version 7.0):
  • DirectDraw
  • DirectInput
  • DirectSound
  • DirectMusic
  • DirectPlay
  • Direct3D
Each of these components are actually COM objects, and are used much like regular C++ objects (if you don't know what COM is, don't worry). Luckily, each is fairly intuitive and straightforward to get working for you. In the sections that follow, I’ll introduce three of these – DirectDraw, DirectSound and DirectInput, and leave the rest for when they’re needed. DirectDraw DirectDraw is our ticket to unleashing the power of hardware acceleration, video memory and all of the various features available in today’s high-performance video hardware. We are able to create memory buffers called DirectDraw surfaces, and these surfaces can make use of video and system memory to hold buffers for the actual display, secondary display buffers, and buffers for our game images. The beauty of DirectX is in its ability to ‘flip’ surfaces directly to the video adapter’s active display, removing the need to copy memory. And since our game images can be held in DirectDraw surface buffers in the video card’s memory, hardware acceleration can be used to move these images directly into display buffers for speedy rendering. DirectInput The asynchronous state of a wide array of input devices can be ascertained through DirectInput objects. It’s direct (read: fast ), it’s well organized and it’s a convenient abstraction for all of the data available to your game. You don’t have to worry about the endless types of joysticks, mice, VR headsets, force-feedback devices or anything else on the market – the data you’re looking for is presented to you in a way you can use without the hassle. DirectSound Sound can be a complicated aspect of writing a game. DirectSound seeks to simplify the output of sound and puts the power of many specialized effects at your disposal, and allows you to use audio resources in any popular format. Similar to DirectDraw’s surfaces, DirectSound utilizes sound buffers for storing, organizing and playing your audio resources in a straightforward and intuitive manner. Other Options Of course, DirectX isn’t the only solution out there for gaming under Windows. Here’s a (very) partial list of some other tools:
  • OpenGL (Open graphics library – very popular as well)
  • GlIDE (3DFX’s native API for Voodoo-based video cards)
  • Allegro (a multi-platform graphics library)
  • SDL (another multi-platform graphics library – thanks to pazu for the heads-up)
  • MIDAS (a third-party sound support API)
I’m sure that you can think of many that I haven’t listed… So why did I choose DirectX? One of the advantages to using DirectX is that the libraries needed on the user’s end are either already in Windows, or simple to update. As you’ve no doubt seen, it’s a very popular choice for most of today’s popular games. A main disadvantage to using (only) DirectX is that it’s not portable to other types of systems. After all, there are people using other environments such as UNIX or the MAC. As a matter of fact, I’m already getting differences of opinion from some forum members on choosing DirectX. Deep down though, you all know I’m right Multi-Platform Parallel Development There’s a willingness by many forum members to have the main material in this forum adopted to other graphics, input and sound tools, and for the most part I’m all for supporting as wide an array of multi-platform APIs as possible. Unfortunately, I doubt I’d have the time to perform the necessary translation myself. As is the case with my choice of language, you’re going to be limited to DirectX in the material I present (for the foreseeable future anyhow), but I am willing to entertain requests from others to take on a role in this tutorial series by representing the interests of other tools. More information on this ongoing issue will follow. Arming Your Machine for DirectX There are two components for DirectX: the user DLLs and the developer’s SDK. Both are available from Microsoft (http://www.microsoft.com/directx), but before you do, we’d better look at the various versions of DirectX that are available (and in use). At the time of this writing, DirectX 7.0(a) and 8.0(a) are the main current versions. This forum uses version 7.0, which means that you need at least this version installed on your machine. Remember that you need both the runtime DLLs (for playing games) and the SDK for writing programs that use DirectX components. If you download and install a version later than 7.0, it includes everything you need. Let me rephrase that clearly: Every version of DirectX is fully compatible with every previous version. If you have DirectX 8.0, you can write games that use version 1, 3, 5, 6 or 7 (there’s no 2 or 4). Think about it – Microsoft couldn’t just scrap older versions or your games would stop working when you updated DirectX on your machine! As I’ve mentioned, there are some DirectX-related files on my webpage, and you can pick and choose what to download instead of grabbing a 150MB file from Microsoft with a lot of useless contents. The one thing that I strongly encourage you to get (even if you have the DirectX 8.0 SDK) is the documentation for DirectX 7.0. Trust me, you’ll need this. The version 8.0 documentation isn’t going to help you. And if you proceed without this documentation at your fingertips, you’re as good as dead . One question remains – if DirectX 8.0 is available right now, why are we using version 7.0 for the tutorials? Well, this is still under debate by many here, but I basically have two reasons:
  1. DirectX 7.0 is still very popular – it’s bound to be the most compatible for writing a game with.
  2. The way things are done in DirectDraw has been massively overhauled in version 8.0 (so much so, DirectDraw doesn’t even exist in 8.0!), and although it’s not the newest anymore, it’s still the most ‘compatible’ when learning to use graphics APIs.
How else can I put it? Version 8.0 is still very new, and 7.0 is well understood by many. It’s in no way out-of-date, and already has more functionality than we even need for a long, long time. The moment I hear a decent argument for abandoning 7.0 in favor of version 8.0, I’ll be the first to concede and update the contents of all material in this forum. What About the Other DirectX Components? DirectMusic deals with playing MIDI music in your game. While I agree that it’s an important part of professional games, it’s not really central to game development. We’ll see where this forum takes us. DirectPlay assists in all of those fun issues involved with network-play. As with DirectMusic, I do not doubt its usefulness – I’m just not concerned with it at the moment. Direct3D: oh boy . I bet that many of you are drooling over this one, aren’t you… Well, here’s my philosophy on 2D and 3D games: if you can’t make Pac-Man eat pellets or a sprite jump onto a ledge, you’re not going to be able to write the next Unreal Tournament. We’re starting our game development journey from the ground-up, and that means at the basics. Too many over-eager enthusiasts jump right into 3D engines and find themselves either pasting code together from other websites, getting hopelessly lost in the mountains of complicated code and math, or finally finishing and having a basic, out-of-date 3D engine ala Quake I/II. The true creativity (in my humble opinion) can be better manifest in 2D games. Ultimately, I’d love to have the forum evolve to such a state where we move into 3D game development… it is, after all, the natural progression… Pre-Flight Checklist Before you move onto the next article, I want you to ensure that you have the following installed and ready:
  • DirectX 7.0 (or higher) runtime DLLs – you can check this by going to your Start Menu/Run… and typing DXDIAG. Somewhere on the first tab of this utility is the current DirectX version number on your machine.
  • DirectX 7.0 SDK (or higher) – you need the C++ libraries at the very least. Also included in the install package is a whack of samples that you may or may not be interested in (but I do highly recommend that you get them – many of the samples are great to learn from)
  • DirectX 7.0 Online Documentation – this comes with the complete DirectX 7.0 SDK, but not with version 8.0. I’ve already told you that this is important, and that it’s available on my webpage.
Here's the link to my webpage: http://teejb.webjump.com If you’re ready, we’re going to move on to actually starting to use this stuff in the next article. Questions? Comments? Please reply to this post. Edited by - teej on April 10, 2001 11:24:37 PM
Advertisement
I don''t know how practical this is, but I''m really interested in DirectPlay, and I''m sure I''m not alone. There seems to be a shortage of good DP Tutorials on the net, and I''ve been looking.
~Thek

"There are three kinds of people in the world: those who can count, and those who can''t."
"There are three kinds of people in the world: those who can count, and those who can't."
Hi everybody,

Does anybody know where I could find version 7.0 of DirectX SDK for Visual C++? I visited the Microsoft download page, but the only thing available there is ver 8.0.

Thanks in advance
I do not think you can still get directX 7.0 from Microsoft but directx 8.0 should be just fine.

As Teej said, 8.0 is fully compatible with 7.0. The only thing you need, since we will be doing games with directx 7.0 is the documentation for 7.0 and you can get it from Teej''s page.

Hope it helps

Skidoodlidoo
Careful, the DX8 user runtime will run DX7 programs, but the DX8 developer SDK won''t be compatible with DX7 code. Mostly the area that is affected is the stuff that is done with DirectDraw (since MS put all 2D functionality in D3D and removed DDraw entirely). Seeing as the first few games (at least) that''ll be done in here are 2D, DirectDraw will be a large part of it. I think you can get the developer stuff for DX7 on Teej''s site.
PiotyrSoftware Engineer by day, Game developer by nightThe early bird may get the worm, but the second mouse gets the cheese.
I don''t know where you heard that Piotyr, but it is soooo wrong. I installed DirectX 8 on my computer (developer files), and atm, I am making a pong clone using... DirectX 7. There are ambiguities. For example, if you include D3d.h, you will be programming in DirectX 8. That must be what you meant. But wait

#define DIRECTDRAW_VERSION 0x0700

Presto. All your code are belong to us. In directx version 7. Want to go back to the good ole days and execute buffers?

#define DIRECTDRAW_VERSION 0x0300

Tryyyy it. It works. (If you don''t believe me, go into ddraw.h, it comes with your DirectX sdk, at the very beginning.. oh here, I''ll just hand you the snippit of code.

/*==========================================================================;
*
* Copyright (C) 1994-1997 Microsoft Corporation. All Rights Reserved.
*
* File: ddraw.h
* Content: DirectDraw include file
*
***************************************************************************/

#ifndef __DDRAW_INCLUDED__
#define __DDRAW_INCLUDED__

//Disable the nameless union warning when building internally
#undef ENABLE_NAMELESS_UNION_PRAGMA
#ifdef DIRECTX_REDIST
#define ENABLE_NAMELESS_UNION_PRAGMA
#endif

#ifdef ENABLE_NAMELESS_UNION_PRAGMA
#pragma warning(disable:4201)
#endif

/*
* If you wish an application built against the newest version of DirectDraw
* to run against an older DirectDraw run time then define DIRECTDRAW_VERSION
* to be the earlies version of DirectDraw you wish to run against. For,
* example if you wish an application to run against a DX 3 runtime define
* DIRECTDRAW_VERSION to be 0x0300.
*/
#ifndef DIRECTDRAW_VERSION
#define DIRECTDRAW_VERSION 0x0700
#endif /* DIRECTDRAW_VERSION */


Just letting you know.

-Blackstream

Will you, won''t you, will you, won''t you, won''t you take my virus?

-The Mad Hacker

Blackstream''s Webpage
-Blackstream Will you, won't you, will you, won't you, won't you take my virus?-The Mad HackerBlackstream's Webpage
Sure that comes with the DX8 SDK? I know I don''t have it with the DX8 SDK, and had to revert to 7 to do DDraw stuff. Maybe they included it in a later version, but when I downloaded it, about 3 days after it came out, there wasn''t any DDraw.h in there. I''ve been wrong before, though, so it wouldn''t surprise me too much. I''ve just used the DX7 SDK for all my 2D needs.
PiotyrSoftware Engineer by day, Game developer by nightThe early bird may get the worm, but the second mouse gets the cheese.
Hmmm, interesting. I wonder why what you downloaded didn''t have it. You downloaded the whole 130 mb (or so) right? But I do know that what I downloaded had DirectX 8 on it, because this is a new computer that I have, and I didn''t have any sdks installed on my computer. I downloaded DirectX 8, and now I have Ddraw.h. Check you DirectX 8 samples that you got. In the directDraw folder (if you got that, hrmmmm) there is a windowed mode program. They use DirectX 7 and a really nice version of Ddutil.h (it is in class form now). I''d redownload the sdk and have a look at it (if you have time or a dsl). I haven''t looked into direct 3d for DirectX 8, but I here it is much better than 7 (which I touched once). Or do you already have Direct 3d 8? I''m not sure if you had to uninstall 8 in order to use 7 again or not.

-Blackstream

Will you, won''t you, will you, won''t you, won''t you take my virus?

-The Mad Hacker

Blackstream''s Webpage
-Blackstream Will you, won't you, will you, won't you, won't you take my virus?-The Mad HackerBlackstream's Webpage
Hey Teez, I see we have stopped for a while. Just wondered when we would be moving again

Borland C++ Builder Compiler and DirectX

As I said in an other section, BCC is by far one of the best compiler available and it is free:


BCC 5.5

But when it comes to DirectX, many of you may have to fight hard to link your stuffs. I can prevent this for you: BCC users will have to download specific Borland-compatible libraries . A place to find these is Fötsch''s website:


Borland-compatible DirectX LIB''s

This topic is closed to new replies.

Advertisement