03. Initializing Direct3D 11

全局变量

IDXGISwapChain* SwapChain;
ID3D11Device* d3d11Device;
ID3D11DeviceContext* d3d11DevCon;
ID3D11RenderTargetView* renderTargetView;

float red = 0.0f;
float green = 0.0f;
float blue = 0.0f;
int colormodr = 1;
int colormodg = 1;
int colormodb = 1;

函数原型
bool InitializeDirect3d11App(HINSTANCE hInstance);
void ReleaseObjects();
bool InitScene();
void UpdateScene();
void DrawScene();
if(!InitializeDirect3d11App(hInstance))    //Initialize Direct3D
{
    MessageBox(0, L"Direct3D Initialization - Failed",
        L"Error", MB_OK);
    return 0;
}

if(!InitScene())    //Initialize our scene
{
    MessageBox(0, L"Scene Initialization - Failed",
        L"Error", MB_OK);
    return 0;
}

messageloop();

ReleaseObjects();    
 

Initializing Direct3D 11初始化dx11

 1 bool InitializeDirect3dApp(HINSTANCE hInstance)
 2 {
 3 HRESULT hr;
 4
 5 //Describe our Buffer
 6 DXGI_MODE_DESC bufferDesc;
 7
 8 ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC));
 9
10 bufferDesc.Width = Width;
11 bufferDesc.Height = Height;
12 bufferDesc.RefreshRate.Numerator = 60;
13 bufferDesc.RefreshRate.Denominator = 1;
14 bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15 bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
16 bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
17
18 //Describe our SwapChain
19 DXGI_SWAP_CHAIN_DESC swapChainDesc;
20
21 ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
22
23 swapChainDesc.BufferDesc = bufferDesc;
24 swapChainDesc.SampleDesc.Count = 1;
25 swapChainDesc.SampleDesc.Quality = 0;
26 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
27 swapChainDesc.BufferCount = 1;
28 swapChainDesc.OutputWindow = hwnd;
29 swapChainDesc.Windowed = TRUE;
30 swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
31
32
33 //Create our SwapChain
34 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL,
35     D3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, NULL, &d3d11DevCon);
36
37 //Create our BackBuffer
38 ID3D11Texture2D* BackBuffer;
39 hr = SwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (void**)&BackBuffer );
40
41 //Create our Render Target
42 hr = d3d11Device->CreateRenderTargetView( BackBuffer, NULL, &renderTargetView );
43 BackBuffer->Release();
44
45 //Set our Render Target
46 d3d11DevCon->OMSetRenderTargets( 1, &renderTargetView, NULL );
47
48 return true;
49 }

Describing the BackBuffer( DXGI_MODE_DESC )

typedef struct DXGI_MODE_DESC {
  UINT                     Width;//宽度
  UINT                     Height;//高度
  DXGI_RATIONAL            RefreshRate;//刷新率 设为60HZ
  DXGI_FORMAT              Format;//显示方式 rgba每个8bit 一共32bit
  DXGI_MODE_SCANLINE_ORDER ScanlineOrdering;//渲染方式 不指定 双缓冲无所谓
  DXGI_MODE_SCALING        Scaling;//缩放 不指定
} DXGI_MODE_DESC, *LPDXGI_MODE_DESC;
DXGI_MODE_DESC bufferDesc;

ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC));

bufferDesc.Width = Width;
bufferDesc.Height = Height;
bufferDesc.RefreshRate.Numerator = 60;
bufferDesc.RefreshRate.Denominator = 1;
bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;//渲染方式不指定
bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;//缩放不指定

Describing the SwapChain( DXGI_MODE_DESC )

typedef struct DXGI_SWAP_CHAIN_DESC {
  DXGI_MODE_DESC   BufferDesc;// 上述的backbuffer
  DXGI_SAMPLE_DESC SampleDesc;//采样方式
  DXGI_USAGE       BufferUsage;//
  UINT             BufferCount;//缓冲区数量 1:双缓冲 2:三缓冲
  HWND             OutputWindow;//我们自己的输出窗口
  BOOL             Windowed;//是否窗口化
  DXGI_SWAP_EFFECT SwapEffect;//cpu访问后台缓冲区的方式
  UINT             Flags;//额外的标志
} DXGI_SWAP_CHAIN_DESC;
DXGI_SWAP_CHAIN_DESC swapChainDesc; 

ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));

