DirectX 教程: DirectX Tutorial - Direct3D: Getting Started

基本知识:

1. 图形硬件

随着显示技术的发展,显示器独立带有显存

2. DXGI ( DirectX Graphics Infrastructure )

The DirectX Graphics Infrastructure is a component that lies at the base of all the most recent versions of Direct3D.

Its job is to handle fundamental tasks such as displaying images on the screen and finding out what resolutions the monitor and video card can handle.

DXGI is not actually a part of Direct3D.

3. The Swap Chain

基本做法: 设立两个buffer,一个读出数据用于显示的同时,另外一个用于存计算机输出的显示数据,再交换。

4. 流水线

此处作者没有详细讲

5. 坐标系统

作者从一维讲到三维,没有必要细讲了。

6. 三维几何

Primitives(基本几何形状)

A primitive is a single element in a 3D environment, be it a triangle, a line, a dot, or whatever. Following is a list of ways primitives can be combined to create 3D objects.

1. Point Lists

2. Line Lists


3. Line Strips


4. Triangle Lists


5. Triangle Strips

7. COM

COM stands for Component Object Model.

Even though COM's job is to hide all the complexity, there are four things you need to know about it.
1. A COM object is a class or set of classes controlled by an interface. An interface is a set of functions that, well, controls a COM object. In the example above, "device" is a COM object, and the functions control it.
2. Each type of COM object has a unique ID. 
3. When done using a COM object, you must always call the function Release(). 
4. COM objects are easy to identify, because they typically start with an 'I', such as 'ID3D10Device'.

程序基本结构:

8. Direct3D Headers

// include the basic windows header files and the Direct3D header files
#include <windows.h>
#include <windowsx.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dx10.h>// include the Direct3D Library file
#pragma comment (lib, "d3d11.lib")
#pragma comment (lib, "d3dx11.lib")
#pragma comment (lib, "d3dx10.lib")// global declarations
IDXGISwapChain *swapchain;             // the pointer to the swap chain interface
ID3D11Device *dev;                     // the pointer to our Direct3D device interface
ID3D11DeviceContext *devcon;           // the pointer to our Direct3D device context// function prototypes
void InitD3D(HWND hWnd);     // sets up and initializes Direct3D
void CleanD3D(void);         // closes Direct3D and releases memory// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

这里主要注意的就是global declarations

需要建立两个设备相关的指针,另外还需要一个swap chain 的指针

然后是D3D的初始化和释放,分别对应两个函数。

注意还要导入D3D相关的头文件,详细步骤请看:http://www.directxtutorial.com/lessonarticle.aspx?id=4

9. DirectX3D 初始化

初始化主要就是写上D3D11CreateDeviceAndSwapChain函数

这个函数看着很复杂,其实基本参数都用那几个,不大会变,详细自己看英文教程,不详述。使用这个函数是init的第一步。

// this function initializes and prepares Direct3D for use
void InitD3D(HWND hWnd)
{// create a struct to hold information about the swap chainDXGI_SWAP_CHAIN_DESC scd;// clear out the struct for useZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));// fill the swap chain description structscd.BufferCount = 1;                                    // one back bufferscd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;     // use 32-bit colorscd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;      // how swap chain is to be usedscd.OutputWindow = hWnd;                                // the window to be usedscd.SampleDesc.Count = 4;                               // how many multisamplesscd.Windowed = TRUE;                                    // windowed/full-screen mode// create a device, device context and swap chain using the information in the scd structD3D11CreateDeviceAndSwapChain(NULL,D3D_DRIVER_TYPE_HARDWARE,NULL,NULL,NULL,NULL,D3D11_SDK_VERSION,&scd,&swapchain,&dev,NULL,&devcon);
}

这里还要补充一点

scd.SampleDesc.Count = 1; 是用来表示是否打开抗锯齿

10. 释放D3D

// this is the function that cleans up Direct3D and COM
void CleanD3D()
{// close and release all existing COM objectsswapchain->Release();dev->Release();devcon->Release();
}

开始进行渲染:


这里需要两步:

First, we need to tell the GPU where in memory to create the final image (for us, this is the back buffer).

这一步包含11,12两点,注意这一步的时候各个代码段在initD3D中的顺序。

Second, we need to tell the GPU where on the backbuffer it should draw.

这一步是13点,这是一个独立的刷新方法,会在每一个frame显示的时候调用,所以要注意调用这个方法的位置是在while主循环中。

11. Setting the Render Target

ID3D11RenderTargetView *backbuffer;    // global declaration// this function initializes and prepares Direct3D for use
void InitD3D(HWND hWnd)
{// Direct3D initialization// ...// get the address of the back bufferID3D11Texture2D *pBackBuffer;swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);// use the back buffer address to create the render targetdev->CreateRenderTargetView(pBackBuffer, NULL, &backbuffer);pBackBuffer->Release();// set the render target as the back bufferdevcon->OMSetRenderTargets(1, &backbuffer, NULL);
}

First, we determine the address of the back buffer.

Second, we create a COM object using that address to represent the render target.

Third, we set that object as the active render target.

12. Setting the Viewport

这里涉及到坐标系归一化的概念

// this function initializes and prepares Direct3D for use
void InitD3D(HWND hWnd)
{// Direct3D initialization// ...// Set the render target// ...// Set the viewportD3D11_VIEWPORT viewport;ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));viewport.TopLeftX = 0;viewport.TopLeftY = 0;viewport.Width = 800;viewport.Height = 600;devcon->RSSetViewports(1, &viewport);
}

