14
Beginning Direct3D Game Programming: 3. Programming Conventions [email protected] Division of Digital Contents, DongSeo University. April 2016

Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

Embed Size (px)

Citation preview

Page 1: Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

Beginning Direct3D Game Programming:3. Programming Conven-

[email protected]

Division of Digital Contents, DongSeo University.April 2016

Page 2: Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

Presentation Outline How to access a COM object. The naming convention (Hungarian notation) used in the

DirectX SDK. Useful debugging tips for Direct3D applications. How and why to use return codes.

2

Page 3: Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

Accessing COM Objects COM objects and C++ objects are binary-compatible so

that compilers handle COM interfaces and C++ abstract classes in the same way.

The in-memory layout in C++ of a class instance that inherits from a pure virtual base class (a class with only methods that are virtual and equal to zero) has the same memory representation as a COM interface.

hr = m_pd3dDevice->SetLight(0, &light );

3

Page 4: Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

A number of import libraries to compile a DirectX pro-gram.– d3dx9.lib– d3dxof.lib– d3d9.lib– winmm.lib– dxguid.lib

Direct3D run-time COM objects and DLLs must be regis-tered to and loaded by Windows.

You must include the previously mentioned libraries in your Windows project so that the wrapper methods you call are linked.

You must include the proper include files in your source file and in the include path entry forms of your IDE.

4

Page 5: Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

Visual Studio Library Settings

5

Page 6: Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

Visual Studio Include Directory Settings

6

Page 7: Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

LPDIRECT3D9 m_pD3D = NULL;

m_pD3D = Direct3DCreate9( D3D_SDK_VERSION );

hr = m_pD3D->CreateDevice( m_d3dSettings.AdapterOrdinal() , pDeviceInfo->DevType, m_hWndFocus , behaviorFlags , &m_d3dpp, &m_pd3dDevice );

7

Page 8: Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

Naming Conventions Hungarian Notation Camel Notation Types and constants begin with an uppercase letter, but

you can use underscores in the names, for example:

#define D3DPRESENT_BACK_BUFFERS_MAX 3L

You must prefix all C++ classes with a capital C, for ex-ample:

class CD3DMesh{public:};

8

Page 9: Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

Hungarian Notation

9

Page 10: Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

Typical Direct3D application class:class CMyD3DApplication : public CD3DApplication{

CD3DFont* m_pFont;CUSTOMVERTEX m_QuadVertices[4];LPDIRECT3DTEXTURE9 m_pCustomNormalMap;LPDIRECT3DTEXTURE9 m_pFileBasedNormalMap;D3DXVECTOR3 m_vLight;BOOL m_bUseFileBasedTexture;BOOL m_bShowNormalMap;HRESULT CreateFileBasedNormalMap();

10

Page 11: Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

Debugging DirectX The DirectX Control Panel allows you to set the debug

output level from 0 to 5. Using a memory manager can reduce memory allocation

and de-allocation problems. Visual C++ provides a memory manager called CRT.

You can debug vertex and pixel shaders with PIX or Nvidia PerfHud.

You can measure the performance of your application with something like Intel’s VTune.

The OutputDebugString() function is a useful debug-ging aid.

Using a simple log file class is helpful in larger applica-tions.

It is quite common to use a debug texture to see whether problems with texture alignment or filtering are occurring.

11

Page 12: Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

Return Codes A return code indicates the success or failure of a call

and, if applicable, the reason why the call failed. Checking the return codes is simplified by the SUC-

CEEDED() and FAILED() macros provided with the Di-rectX 9.0 SDK.– They take an HRESULT as an argument and return whether it

indicates a success code or a failure code.– Don’t try to check HRESULT against S_OK; not every method re-

turns S_OK if it succeeds. Every DirectX method returns an HRESULT

– you need to structure your code to check for and handle all po-tential errors.

12

Page 13: Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

References

13

Page 14: Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks