270 likes | 435 Views
Introduction to DirectX Programming. Dongho Kim February 12, 2002. What is DirectX. 2D/3D graphics / multimedia API Made and maintained by Microsoft Designed for Game and Multimedia Programming Works only on MS Windows platform 95/98/ME/2000/XP Old version for Windows NT.
E N D
Introduction toDirectX Programming Dongho Kim February 12, 2002
What is DirectX • 2D/3D graphics / multimedia API • Made and maintained by Microsoft • Designed for Game and Multimedia Programming • Works only on MS Windows platform • 95/98/ME/2000/XP • Old version for Windows NT © 2001 Dongho Kim, GWU Institute for Computer Graphics
Versions of DirectX • First introduction in 1996 • Goal: Easy game programming under MS Windows • Current versions • DirectX 8.1 : Windows 95/98/ME/2000 (2001) • Built-in in Windows XP • DirectX 3 : Windows NT 4.0 • DirectX 9 : under beta test © 2001 Dongho Kim, GWU Institute for Computer Graphics
Versions of DirectX (cont.) • Backward Compatible • Applications complied with older version should work with newer version © 2001 Dongho Kim, GWU Institute for Computer Graphics
Components of DirectX • Direct3D • DirectDraw: integrated into Direct3D in DX 8 • DirectShow: integrated into Direct3D in DX 8 • DirectSound / DirectMusic • DirectInput • DirectPlay • DirectSetup © 2001 Dongho Kim, GWU Institute for Computer Graphics
Comparison ofDirectX and OpenGL (1) • DirectX • Controlled by Microsoft; frequent updates • Many features for game programming • Sound, input, media stream, … • Non-core functionality such as file format reader (image and 3D model) • OpenGL • Controlled by OpenGL ARB; only a few updates • General purpose 2D/3D graphics API; 2D is weak © 2001 Dongho Kim, GWU Institute for Computer Graphics
Comparison ofDirectX and OpenGL (2) • DirectX • Only Microsoft Windows platform; MMX, 3DNow • Rather difficult to learn • not many documentation; stick to MS documentations • OpenGL • Platform independent (Windows, Linux, Unix, Apple, …) • Rather easy to learn; many 3rd party documentations © 2001 Dongho Kim, GWU Institute for Computer Graphics
DirectX 8.1 SDK • Installation © 2001 Dongho Kim, GWU Institute for Computer Graphics
Using DirectX SDK (1) http://www.microsoft.com/directx • Include and Lib directories • Documentation • Samples • Utilities • Paths are included in Visual C++ automatically (DX8) © 2001 Dongho Kim, GWU Institute for Computer Graphics
Using DirectX SDK (2) • Direct3DX library • Similar to GLU in OpenGL • Collection of useful functionalities • Math, Mesh, Shader, … • Interfaces starting with “ID3DX” • Functions starting with “D3DX” © 2001 Dongho Kim, GWU Institute for Computer Graphics
Using DirectX SDK (3) • “Common” directory (DX8) • C++ source code • Not part of DirectX, but contains useful source codes • DirectX initialization, window creation, … • Most of the samples link with this part © 2001 Dongho Kim, GWU Institute for Computer Graphics
Demo: DirectX 8.1 Samples • Most of the features are shown • Start your own project from a sample in DirectX SDK © 2001 Dongho Kim, GWU Institute for Computer Graphics
COM(Component Object Model) • DirectX libraries are implemented as COM • COM object is a black box performing one or more tasks • Similar to C++ objects • Implemented as DLL • Stricter encapsulation • Not explicitly loaded • Supports many programming languages © 2001 Dongho Kim, GWU Institute for Computer Graphics
Programming with COM • May be complex • But it is not so difficult • We do not make COM objects • We simply use COM objects • Interface is used to access the the functionality of COM objects • Class names start with I • Start from the samples with “Common” files © 2001 Dongho Kim, GWU Institute for Computer Graphics
Example of COM instantiation IDirect3DDevice8 *g_pd3dDevice = NULL; ... if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, 3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ))) return E_FAIL; © 2001 Dongho Kim, GWU Institute for Computer Graphics
Recommendations on how to start DirectX programming • Some knowledge on Windows Programming is required • Start with Newest version, DirectX 8.1 • Start from the SAMPLES in the SDK • Most of the examples are written without MFC • Mostly performance issues in games • Only some of them are written with MFC © 2001 Dongho Kim, GWU Institute for Computer Graphics
Lecture from now on • Focus on Direct3D • Follow the tutorials in DX8.1 SDK • Tutorials do not use “Common” files, though • Samples using “Common” files © 2001 Dongho Kim, GWU Institute for Computer Graphics
Tutorial 1: CreateDevice © 2001 Dongho Kim, GWU Institute for Computer Graphics
Tutorial 2: Vertices © 2001 Dongho Kim, GWU Institute for Computer Graphics
Tutorial 3: Matrices © 2001 Dongho Kim, GWU Institute for Computer Graphics
Tutorial 4: Lights © 2001 Dongho Kim, GWU Institute for Computer Graphics
Tutorial 5: Textures © 2001 Dongho Kim, GWU Institute for Computer Graphics
Tutorial 6: Meshes © 2001 Dongho Kim, GWU Institute for Computer Graphics
Sample: Billboard © 2001 Dongho Kim, GWU Institute for Computer Graphics
Extras in SDK • X file exporter • 3D Studio MAX version 3 / 4 • Maya version 2.5 / 3.0 / 4.0 © 2001 Dongho Kim, GWU Institute for Computer Graphics
Next week • Advanced features • Programmable shader • Vertex shader / Vertex program • Pixel shader / register combiner • Multi-texturing / Multi-pass texturing • Game specific topics • joystick, frame rate control, etc… © 2001 Dongho Kim, GWU Institute for Computer Graphics
Bookmarks • http://www.microsoft.com/directx • microsoft.public.win32.programmer.directx • microsoft.public.directx • OpenGL vs DirectX comparison • http://www.xmission.com/~legalize/d3d-vs-opengl.html © 2001 Dongho Kim, GWU Institute for Computer Graphics