swapChainDesc.BufferDesc = bufferDesc;
swapChainDesc.SampleDesc.Count = 1;//每个像素多重采样的数量
swapChainDesc.SampleDesc.Quality = 0;//质量
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = 1;
swapChainDesc.OutputWindow = hwnd;
swapChainDesc.Windowed = TRUE;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

Creating the Device and SwapChain( D3D11CreateDeviceAndSwapChain() )


HRESULT D3D11CreateDeviceAndSwapChain(
  __in   IDXGIAdapter *pAdapter,//我们使用的adapter NULL使用默认的
  __in   D3D_DRIVER_TYPE DriverType,//direct3d要怎么实现 D3D_DRIVER_TYPE_HARDWARE将由gpu来实现
  __in   HMODULE Software,//软件栅格化的句柄 NULL
  __in   UINT Flags,//NULL
  __in   const D3D_FEATURE_LEVEL *pFeatureLevels,//NULL 使用最好的
  __in   UINT FeatureLevels,//NULL
  __in   UINT SDKVersion,//D3D11_SDK_VERSION
  __in   const DXGI_SWAP_CHAIN_DESC *pSwapChainDesc,//刚创建的交换链
  __out  IDXGISwapChain **ppSwapChain,//接收我们刚创建的交换链
  __out  ID3D11Device **ppDevice,//device
  __out  D3D_FEATURE_LEVEL *pFeatureLevel,//D3D_FEATURE_LEVEL 最高的
  __out  ID3D11DeviceContext **ppImmediateContext//device context
);
hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL,
    D3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, NULL, &d3d11DevCon);

Creating the BackBuffer( GetBuffer() )

HRESULT GetBuffer(
  [in]       UINT Buffer,//0
  [in]       REFIID riid,//ID3D11Texture2D 改变后缓冲区的借口类型的引用id
  [in, out]  void **ppSurface//backbuffer
);
ID3D11Texture2D* BackBuffer;
hr = SwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (void**)&BackBuffer );

Creating the Render Target( ID3D11Device::CreateRenderTargetView() ) and release backbuffer

