Download presentation
Presentation is loading. Please wait.
Published byMark Bryant Modified over 9 years ago
1
Introduction to DirectX Programming Dongho Kim February 12, 2002 Dongho Kim February 12, 2002
2
© 2001 Dongho Kim, GWU Institute for Computer Graphics 2 What is DirectX 2D/3D graphics / multimedia API Made and maintained by MicrosoftMade and maintained by Microsoft Designed for Game and Multimedia ProgrammingDesigned for Game and Multimedia Programming Works only on MS Windows platformWorks only on MS Windows platform –95/98/ME/2000/XP –Old version for Windows NT 2D/3D graphics / multimedia API Made and maintained by MicrosoftMade and maintained by Microsoft Designed for Game and Multimedia ProgrammingDesigned for Game and Multimedia Programming Works only on MS Windows platformWorks only on MS Windows platform –95/98/ME/2000/XP –Old version for Windows NT
3
© 2001 Dongho Kim, GWU Institute for Computer Graphics 3 Versions of DirectX First introduction in 1996 Goal: Easy game programming under MS WindowsGoal: Easy game programming under MS Windows Current versions DirectX 8.1 : Windows 95/98/ME/2000 (2001)DirectX 8.1 : Windows 95/98/ME/2000 (2001) –Built-in in Windows XP DirectX 3 : Windows NT 4.0DirectX 3 : Windows NT 4.0 DirectX 9 : under beta testDirectX 9 : under beta test First introduction in 1996 Goal: Easy game programming under MS WindowsGoal: Easy game programming under MS Windows Current versions DirectX 8.1 : Windows 95/98/ME/2000 (2001)DirectX 8.1 : Windows 95/98/ME/2000 (2001) –Built-in in Windows XP DirectX 3 : Windows NT 4.0DirectX 3 : Windows NT 4.0 DirectX 9 : under beta testDirectX 9 : under beta test
4
© 2001 Dongho Kim, GWU Institute for Computer Graphics 4 Versions of DirectX (cont.) Backward Compatible Applications complied with older version should work with newer versionApplications complied with older version should work with newer version Backward Compatible Applications complied with older version should work with newer versionApplications complied with older version should work with newer version
5
© 2001 Dongho Kim, GWU Institute for Computer Graphics 5 Components of DirectX Direct3D DirectDraw: integrated into Direct3D in DX 8 DirectShow: integrated into Direct3D in DX 8 DirectSound / DirectMusic DirectInputDirectPlayDirectSetupDirect3D DirectDraw: integrated into Direct3D in DX 8 DirectShow: integrated into Direct3D in DX 8 DirectSound / DirectMusic DirectInputDirectPlayDirectSetup
6
© 2001 Dongho Kim, GWU Institute for Computer Graphics 6 Comparison of DirectX and OpenGL (1) DirectX Controlled by Microsoft; frequent updatesControlled by Microsoft; frequent updates Many features for game programmingMany 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 updatesControlled by OpenGL ARB; only a few updates General purpose 2D/3D graphics API; 2D is weakGeneral purpose 2D/3D graphics API; 2D is weakDirectX Controlled by Microsoft; frequent updatesControlled by Microsoft; frequent updates Many features for game programmingMany 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 updatesControlled by OpenGL ARB; only a few updates General purpose 2D/3D graphics API; 2D is weakGeneral purpose 2D/3D graphics API; 2D is weak
7
© 2001 Dongho Kim, GWU Institute for Computer Graphics 7 Comparison of DirectX and OpenGL (2) DirectX Only Microsoft Windows platform; MMX, 3DNowOnly Microsoft Windows platform; MMX, 3DNow Rather difficult to learnRather difficult to learn –not many documentation; stick to MS documentations OpenGL Platform independent (Windows, Linux, Unix, Apple, …)Platform independent (Windows, Linux, Unix, Apple, …) Rather easy to learn; many 3 rd party documentationsRather easy to learn; many 3 rd party documentationsDirectX Only Microsoft Windows platform; MMX, 3DNowOnly Microsoft Windows platform; MMX, 3DNow Rather difficult to learnRather difficult to learn –not many documentation; stick to MS documentations OpenGL Platform independent (Windows, Linux, Unix, Apple, …)Platform independent (Windows, Linux, Unix, Apple, …) Rather easy to learn; many 3 rd party documentationsRather easy to learn; many 3 rd party documentations
8
© 2001 Dongho Kim, GWU Institute for Computer Graphics 8 DirectX 8.1 SDK InstallationInstallation
9
© 2001 Dongho Kim, GWU Institute for Computer Graphics 9 Using DirectX SDK (1) http://www.microsoft.com/directx Include and Lib directories DocumentationSamplesUtilities Paths are included in Visual C++ automatically (DX8)Paths are included in Visual C++ automatically (DX8) http://www.microsoft.com/directx Include and Lib directories DocumentationSamplesUtilities Paths are included in Visual C++ automatically (DX8)Paths are included in Visual C++ automatically (DX8)
10
© 2001 Dongho Kim, GWU Institute for Computer Graphics 10 Using DirectX SDK (2) Direct3DX library Similar to GLU in OpenGLSimilar to GLU in OpenGL Collection of useful functionalitiesCollection of useful functionalities –Math, Mesh, Shader, … –Interfaces starting with “ID3DX” –Functions starting with “D3DX” Direct3DX library Similar to GLU in OpenGLSimilar to GLU in OpenGL Collection of useful functionalitiesCollection of useful functionalities –Math, Mesh, Shader, … –Interfaces starting with “ID3DX” –Functions starting with “D3DX”
11
© 2001 Dongho Kim, GWU Institute for Computer Graphics 11 Using DirectX SDK (3) “Common” directory (DX8) C++ source codeC++ source code Not part of DirectX, but contains useful source codesNot part of DirectX, but contains useful source codes –DirectX initialization, window creation, … Most of the samples link with this partMost of the samples link with this part “Common” directory (DX8) C++ source codeC++ source code Not part of DirectX, but contains useful source codesNot part of DirectX, but contains useful source codes –DirectX initialization, window creation, … Most of the samples link with this partMost of the samples link with this part
12
© 2001 Dongho Kim, GWU Institute for Computer Graphics 12 Demo: DirectX 8.1 Samples Most of the features are shown Start your own project from a sample in DirectX SDK Most of the features are shown Start your own project from a sample in DirectX SDK
13
© 2001 Dongho Kim, GWU Institute for Computer Graphics 13 COM (Component Object Model) DirectX libraries are implemented as COM COM object is a black box performing one or more tasks Similar to C++ objectsSimilar to C++ objects Implemented as DLLImplemented as DLL Stricter encapsulationStricter encapsulation Not explicitly loadedNot explicitly loaded Supports many programming languagesSupports many programming languages DirectX libraries are implemented as COM COM object is a black box performing one or more tasks Similar to C++ objectsSimilar to C++ objects Implemented as DLLImplemented as DLL Stricter encapsulationStricter encapsulation Not explicitly loadedNot explicitly loaded Supports many programming languagesSupports many programming languages
14
© 2001 Dongho Kim, GWU Institute for Computer Graphics 14 Programming with COM May be complex But it is not so difficult We do not make COM objectsWe do not make COM objects We simply use COM objectsWe simply use COM objects Interface is used to access the the functionality of COM objectsInterface is used to access the the functionality of COM objects –Class names start with I Start from the samples with “Common” filesStart from the samples with “Common” files May be complex But it is not so difficult We do not make COM objectsWe do not make COM objects We simply use COM objectsWe simply use COM objects Interface is used to access the the functionality of COM objectsInterface is used to access the the functionality of COM objects –Class names start with I Start from the samples with “Common” filesStart from the samples with “Common” files
15
© 2001 Dongho Kim, GWU Institute for Computer Graphics 15 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; IDirect3DDevice8 *g_pd3dDevice = NULL;...... if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, 3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ))) return E_FAIL;
16
© 2001 Dongho Kim, GWU Institute for Computer Graphics 16 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 MFCMost of the examples are written without MFC –Mostly performance issues in games Only some of them are written with MFCOnly some of them are written with MFC 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 MFCMost of the examples are written without MFC –Mostly performance issues in games Only some of them are written with MFCOnly some of them are written with MFC
17
© 2001 Dongho Kim, GWU Institute for Computer Graphics 17 Lecture from now on Focus on Direct3D Follow the tutorials in DX8.1 SDK Tutorials do not use “Common” files, thoughTutorials do not use “Common” files, though Samples using “Common” files Focus on Direct3D Follow the tutorials in DX8.1 SDK Tutorials do not use “Common” files, thoughTutorials do not use “Common” files, though Samples using “Common” files
18
© 2001 Dongho Kim, GWU Institute for Computer Graphics 18 Tutorial 1: CreateDevice
19
© 2001 Dongho Kim, GWU Institute for Computer Graphics 19 Tutorial 2: Vertices
20
© 2001 Dongho Kim, GWU Institute for Computer Graphics 20 Tutorial 3: Matrices
21
© 2001 Dongho Kim, GWU Institute for Computer Graphics 21 Tutorial 4: Lights
22
© 2001 Dongho Kim, GWU Institute for Computer Graphics 22 Tutorial 5: Textures
23
© 2001 Dongho Kim, GWU Institute for Computer Graphics 23 Tutorial 6: Meshes
24
© 2001 Dongho Kim, GWU Institute for Computer Graphics 24 Sample: Billboard
25
© 2001 Dongho Kim, GWU Institute for Computer Graphics 25 Extras in SDK X file exporter 3D Studio MAX version 3 / 43D Studio MAX version 3 / 4 Maya version 2.5 / 3.0 / 4.0Maya version 2.5 / 3.0 / 4.0 X file exporter 3D Studio MAX version 3 / 43D Studio MAX version 3 / 4 Maya version 2.5 / 3.0 / 4.0Maya version 2.5 / 3.0 / 4.0
26
© 2001 Dongho Kim, GWU Institute for Computer Graphics 26 Next week Advanced features Programmable shaderProgrammable shader –Vertex shader / Vertex program –Pixel shader / register combiner Multi-texturing / Multi-pass texturingMulti-texturing / Multi-pass texturing Game specific topics joystick, frame rate control, etc…joystick, frame rate control, etc… Advanced features Programmable shaderProgrammable shader –Vertex shader / Vertex program –Pixel shader / register combiner Multi-texturing / Multi-pass texturingMulti-texturing / Multi-pass texturing Game specific topics joystick, frame rate control, etc…joystick, frame rate control, etc…
27
© 2001 Dongho Kim, GWU Institute for Computer Graphics 27 Bookmarks http://www.microsoft.com/directxhttp://www.microsoft.com/directxhttp://www.microsoft.com/directx microsoft.public.win32.programmer.directxmicrosoft.public.win32.programmer.directx microsoft.public.directxmicrosoft.public.directx OpenGL vs DirectX comparison http://www.xmission.com/~legalize/d3d-vs-opengl.htmlhttp://www.xmission.com/~legalize/d3d-vs-opengl.htmlhttp://www.xmission.com/~legalize/d3d-vs-opengl.html http://www.microsoft.com/directxhttp://www.microsoft.com/directxhttp://www.microsoft.com/directx microsoft.public.win32.programmer.directxmicrosoft.public.win32.programmer.directx microsoft.public.directxmicrosoft.public.directx OpenGL vs DirectX comparison http://www.xmission.com/~legalize/d3d-vs-opengl.htmlhttp://www.xmission.com/~legalize/d3d-vs-opengl.htmlhttp://www.xmission.com/~legalize/d3d-vs-opengl.html
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.