资源简介
directx11教程2代码
代码片段和文件信息
#include“D3DClass.h“
D3DClass::D3DClass()
{
md3dDevice = NULL;
md3dImmediateContext = NULL;;
md3dSwapChain=NULL;
md3dRenderTargetView=NULL;
md3dDepthStencilView = NULL;
md3dDepthStencilBuffer=NULL;
md3dDepthStencilState=NULL;
md3dRasterizerState=NULL;
}
D3DClass::~D3DClass()
{
}
D3DClass::D3DClass(const D3DClass& other)
{
}
bool D3DClass::Initialize(int ScreenWidth int ScreenHeight bool vsync HWND hwnd bool fullscreen float ScreenDepth float ScreenNear)
{
float fieldOfView screenAspect;
//--------------------------------------------------------------
//第一获取显示模式信息和显卡信息
//---------------------------------------------------------------
IDXGIAdapter* adpter;//适配器
IDXGIFactory* factory;
IDXGIOutput* adapterOutput;
unsigned int numModes numerator denominator stringLength;
DXGI_MODE_DESC* displayModeList;
DXGI_ADAPTER_DESC adapterDesc;
int error;
//存储vsyn设定
mVsyncEnable = vsync;
//创建一个Directx图形接口factory
HR(CreateDXGIFactory(__uuidof(IDXGIFactory) (void**)&factory));
//使用factory来为显卡创建一个adapter
HR(factory->EnumAdapters(0 &adpter));
//列举主要的适配器输出
HR(adpter->EnumOutputs(0 &adapterOutput));
//获取适应适配器DXGI_FORMAT_R8G8B8A8_UNORM显示格式的模式数目
HR(adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM DXGI_ENUM_MODES_INTERLACED &numModes NULL));
//创建一个显示模式列表存放可能的显示模式(显卡监视器)
displayModeList= new DXGI_MODE_DESC[numModes];
if (!displayModeList)
return false;
//填充显示模式列表结构体
HR(adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM DXGI_ENUM_MODES_INTERLACED &numModes displayModeList));
//浏览所有的显示模式找到适合屏幕宽度和高度的
//当一个模式匹配存储监视器刷新速度的分子分母??
for (int i = 0; i {
if (displayModeList[i].Width == (unsigned int)ScreenWidth)
{
if (displayModeList[i].Height == (unsigned int)ScreenHeight)
{
numerator = displayModeList[i].RefreshRate.Numerator;
denominator = displayModeList[i].RefreshRate.Denominator;
}
}
}
//获取适配器(显卡)形容
HR(adpter->GetDesc(&adapterDesc));
//获取显卡内存量
mVideoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
//将显卡名字转存在字符数组
error = wcstombs_s(&stringLength mVideoCardDescription 128 adapterDesc.Description 128);
if (error != 0)
{
return false;
}
//释放显示模式列表
delete[] displayModeList;
displayModeList = NULL;
ReleaseCOM(adpter);
ReleaseCOM(factory);
//-----------------------------------------------------
//第二填充交换链形容结构体
//-----------------------------------------------------
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory(&sd sizeof(sd));
sd.BufferDesc.Width = ScreenWidth;
sd.BufferDesc.Height = ScreenHeight;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
if (mVsyncEnable) //限不限帧
{
sd.BufferDesc.RefreshRate.Numerator =numerator;
sd.BufferDesc.RefreshRate.Denominator = denominator;
}
else
{
sd.BufferDesc.RefreshRate.Numerator = 0;
sd.BufferDesc.RefreshRate.Denominator = 1
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10994 2016-09-28 17:22 D3D11教程2\D3DClass.cpp
文件 2002 2016-09-28 17:05 D3D11教程2\D3DClass.h
文件 1004 2016-09-28 16:59 D3D11教程2\GraphicsClass.cpp
文件 628 2016-09-28 17:14 D3D11教程2\GraphicsClass.h
文件 497 2016-09-27 11:27 D3D11教程2\InputClass.cpp
文件 372 2016-09-27 11:11 D3D11教程2\InputClass.h
文件 5840 2016-09-27 18:12 D3D11教程2\SystemClass.cpp
文件 1196 2016-09-27 11:56 D3D11教程2\SystemClass.h
文件 466 2016-09-27 11:37 D3D11教程2\源.cpp
目录 0 2016-10-01 09:44 D3D11教程2
----------- --------- ---------- ----- ----
22999 10
- 上一篇:高程点按范围检查粗差
- 下一篇:D3D11_Pick
评论
共有 条评论