HRESULT CreateRenderTargetView(
  [in]   ID3D11Resource *pResource,//Back buffer
  [in]   const D3D11_RENDER_TARGET_VIEW_DESC *pDesc,//设null创建一个视图来访问mipmap为0的所有子资源
  [out]  ID3D11RenderTargetView **ppRTView//rendertarget

hr = d3d11Device->CreateRenderTargetView( BackBuffer, NULL, &renderTargetView );
BackBuffer->Release();

Set the Render Targets( ID3D11DeviceContext::OMSetRenderTargets() )

void OMSetRenderTargets(
  [in]  UINT NumViews,//需要绑定的View 数目 我们只有一个
  [in]  ID3D11RenderTargetView *const **ppRenderTargetViews,//需要绑定的view
  [in]  ID3D11DepthStencilView *pDepthStencilView//深度模板 没有设NULL
);

Clean Up

释放所有我们创建的com objects

void ReleaseObjects()
{
    //Release the COM Objects we created
    SwapChain->Release();
    d3d11Device->Release();
    d3dDevCon->Release();
}

Initialize Scene

初始化场景
bool InitScene()
{

    return true;
}

Update Scene

更新场景,如改变objects 位置,改变值,场景内的任何改变,本节只改变背景颜色

 1 void UpdateScene()
 2 {
 3     //Update the colors of our scene
 4     red += colormodr * 0.00005f;
 5     green += colormodg * 0.00002f;
 6     blue += colormodb * 0.00001f;
 7
 8     if(red >= 1.0f || red <= 0.0f)
 9         colormodr *= -1;
10     if(green >= 1.0f || green <= 0.0f)
11         colormodg *= -1;
12     if(blue >= 1.0f || blue <= 0.0f)
13         colormodb *= -1;
14 }

Render Scene

DrawScene() render 我们的场景,该函数只渲染场景不更新场景 交换前后缓冲区,掉present会将back buffer 渲染到屏幕

 1 void DrawScene()
 2 {
 3     //Clear our backbuffer to the updated color
 4     D3DXCOLOR bgColor( red, green, blue, 1.0f );
 5
 6     d3d11DevCon->ClearRenderTargetView(renderTargetView, bgColor);
 7
 8     //Present the backbuffer to the screen
 9     SwapChain->Present(0, 0);
10 }
messageloop()方法,先调用UpdateScene() 更新场景,然后然后掉DrawScene()把backbuffer渲染到屏幕

 1 int messageloop(){
 2 MSG msg;
 3 ZeroMemory(&msg, sizeof(MSG));
 4 while(true)
 5 {
 6     BOOL PeekMessageL(
 7         LPMSG lpMsg,
 8         HWND hWnd,
 9         UINT wMsgFilterMin,
10         UINT wMsgFilterMax,
11         UINT wRemoveMsg
12         );
13
14     if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
15     {
16         if (msg.message == WM_QUIT)
17             break;
18         TranslateMessage(&msg);
19         DispatchMessage(&msg);
20     }
21     else{
22 ///////////////**************new**************////////////////////
23         // run game code
24
25         UpdateScene();
26         DrawScene();
27
28 ///////////////**************new**************////////////////////
29     }
30 }
31 return msg.wParam;
32 }

Error Checking:

DXGetErrorDescription 这个没找到
bool InitializeDirect3d11App(HINSTANCE hInstance)
{
    HRESULT hr;

    //Describe our Buffer
    DXGI_MODE_DESC bufferDesc;

    ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC));

    bufferDesc.Width = Width;
    bufferDesc.Height = Height;
    bufferDesc.RefreshRate.Numerator = 60;
    bufferDesc.RefreshRate.Denominator = 1;
    bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
    bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

    //Describe our SwapChain
    DXGI_SWAP_CHAIN_DESC swapChainDesc; 

    ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));

    swapChainDesc.BufferDesc = bufferDesc;
    swapChainDesc.SampleDesc.Count = 1;
    swapChainDesc.SampleDesc.Quality = 0;
    swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    swapChainDesc.BufferCount = 1;
    swapChainDesc.OutputWindow = hwnd;
    swapChainDesc.Windowed = TRUE;
    swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

    //Create our SwapChain
    hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL,
        D3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, NULL, &d3d11DevCon);
    if(FAILED(hr))
    {
        //MessageBoxW(NULL, DXGetErrorDescription(hr),
            //TEXT(" D3D11CreateDeviceAndSwapChain"), MB_OK);
        return 0;
    }    

    //Create our BackBuffer
    ID3D11Texture2D* BackBuffer;
    hr = SwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (void**)&BackBuffer );
    if(FAILED(hr))
    {
        //MessageBoxW(NULL, DXGetErrorDescription(hr),
            //TEXT("SwapChain->GetBuffer"), MB_OK);
        return 0;
    }    

    //Create our Render Target
    hr = d3d11Device->CreateRenderTargetView( BackBuffer, NULL, &renderTargetView );
    BackBuffer->Release();
    if(FAILED(hr))
    {
        //MessageBoxW(NULL, DXGetErrorDescription(hr),
            //TEXT("d3d11Device->CreateRenderTargetView"), MB_OK);
        return 0;
    }    

    //Set our Render Target
    d3d11DevCon->OMSetRenderTargets( 1, &renderTargetView, NULL );

    return true;
}
  1 ///////////////**************new**************////////////////////
  2
  3 #include <windows.h>
  4 #include <d3d11.h>
  5 #include <d3dx11.h>
  6 #include <d3dx10.h>
  7 #include <xnamath.h>
  8
  9 //Global Declarations//
 10 IDXGISwapChain* SwapChain;
 11 ID3D11Device* d3d11Device;
 12 ID3D11DeviceContext* d3d11DevCon;
 13 ID3D11RenderTargetView* renderTargetView;
 14
 15 float red = 0.0f;
 16 float green = 0.0f;
 17 float blue = 0.0f;
 18 int colormodr = 1;
 19 int colormodg = 1;
 20 int colormodb = 1;
 21
 22 ///////////////**************new**************////////////////////
 23
 24 LPCTSTR WndClassName = L"firstwindow";
 25 HWND hwnd = NULL;
 26
 27 const int Width  = 300;
 28 const int Height = 300;
 29
 30 ///////////////**************new**************////////////////////
 31
 32 //Function Prototypes//
 33 bool InitializeDirect3d11App(HINSTANCE hInstance);
 34 void ReleaseObjects();
 35 bool InitScene();
 36 void UpdateScene();
 37 void DrawScene();
 38
 39 ///////////////**************new**************////////////////////
 40
 41 bool InitializeWindow(HINSTANCE hInstance,
 42                       int ShowWnd,
 43                       int width, int height,
 44                       bool windowed);
 45 int messageloop();
 46
 47 LRESULT CALLBACK WndProc(HWND hWnd,
 48                          UINT msg,
 49                          WPARAM wParam,
 50                          LPARAM lParam);
 51
 52
 53 int WINAPI WinMain(HINSTANCE hInstance,    //Main windows function
 54                    HINSTANCE hPrevInstance,
 55                    LPSTR lpCmdLine,
 56                    int nShowCmd)
 57 {
 58
 59     if(!InitializeWindow(hInstance, nShowCmd, Width, Height, true))
 60     {
 61         MessageBox(0, L"Window Initialization - Failed",
 62             L"Error", MB_OK);
 63         return 0;
 64     }
 65
 66     ///////////////**************new**************////////////////////
 67
 68     if(!InitializeDirect3d11App(hInstance))    //Initialize Direct3D
 69     {
 70         MessageBox(0, L"Direct3D Initialization - Failed",
 71             L"Error", MB_OK);
 72         return 0;
 73     }
 74
 75     if(!InitScene())    //Initialize our scene
 76     {
 77         MessageBox(0, L"Scene Initialization - Failed",
 78             L"Error", MB_OK);
 79         return 0;
 80     }
 81
 82     messageloop();
 83
 84     ReleaseObjects();
 85
 86     ///////////////**************new**************////////////////////
 87
 88     return 0;
 89 }
 90
 91 bool InitializeWindow(HINSTANCE hInstance,
 92                       int ShowWnd,
 93                       int width, int height,
 94                       bool windowed)
 95 {
 96     typedef struct _WNDCLASS {
 97         UINT cbSize;
 98         UINT style;
 99         WNDPROC lpfnWndProc;
100         int cbClsExtra;
101         int cbWndExtra;
102         HANDLE hInstance;
103         HICON hIcon;
104         HCURSOR hCursor;
105         HBRUSH hbrBackground;
106         LPCTSTR lpszMenuName;
107         LPCTSTR lpszClassName;
108     } WNDCLASS;
109
110     WNDCLASSEX wc;
111
112     wc.cbSize = sizeof(WNDCLASSEX);
113     wc.style = CS_HREDRAW | CS_VREDRAW;
114     wc.lpfnWndProc = WndProc;
115     wc.cbClsExtra = NULL;
116     wc.cbWndExtra = NULL;
117     wc.hInstance = hInstance;
118     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
119     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
120     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 2);
121     wc.lpszMenuName = NULL;
122     wc.lpszClassName = WndClassName;
123     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
124
125     if (!RegisterClassEx(&wc))
126     {
127         MessageBox(NULL, L"Error registering class",
128             L"Error", MB_OK | MB_ICONERROR);
129         return 1;
130     }
131
132     hwnd = CreateWindowEx(
133         NULL,
134         WndClassName,
135         L"Window Title",
136         WS_OVERLAPPEDWINDOW,
137         CW_USEDEFAULT, CW_USEDEFAULT,
138         width, height,
139         NULL,
140         NULL,
141         hInstance,
142         NULL
143         );
144
145     if (!hwnd)
146     {
147         MessageBox(NULL, L"Error creating window",
148             L"Error", MB_OK | MB_ICONERROR);
149         return 1;
150     }
151
152     ShowWindow(hwnd, ShowWnd);
153     UpdateWindow(hwnd);
154
155     return true;
156 }
157
158 ///////////////**************new**************////////////////////
159
160 bool InitializeDirect3d11App(HINSTANCE hInstance)
161 {
162     //Describe our Buffer
163     DXGI_MODE_DESC bufferDesc;
164
165     ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC));
166
167     bufferDesc.Width = Width;
168     bufferDesc.Height = Height;
169     bufferDesc.RefreshRate.Numerator = 60;
170     bufferDesc.RefreshRate.Denominator = 1;
171     bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
172     bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
173     bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
174
175     //Describe our SwapChain
176     DXGI_SWAP_CHAIN_DESC swapChainDesc;
177
178     ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
179
180     swapChainDesc.BufferDesc = bufferDesc;
181     swapChainDesc.SampleDesc.Count = 1;
182     swapChainDesc.SampleDesc.Quality = 0;
183     swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
184     swapChainDesc.BufferCount = 1;
185     swapChainDesc.OutputWindow = hwnd;
186     swapChainDesc.Windowed = TRUE;
187     swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
188
189
190     //Create our SwapChain
191     D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL,
192         D3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, NULL, &d3d11DevCon);
193
194     //Create our BackBuffer
195     ID3D11Texture2D* BackBuffer;
196     SwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (void**)&BackBuffer );
197
198     //Create our Render Target
199     d3d11Device->CreateRenderTargetView( BackBuffer, NULL, &renderTargetView );
200     BackBuffer->Release();
201
202     //Set our Render Target
203     d3d11DevCon->OMSetRenderTargets( 1, &renderTargetView, NULL );
204
205     return true;
206 }
207
208 void ReleaseObjects()
209 {
210     //Release the COM Objects we created
211     SwapChain->Release();
212     d3d11Device->Release();
213     d3d11DevCon->Release();
214 }
215 bool InitScene()
216 {
217
218     return true;
219 }
220
221 void UpdateScene()
222 {
223     //Update the colors of our scene
224     red += colormodr * 0.00005f;
225     green += colormodg * 0.00002f;
226     blue += colormodb * 0.00001f;
227
228     if(red >= 1.0f || red <= 0.0f)
229         colormodr *= -1;
230     if(green >= 1.0f || green <= 0.0f)
231         colormodg *= -1;
232     if(blue >= 1.0f || blue <= 0.0f)
233         colormodb *= -1;
234 }
235
236 void DrawScene()
237 {
238     //Clear our backbuffer to the updated color
239     D3DXCOLOR bgColor( red, green, blue, 1.0f );
240
241     d3d11DevCon->ClearRenderTargetView(renderTargetView, bgColor);
242
243     //Present the backbuffer to the screen
244     SwapChain->Present(0, 0);
245 }
246
247 ///////////////**************new**************////////////////////
248
249 int messageloop(){
250     MSG msg;
251     ZeroMemory(&msg, sizeof(MSG));
252     while(true)
253     {
254         BOOL PeekMessageL(
255             LPMSG lpMsg,
256             HWND hWnd,
257             UINT wMsgFilterMin,
258             UINT wMsgFilterMax,
259             UINT wRemoveMsg
260             );
261
262         if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
263         {
264             if (msg.message == WM_QUIT)
265                 break;
266             TranslateMessage(&msg);
267             DispatchMessage(&msg);
268         }
269         else{
270             ///////////////**************new**************////////////////////
271             // run game code
272
273             UpdateScene();
274             DrawScene();
275
276             ///////////////**************new**************////////////////////
277         }
278     }
279     return msg.wParam;
280 }
281
282 LRESULT CALLBACK WndProc(HWND hwnd,
283                          UINT msg,
284                          WPARAM wParam,
285                          LPARAM lParam)
286 {
287     switch( msg )
288     {
289     case WM_KEYDOWN:
290         if( wParam == VK_ESCAPE ){
291             DestroyWindow(hwnd);
292         }
293         return 0;
294
295     case WM_DESTROY:
296         PostQuitMessage(0);
297         return 0;
298     }
299     return DefWindowProc(hwnd,
300         msg,
301         wParam,
302         lParam);
303 }

