djdirectxtut.html: Last updated 18 Jan 1998. hits since 23 Nov 1997

[ About | The tutorial | Other resources | AQ (Asked Questions) ]


Game programming with DirectX

Copyright (C) David Joffe 1997-1998.

Disclaimer: This document and all files and code provided with it are provided "as is" and without warranty. I am *NOT* responsible for any harm that might come from use or misuse of this document.

I know this tutorial is a bit brief and somewhat inadequate but I'm a bit busy these days with my degree so I can't really update it much. For the same reason I cannot answer your questions.

I am busy working on a code sample, which I am making available for download as from May 3 1998. Please let me know if there are bugs in it, or things missing or whatever (such as enumerating devices for example.)

Who this tutorial is for: C/C++ Windoze programmers who want to learn to write applications that use Microsoft's confusing API, DirectX. The tutorial uses MFC, but most of the stuff is MFC-independent.

Please let me know if you find any mistakes in the article.


The tutorial:

[ Some Other Resources Links to other useful sites ]

[ Asked Questions (AQ) Check here for some answers to common problems ]

[ DirectX Sample xapp.zip, 112K. Sample program, not exactly complete ]

[ Ch 1: Intro | Ch 2: Background | Ch 3: A DDraw sample | Ch 4: A D3DRM Sample | Ch 5: Misc new stuff ]

Download the entire tutorial (with sample program) zipped for local viewing: dj.zip 31K.

Download the entire tutorial (including sample program) zipped for local viewing: dj.zip 31K.


2 September 1997: Changed error-checking to use the SUCCEEDED and FAILED macros; this is the correct way to check for errors with COM objects.
17 June 1997: Fixed error in chapter 4 (Direct3D RM App) in CreateSurface - caps for the offscreen surface should have included DDSCAPS_3DDEVICE. (thanks go to Eetu Mänttäri)

8 June 1997: Fixed error in SetMode: hr undeclared. Fixed error that SetMode wasn't called in InitInstance. (thanks go to Rostislav V. Shabalin)

11 May 97: Fixed: lpDD vs. pDD problem; useless DDERR macro reference removed; 640x480 "scrolling seasickness" problem fixed
Added: Clipper code, restoring lost surfaces, most of Direct3D sample

5 May 98: Gosh, has it been that long? Anyway, I'm adding a D3D sample program.


Some other resources:


AQ (Asked Questions)

I get a linker error saying external symbol main not found. What's wrong?

It's looking for "main" because it thinks you're trying to write a console mode (DOS-style) (command-line) application. Win32 functions have a WinMain instead of a main. Create a project with the target platform being a Win32 application.

What's my opinion on wrapper class libraries for DirectX?

If you want to write your own one, fine, but there is already one called CDX. It's free, with source code. As such, it is something that is developed by the software development community, and for the software development community. Lets not fragment software development any more by developing several thousand different class libraries. Use CDX; if its not quite what you need, then don't make a new one, rather add to CDX.

How do I load a bitmap using DirectDraw?

That'll be coming soon.

How do I set a 3D scene's background color?

SetSceneBackgroundRGB.

Your code fails when I try it in 256-color mode. What gives?

I was a tad lazy. I'll correct this soon, although I kind of believe 256-color modes should be killed (and made to suffer).

What's this stdafx.h I see #included in your source?

The file stdafx.h is a .h file that is created with each MFC AppWizard project. It should be included in every .cpp file for your project, and heres a handy tip: include it *before* any other includes.

How do I make the samples (and/or my own stuff) from the command-line, with NMAKE?

Blah blah. Coming soon. In the meantime, heres a hint (for Visual C++ users): Check out the batch file VCVARS32.BAT in your VC\BIN directory.

I'm out of questions. Tell me something.

*Never* hard-code an absolute directory/filename. It's annoying to download code with a makefile or project workspace that specifies absolute directories, such that you have to change it yourself to get it to compile.

Tell me more.

You can really mess up your fingers typing, so *be careful*. Don't "race" when you type; take it easy. Get yourself one of those "natural" keyboards, they're pretty good. If your fingers/wrists start to hurt, stop typing and get to a doctor.

Tell me even more.

Check out Linux and X-Windows. It's great.

The tutorial really sux, especially the code, when are you going to improve it?

I'm busy working on a "new improved" version, with a decent sample that will be download'able, and probably even usable in your own applications.

