Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

Introduction To DirectX
  vbProgramming 
Tutorials - Introduction To DirectX
 
     

vbProgramming Home :: vbProgramming Forums :: Tutorials :: Contact :: Links 

 

 
This tutorial will serve as an introduction to DirectX. It will show you how to set up DirectX on your computer. It will also show you why you might want to use DirectX over other technologies.

Introduction to the World of DirectX

Welcome to the awaited DirectX tutorial. I'm going to start off by explaining DirectX with a little FAQ.

Well what is DirectX, and why do you want to use it?

"Microsoft DirectX is an advanced set of multimedia APIs built into Windows operating systems. DirectX provides a standard development platform for Windows-based PCs by enabling software developers to access specialized hardware features without having to write code that is hardware-specific."
-www.microsoft.com/HWDev/acronym.htm

Simply put, DirectX is an API for creating games. Rather than talking in 'hardware' language, we use the a set of functions that MS gives us to make life easier! There are various APIs that DirectX gives us:
DirectDraw - For 2D
Direct3D - For 2D and 3D
DirectMusic/DirectMusix - For Music/Sound
DirectInput - For Keyboard/Mouse/Force-Feedback Joystick input (force feed back is like (for example) in a racing game your car hits the wall on the right, the joystick gets pulled to the left.. neat future isn't it.


"I want to write a 2D Game, so why should I use Direct3D?"

Microsoft basically (like it does with most products) dropped support for DirectDraw. Another reason to use Direct3D is becuase its got more features (Shader Language, Effects Framework, Alphablending..etc).

"Why can't I just use GDI+?"

Direct3D is way faster (although more complicated). I'm not saying don't use GDI+, its great for games such as card games, simple strategy games, board games (basically games which don't require a lot of stuff to move all at once). I once wrote a Tile Based GDI+ Game Engine. Once I added 2 enemy characters moving around, I got 7 FPS, and it dropped down to 4 when I added one more! GDI+ relies on software (.NET) to do all the drawing, whereas DirectX talks directly to your hardware. Also, Direct3D (like I mentioned above) has a lot more features.

"What are the downsides of using Direct3D?"

Uhh... its harder . Fortunately these tutorials may help you out and 'ease the pain' :).


"What about OpenGL?"

OpenGL is really not that supported in .NET, but if you really want to do that, visit http://csgl.sourceforge.net/

"What are some books you recommend for learning Direct3D?"

Managed DirectX KickStart - C#, but the source is in VB.NET
For the uber n00b: .NET Game Programming with DirectX 9.0 - mentioned several times already in this site :). I learned a great deal from this book.
If you read the Amazon reviews, here's my response to them: Yes, like most books it contains errors - but hey, no one's perfect. The important thing is that you learn from the book. It's a pretty easy read, as the author explains a lot, sometimes he gets a little unclear - but most of the time he's clear and concise. It's "An easy to read, soup-to-nuts guide that helps you start programming games fast" (from the cover of the book).

---

Well, now that you're convinced to use DirectX, the first thing we need to do is install it!

Click here to get the Summer Update 2004, the latest DirectX Update at this time of writing(8/13/04). The file is fairly large, so you may require a broadband connection. If you don't have a fast connection.. try getting it at your friend's house lol :p.

During the installation, if it asks whether you want to install 'Retail' or 'Debug' choose debug. If there is an error in your game, debug will tell you what that error is. On the other hand, retail is faster, but the error will say something like "Error in the application", like that really helps :p.

Reboot your computer when it asks.

After rebooting, open VS.NET. Create a new project, name it whatever you want. All the way to the right, near the solution explorer it says "References". Right click it and hit Add Reference. Be sure that Microsoft.DirectX and Microsoft.DirectX.Direct3D show up on the list.

[This is for VS.NET 2002 users]
If it doesn't show those 2 references, then you're probably using VS.NET 2002. Unfortunately, MS basically dropped support for VS.NET 2002. But don't worry - close VS.NET follow these instructions:

1) Go to the directory where you extracted the SDK Setup files, and then go to: Developer Runtimes | Managed DirectX | Debug (or retail if you want) | and run the short setup file there

2) Open Regedit(Start | run | "Regedit")
Navigate to

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\AssemblyFolders\
Right click the "AssemblyFolders" Icon and select New | Key
name it DirectXAssemblies

3) Go to the DirectXAssemblies folder and double click the key in there which says "(default)"
and type in the path to your DLLs:
C:\WINDOWS\Microsoft.NET\Managed DirectX\v9.00.0900

This made the summer update work for me.

Now go back and check whether the References show up or not (they should).


[/This is for VS.NET 2002 users]


Well that's it for this tutorial. Now your computer is ready to start making some DirectX apps!
 

There is no Source Code for this tutorial.