工程设置如下:


				
时间: 2024-10-28 20:53:40

03. Initializing Direct3D 11的相关文章

INITIALIZING DIRECT3D

初始化Direct3D需要一下几个步骤: 1. Create the ID3D11Device and ID3D11DeviceContext interfaces using the D3D11CreateDevice function.2. Check 4X MSAA quality level support using the ID3D11Device::CheckMultisampleQualityLevels method.3. Describe the characteristic

[转]Direct3D 11 Tessellation Tutorial

The new hardware tessellation feature available on Direct3D 11 video cards has great potential, but using it effectively currently requires understanding higher-order surfaces as well as a myriad of performance implications. In addition to the Window

Direct3D 11第四节 3D Spaces

引言 3D 坐标系 Object Space对象坐标系 World Space世界坐标系 View Space视坐标系 坐标系转换 World Transformation世界变换 View Transformation视变换 Projection Transformation投影变换 使用变换 修改顶点缓存 修改顶点着色器 设置矩阵 更新常量缓存 引言 这节,我们将深入研究3D位置和转换.这节的目标就是将一个3D物体绘制到屏幕上. 3D 坐标系 为了在世界中的某个位置放一个物体,我们需要使用坐

【译】Import Changes from Direct3D 11 to Direct3D 12

译者:林公子 出处:木木的二进制人生 转载请注明作者和出处,谢谢! 这是微软公布的Direct3D 12文档的其中一篇,此翻译留作学习记录备忘,水平有限,错漏难免,还望海涵. 原文链接是https://msdn.microsoft.com/en-us/library/windows/desktop/dn899194(v=vs.85).aspx Direct3D 12到Direct3D 11的重大改变 Direct3D 12是对Direct3D 11编程模型的一个巨大颠覆.Direct3D 12让