13. Rendering Frames

// this is the function used to render a single frame
void RenderFrame(void)
{// clear the back buffer to a deep bluedevcon->ClearRenderTargetView(backbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f));// do 3D rendering on the back buffer here// switch the back buffer and the front bufferswapchain->Present(0, 0);
}

14. release修改:

需要加一行:

backbuffer->Release();

DirectX 教程: DirectX Tutorial - Direct3D: Getting Started相关推荐

  1. 【Visual C++】游戏开发笔记四十一 浅墨DirectX教程之九 为三维世界添彩:纹理映射技术(一)...

    本系列文章由zhmxy555(毛星云)编写,转载请注明出处. 文章链接: http://blog.csdn.net/zhmxy555/article/details/8523341 作者:毛星云(浅墨 ...

  2. 【Visual C++】游戏开发四十八 浅墨DirectX教程十六 三维地形系统的实现

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 本系列文 ...

  3. 【Visual C++】游戏开发笔记四十二 浅墨DirectX教程之十 游戏输入控制利器 DirectInput专场

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 本系列文 ...

  4. 【Visual C++】游戏开发笔记四十七 浅墨DirectX教程十五 翱翔于三维世界 摄像机的实现

    分享一下我老师大神的人工智能教程.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow 本系列文章由zhm ...

  5. 【Visual C++】游戏开发笔记四十三 浅墨DirectX教程十一 为三维世界添彩:纹理映射技术(二)...

    本系列文章由zhmxy555(毛星云)编写,转载请注明出处. 作者:毛星云(浅墨)    邮箱: happylifemxy@163.com 本篇文章里,我们首先对Direct3D之中固定功能流水线中的 ...

  6. 动画骨骼【Visual C++】游戏开发五十二 浅墨DirectX教程二十 骨骼动画来袭(一)...

    间时紧张,先记一笔,后续优化与完善. 本系列文章由zhmxy555(毛星云)编写,载转请注明出处. 文章链接: http://blog.csdn.net/zhmxy555/article/detail ...

  7. 【Visual C++】游戏开发五十六 浅墨DirectX教程二十三 打造游戏GUI界面(一)

    本系列文章由zhmxy555(毛星云)编写,转载请注明出处. 文章链接: http://blog.csdn.net/poem_qianmo/article/details/16384009 作者:毛星 ...

  8. 【Visual C++】游戏开发笔记四十二 浅墨DirectX教程之十 游戏输入控制利器:DirectInput专场...

    本系列文章由zhmxy555(毛星云)编写,转载请注明出处. 文章链接:http://blog.csdn.net/zhmxy555/article/details/8547531 作者:毛星云(浅墨) ...

  9. 【Visual C++】游戏开发五十二 浅墨DirectX教程二十 骨骼动画来袭(一)

    这是答应大家的讲解骨骼动画的文章的N部曲的第二篇.这篇文章里,我们对现行的三种模型动画技术进行了概述,然后对X文件构成进行了详细的剖析,最后放出了骨骼动画的第一个示例程序,载入了<诛仙>中 ...

最新文章

  1. python导入matplotlib出错_解决导入matplotlib的RuntimeError: Python is not installed as a framework....
  2. Reboot分享第三期(已结束)
  3. 【听说是线段树】bzoj1012 [JSOI2008]最大数maxnumber
  4. spring 中 Hibernate 事务和JDBC事务嵌套问题
  5. UVALive - 3231 Fair Share(最大流+二分)
  6. docker学习笔记(七)docker-swarm
  7. MyBatis 思维导图,让 MyBatis 不再难懂(一)
  8. Spring + Dubbo + zookeeper (linux) 框架搭建
  9. linux df 查看磁盘剩余空间,du查看文件占用多少空间,rm -rf 删除文件 mkdir -p创建目录(含父级)
  10. python三引号的作用_Python学习笔记(三)基本数据类型
  11. DayDayUp:计算机技术与软件专业技术资格证书之《系统集成项目管理工程师》证书考试历年真题及其解析之2019年/2020年
  12. Android10 mockLocation 模拟定位
  13. python字符串输入并倒叙_基于python3实现倒叙字符串
  14. HTML中的 后代选择器 和 子代选择器
  15. 社会对计算机专业学生的需求,关于计算机专业社会人才需求调查报告
  16. fastadmin 阿里云oss解决访问图片是下载
  17. 虚拟服务器的常用服务器选什么,如何选择合适的虚拟主机,虚拟主机选什么系统...
  18. JavaWeb 项目 --- 博客系统(基于模板引擎)
  19. 利用PYTHON出小学数学题
  20. win10中搭建并配置ftp服务器的方法(实现多用户登录整合版

热门文章

  1. 机械硬盘低级格式化软件_西数硬盘专用修复工具_WD HDD Repair Tool|西部数据硬盘修复工具 V3.6 中文版 - 偶要下载站...
  2. 并行计算mpi实现矩阵转置,mpi分布式编程简介,点对点通信方法
  3. cmd命令方式启动服务
  4. 目标竞赛省队,寒假如何备考生物竞赛联赛?
  5. GA遗传算法实现记录 C++版本 解决多元函数最值问题
  6. Centos操作系统yum源的使用
  7. redis源码注释二:简单字符串sds.c sds.h
  8. docker GitLab-runner CI/CD持续集成
  9. fatal: the remote end hung up unexpectedly (curl 56 OpenSSL SSL_read:SSL_ERROR_sysCALL)
  10. 从ZigBee到Matter,智能家居碎片化时代或将终结