beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks

Post on 13-Feb-2017

16 Views

Category:

Engineering

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Beginning Direct3D Game Programming:3. Programming Conven-

tionsjintaeks@gmail.com

Division of Digital Contents, DongSeo University.April 2016

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

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

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

Visual Studio Library Settings

5

Visual Studio Include Directory Settings

6

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

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

Hungarian Notation

9

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

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

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

References

13

top related