Direct3D 11 Tutorial 2: Rendering a Triangle_Direct3D 11 教程2:渲染一个三角形

概要 在之前的教程中,我们建立了一个最小的Direct3D 11的应用程序,它用来在窗口上输出一个单一颜色.在本次教程中,我们将扩展这个应用程序,在屏幕上渲染出一个单一颜色的三角形.我们将通过设置数据机构的过程关联到三角形. 这个教程的输出结果是在窗口中央渲染出一个三角形. 资源目录 (SDK root)\Samples\C++\Direct3D11\Tutorials\Tutorial02 Github-LearnDirectX-DX3D11 tutorial02 (源码已上传至Github)

Direct3D 11 Tutorial 3: Shaders and Effect System_Direct3D 11 教程3:着色器和效果系统

概述 在上一个教程中,我们设置了一个顶点缓冲区并将一个三角形传递给GPU. 现在,我们将逐步完成图形管道并查看每个阶段的工作原理. 将解释着色器和效果系统的概念. 请注意,本教程与前一个源代码共享相同的源代码,但将强调不同的部分. 资源目录 (SDK root)\Samples\C++\Direct3D11\Tutorials\Tutorial03 Github仓库 图形管道 在上一个教程中,我们设置顶点缓冲区,然后将顶点布局与顶点着色器相关联. 现在,我们将解释着色器是什么以及它是如何工作的.

