Skip to content

Commit 662d455

Browse files
committed
DX Tutorials
1 parent 3f14995 commit 662d455

File tree

132 files changed

+43392
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+43392
-0
lines changed

Tutorial 1/DX10 Tutorial 1.vcxproj

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<ProjectGuid>{9A65FE1C-BA64-43AF-BDED-FA69F5CEEE7E}</ProjectGuid>
15+
<RootNamespace>DX10Tutorial1</RootNamespace>
16+
</PropertyGroup>
17+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
18+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
19+
<ConfigurationType>Application</ConfigurationType>
20+
<CharacterSet>MultiByte</CharacterSet>
21+
<WholeProgramOptimization>true</WholeProgramOptimization>
22+
</PropertyGroup>
23+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
24+
<ConfigurationType>Application</ConfigurationType>
25+
<CharacterSet>MultiByte</CharacterSet>
26+
</PropertyGroup>
27+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
28+
<ImportGroup Label="ExtensionSettings">
29+
</ImportGroup>
30+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
31+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
32+
</ImportGroup>
33+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
34+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
35+
</ImportGroup>
36+
<PropertyGroup Label="UserMacros" />
37+
<PropertyGroup>
38+
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
39+
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
40+
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
41+
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
42+
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
43+
</PropertyGroup>
44+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
45+
<ClCompile>
46+
<Optimization>Disabled</Optimization>
47+
<MinimalRebuild>true</MinimalRebuild>
48+
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
49+
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
50+
<WarningLevel>Level3</WarningLevel>
51+
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
52+
</ClCompile>
53+
<Link>
54+
<AdditionalDependencies>d3d10.lib;d3dx10.lib;%(AdditionalDependencies)</AdditionalDependencies>
55+
<GenerateDebugInformation>true</GenerateDebugInformation>
56+
<TargetMachine>MachineX86</TargetMachine>
57+
</Link>
58+
</ItemDefinitionGroup>
59+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
60+
<ClCompile>
61+
<Optimization>MaxSpeed</Optimization>
62+
<IntrinsicFunctions>true</IntrinsicFunctions>
63+
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
64+
<FunctionLevelLinking>true</FunctionLevelLinking>
65+
<WarningLevel>Level3</WarningLevel>
66+
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
67+
</ClCompile>
68+
<Link>
69+
<AdditionalDependencies>d3d10.lib;d3dx10.lib;%(AdditionalDependencies)</AdditionalDependencies>
70+
<GenerateDebugInformation>true</GenerateDebugInformation>
71+
<OptimizeReferences>true</OptimizeReferences>
72+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
73+
<TargetMachine>MachineX86</TargetMachine>
74+
</Link>
75+
</ItemDefinitionGroup>
76+
<ItemGroup>
77+
<ClCompile Include="dxManager.cpp" />
78+
<ClCompile Include="winMain.cpp" />
79+
</ItemGroup>
80+
<ItemGroup>
81+
<ClInclude Include="dxManager.h" />
82+
</ItemGroup>
83+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
84+
<ImportGroup Label="ExtensionTargets">
85+
</ImportGroup>
86+
</Project>
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="dxManager.cpp">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
<ClCompile Include="winMain.cpp">
22+
<Filter>Source Files</Filter>
23+
</ClCompile>
24+
</ItemGroup>
25+
<ItemGroup>
26+
<ClInclude Include="dxManager.h">
27+
<Filter>Header Files</Filter>
28+
</ClInclude>
29+
</ItemGroup>
30+
</Project>