Your TraceErrorDD function is kind of MFC-specific. That sucks.

Yes it does. That was an initial oversight. I'll change that quite soon.

What is this D3DVAL stuff?

A D3DVALUE is pretty much the same as a float; in fact, D3DVALUE is defined as a float. However, it is incorrect to use float and D3DVALUE interchangably, as there is no guarantee that your code will still work if a future version of DirectX changes D3DVALUE to, say, a double. Therefore you should use D3DVALUE's throughout. There is a macro (#define) to convert floats and doubles to D3DVALUE's, called D3DVAL. Hence: D3DVAL(3.4);

Shouldn't you explain a bit more about creating and releasing DirectX objects, as well as the reference count stuff?

Yes.

Why do I get some sort of palette error when I try create a device from the surface?

You're probably in 256-color mode, in which case you need to attach a palette to the surface. I recommend running Windows in 16-bit or higher color modes instead.

What is the difference between Direct3D Retained Mode and Immediate Mode?

Immediate mode is a lower-level 3D API, in which you have to manage lists of vertices and faces, generally doing sorting yourself etc. Rendering is done via Immediate Mode "execute buffers" which contain lists of rendering instructions to give to the 3D hardware. Rendering can also be done using any of 17 DrawPrimitive functions, which let you draw triangles etc without going through the execute buffers. Retained Mode is built on top of Immediate Mode, and wrap up a lot of functionality in classes to manage a 3D scene, 3D objects etc.

Why is the area around the window in the DirectDraw sample a mess?

Because I didn't bother to solid-color-blit the back buffer black when I created it. It happened to be black on my machine, so I never noticed the bug. Consider it an "exercise".

What books can I recommend?

None, since I've never really used any. Sorry.

When am I going to finish the tutorial?

I'm not sure if it'll ever be finished, as such.

When am I going to put actual sample code here?

Quit bugging me, okay? :)

How do I get started in game programming/3d programming/3d graphics?

Link coming soon as answer to this question.

What compiler can I recommend?

Whatever you prefer. I like Visual C++; it has a very nice IDE, a *great* debugger, and the compiler's pretty good. DJGPP is an excellent option for the poorer amongst you: it's free.

Can I use DJGPP for DirectX?

I think so (not sure) but when I get time I will find out and place the relevant info here. DJGPP is a free C/C++ compiler; that way you won't have to go buy an expensive compiler.

What are all those strange little letters in front of your variable names, like bAnimating?

Hungarian Notation. The idea is to try make code more readable by including the type of the variable in the name, such as a b for boolean or a dw for a DWORD. Thus a boolean variable indicating whether or not the program is busy animating would be bAnimating. "m_" in front of a variable means 'member'. It takes only an hour or two at most to get used to, and it really helps make code more readable. I recommend it.

Collision detection?

There is a rather lengthy document on collision detection available elsewhere. Pretty soon I'll even put the URL here, as soon as I find it.

Video/AVI player with DirectX?

Ack. Ask me again later. I'm still getting nightmares.

So what the hell is a UINT anyway?

It's an unsigned int.

What does the Afx in AfxMessageBox mean?

I think it means "application framework" its part of MFC-specific stuff.

Isn't it silly that you've named the function that creates both primary and back surfaces CreatePrimarySurface?

Yes. I'll change that soon, with the new sample that's in development.

What's your email address? Can I email you?

To be perfectly honest, I'm *not* fond of getting email, especially lots of annoying questions. My RSI is bad enough as it is, without that extra typing work to do. Also, I'm really bad at answering email; I sometimes take up to 6 weeks to answer email, although I do try my best to answer everything.

Todo:Coding style, Overlays, Lock, enumerating drivers, enumerating display modes, Cleaning up, Palette, COM Objects, Handling WM_ACTIVATEAPP, WM_MOVE, WM_PAINT, BltFast, Using GDI on DD surface, Showing frame rate, simple bitmap animation techniques & tile-based game techniques in DD, conv3ds and .x files, camera animation in 3d, 3d math and 3d programming basics, setting the windows size in MFC, meshbuilder stuff; explain ramp/RGB/other drivers, as well as caps, in enough detail; sprites (decals), Thanks to section; other compilers like Borland and Watcom and DJGPP, OpenGL.


URL of this document: http://www.geocities.com/SoHo/Lofts/2018/djdirectxtut.html


[Top] [Home]