Direct3D 11 Tutorial 4: 3D Spaces_Direct3D 11 教程4:3D空间

概述 在上一个教程中,我们在应用程序窗口的中心成功渲染了一个三角形. 我们没有太注意我们在顶点缓冲区中拾取的顶点位置. 在本教程中,我们将深入研究3D位置和转换的细节. 本教程的结果将是渲染到屏幕的3D对象. 虽然之前的教程侧重于将2D对象渲染到3D世界,但在这里我们展示了一个3D对象. 资源目录 (SDK root)\Samples\C++\Direct3D11\Tutorials\Tutorial04 Github仓库 3D空间 在上一个教程中,三角形的顶点被有策略地放置,以在屏幕上完美地对

Direct3D 11 Tutorial 5: 3D Transformation_Direct3D 11 教程5:3D转型

概述 在上一个教程中,我们从模型空间到屏幕渲染了一个立方体. 在本教程中,我们将扩展转换的概念并演示可以通过这些转换实现的简单动画. 本教程的结果将是围绕另一个轨道运行的对象. 展示转换以及如何将它们组合以实现期望的效果将是有用的. 在我们介绍新概念时,未来的教程将在此基础上构建. 资源目录 (SDK root)\Samples\C++\Direct3D11\Tutorials\Tutorial05 Github 转型 在3D图形中,变换通常用于对顶点和矢量进行操作. 它还用于将它们在一个空间中

Direct3D 11 Tutorial 6:Lighting_Direct3D 11 教程6:灯光

概述 在之前的教程中,世界看起来很无聊,因为所有对象都以相同的方式点亮. 本教程将介绍简单照明的概念及其应用方法. 使用的技术将是朗伯照明. 本教程的结果将修改前面的示例以包含光源. 该光源将附在轨道上的立方体上. 可以在中心立方体上看到光的影响. 资源目录 (SDK root)\Samples\C++\Direct3D11\Tutorials\Tutorial06 Github 灯光 在本教程中,将介绍最基本的照明类型:朗伯照明. 无论距离光线的距离如何,朗伯照明都具有均匀的强度. 当光照射到