Tutorial 1/dxManager.cpp

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#include "dxManager.h"
2+
3+
/*******************************************************************
4+
* Constructor
5+
*******************************************************************/
6+
dxManager::dxManager() : pD3DDevice(NULL),
7+
pSwapChain(NULL),
8+
pRenderTargetView(NULL)
9+
{
10+
11+
}
12+
/*******************************************************************
13+
* Destructor
14+
*******************************************************************/
15+
dxManager::~dxManager()
16+
{
17+
if ( pRenderTargetView ) pRenderTargetView->Release();
18+
if ( pSwapChain ) pSwapChain->Release();
19+
if ( pD3DDevice ) pD3DDevice->Release();
20+
}
21+
/*******************************************************************
22+
* Initializes Direct3D Device
23+
*******************************************************************/
24+
bool dxManager::initialize( HWND* hW )
25+
{
26+
//window handle
27+
hWnd = hW;
28+
29+
//get window dimensions
30+
RECT rc;
31+
GetClientRect( *hWnd, &rc );
32+
UINT width = rc.right - rc.left;
33+
UINT height = rc.bottom - rc.top;
34+
35+
//Set up DX swap chain
36+
//--------------------------------------------------------------
37+
DXGI_SWAP_CHAIN_DESC swapChainDesc;
38+
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
39+
40+
//set buffer dimensions and format
41+
swapChainDesc.BufferCount = 2;
42+
swapChainDesc.BufferDesc.Width = width;
43+
swapChainDesc.BufferDesc.Height = height;
44+
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
45+
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;;
46+
47+
//set refresh rate
48+
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
49+
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
50+
51+
//sampling settings
52+
swapChainDesc.SampleDesc.Quality = 0;
53+
swapChainDesc.SampleDesc.Count = 1;
54+
55+
//output window handle
56+
swapChainDesc.OutputWindow = *hWnd;
57+
swapChainDesc.Windowed = true;
58+
59+
//Create the D3D device
60+
//--------------------------------------------------------------
61+
if ( FAILED( D3D10CreateDeviceAndSwapChain( NULL,
62+
D3D10_DRIVER_TYPE_HARDWARE,
63+
NULL,
64+
0,
65+
D3D10_SDK_VERSION,
66+
&swapChainDesc,
67+
&pSwapChain,
68+
&pD3DDevice ) ) ) return fatalError("D3D device creation failed");
69+
70+
//Create render target view
71+
//--------------------------------------------------------------
72+
73+
//try to get the back buffer
74+
ID3D10Texture2D* pBackBuffer;
75+
if ( FAILED( pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*) &pBackBuffer) ) ) return fatalError("Could not get back buffer");
76+
77+
//try to create render target view
78+
if ( FAILED( pD3DDevice->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView) ) ) return fatalError("Could not create render target view");
79+
80+
//release the back buffer
81+
pBackBuffer->Release();
82+
83+
//set the render target
84+
pD3DDevice->OMSetRenderTargets(1, &pRenderTargetView, NULL);
85+
86+
//Create viewport
87+
//--------------------------------------------------------------
88+
89+
//create viewport structure
90+
viewPort.Width = width;
91+
viewPort.Height = height;
92+
viewPort.MinDepth = 0.0f;
93+
viewPort.MaxDepth = 1.0f;
94+
viewPort.TopLeftX = 0;
95+
viewPort.TopLeftY = 0;
96+
97+
//set the viewport
98+
pD3DDevice->RSSetViewports(1, &viewPort);
99+
100+
// Set up the view matrix
101+
//--------------------------------------------------------------
102+
D3DXVECTOR3 camera[3] = { D3DXVECTOR3(0.0f, 0.0f, -5.0f),
103+
D3DXVECTOR3(0.0f, 0.0f, 1.0f),
104+
D3DXVECTOR3(0.0f, 1.0f, 0.0f) };
105+
D3DXMatrixLookAtLH(&viewMatrix, &camera[0], &camera[1], &camera[2]);
106+
107+
//Set up projection matrix
108+
//--------------------------------------------------------------
109+
D3DXMatrixPerspectiveFovLH(&projectionMatrix, (float)D3DX_PI * 0.5f, (float)width/(float)height, 0.1f, 100.0f);
110+
111+
//everything completed successfully
112+
return true;
113+
}
114+
115+
/*******************************************************************
116+
* Scene Renderer
117+
*******************************************************************/
118+
void dxManager::renderScene()
119+
{
120+
//clear scene
121+
pD3DDevice->ClearRenderTargetView( pRenderTargetView, D3DXCOLOR(0,0,0,0) );
122+
123+
//SCENE RENDERING GOES HERE!!!
124+
125+
//flip buffers
126+
pSwapChain->Present(0,0);
127+
}
128+
129+
/*******************************************************************
130+
* Fatal Error Handler
131+
*******************************************************************/
132+
bool dxManager::fatalError(LPCSTR msg)
133+
{
134+
MessageBox(*hWnd, msg, "Fatal Error!", MB_ICONERROR);
135+
return false;
136+
}

Tutorial 1/dxManager.h

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifndef DXMANAGER
2+
#define DXMANAGER
3+
4+
#include <windows.h>
5+
#include <d3d10.h>
6+
#include <d3dx10.h>
7+
8+
class dxManager
9+
{
10+
/*******************************************************************
11+
* Members
12+
********************************************************************/
13+
private:
14+
15+
//window handle
16+
HWND* hWnd;
17+
18+
//device vars
19+
ID3D10Device* pD3DDevice;
20+
IDXGISwapChain* pSwapChain;
21+
ID3D10RenderTargetView* pRenderTargetView;
22+
D3D10_VIEWPORT viewPort;
23+
24+
//projection and view matrices
25+
D3DXMATRIX viewMatrix;
26+
D3DXMATRIX projectionMatrix;
27+
28+
/*******************************************************************
29+
* Methods
30+
********************************************************************/
31+
public:
32+
33+
//constructor and destructor
34+
dxManager();
35+
~dxManager();
36+
37+
//initialize directx device
38+
bool initialize(HWND*);
39+
40+
//renderScene
41+
void renderScene();
42+
43+
private:
44+
45+
//fatal error handler
46+
bool fatalError(LPCSTR msg);
47+
};
48+
49+
#endif

0 commit comments

Comments
 (0)