Directx
时间:2014-03-07
来源:互联网
最麻烦系一个Direct2D需要一个Device Context
而一个Direct2D Device Context需要一个Direct2D Device
而一个Direct2D Device需要一个DXGI Device
使用一个DXGI Device需要建立Swap Chain, Texture, Buffer, Bitmap
建立Swap Chain需要DXGI Factory
而一个DXGI Device需要一个Direct3D Device
到最后....居然话以上的东西都不能写字...
所以要Print "Hello world"还需要一个DirectWrite Factory
2014-2-20 12:15 AM
2014-2-20 12:15 AM
作者: Susan﹏汪汪 发布时间: 2014-03-07

就好似全部用Win32 API写个GUI程式出黎,所以DX主力都系C++
作者: sinson123 发布时间: 2014-03-07
建立一个Directx环境....两个字...麻烦
最麻烦系一个Direct2D需要一个Device Context
而一个Direct2D Device Context需要一个Direct2D Device
而一个Direct2D Device需要一个DXGI Device
使用一个DXGI Device需 ...
其实 SDL + OpenGL ES 是否更好的选择?
上述的我都未用过,不过好像它们都是 cross-platform 的。
http://en.wikipedia.org/wiki/Simple_DirectMedia_Layer
http://en.wikipedia.org/wiki/OpenGL_ES
作者: xianrenb 发布时间: 2014-03-07
唔系佢都唔整个XNA出黎

就好似全部用Win32 API写个GUI程式出黎,所以DX主力都系C++
有大量的指针操作
不过window 8的话会提供左一些XNA、或者其他的GUI介面系统的handle比directx用
作者: Susan﹏汪汪 发布时间: 2014-03-07
我无用过 DirectX 。
其实 SDL + OpenGL ES 是否更好的选择?
上述的我都未用过,不过好像它们都是 cross-platform 的。
http://en.wikipedia.org/wiki/Simple_DirectMedia_Layer
http://en.wikipedia.org/w ...
应该唔再需要理用directx定OpenGL
作者: Susan﹏汪汪 发布时间: 2014-03-07
我无用过 DirectX 。
其实 SDL + OpenGL ES 是否更好的选择?
上述的我都未用过,不过好像它们都是 cross-platform 的。
http://en.wikipedia.org/wiki/Simple_DirectMedia_Layer
http://en.wikipedia.org/w ...
作者: bread.doves. 发布时间: 2014-03-07
以前看过一本 dx 的书, 单是 lib 的每一个function 的 arg 已经几行... 同 win API 有得挥 (烦) ... 如果单是写 game, 一定用 unity 呢 d game engine, 方便快捷, 简单, 仲要 cross platform (ios, android, pc)
这是Device封装
{
D3D_FEATURE_LEVEL featureLevel;
IDXGIDevice1 * pDXGIDevice;
ID2D1Device * pd2dDevice;
ID3D11Device * pd3dDevice;
ID2D1DeviceContext * pd2dDeviceContext;
ID3D11DeviceContext * pd3dDeviceContext;
DXDevice( void );
~DXDevice( void );
};
DXDevice:XDevice( void )
{
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1
};
HResult( D3D11CreateDevice(
nullptr, // specify null to use the default adapter
D3D_DRIVER_TYPE_HARDWARE,
0,
creationFlags, // optionally set debug and Direct2D compatibility flags
featureLevels, // list of feature levels this app can support
ARRAYSIZE(featureLevels), // number of possible feature levels
D3D11_SDK_VERSION,
&this->pd3dDevice, // returns the Direct3D device created
&this->featureLevel, // returns feature level of device created
&this->pd3dDeviceContext // returns the device immediate context
) );
HResult( this->pd3dDevice->QueryInterface(__uuidof(IDXGIDevice), (void **)&this->pDXGIDevice) );
HResult( D2D1CreateDevice(this->pDXGIDevice, nullptr, &this->pd2dDevice) );
HResult( this->pd2dDevice->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &this->pd2dDeviceContext) );
}
DXDevice::~DXDevice( void )
{
SafeRelease(&this->pd2dDeviceContext);
SafeRelease(&this->pd3dDeviceContext);
SafeRelease(&this->pDXGIDevice);
SafeRelease(&this->pd2dDevice);
SafeRelease(&this->pd3dDevice);
}
swapChainDesc.Width = 0; // use automatic sizing
swapChainDesc.Height = 0;
swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // this is the most common swapchain format
swapChainDesc.Stereo = false;
swapChainDesc.SampleDesc.Count = 1; // don't use multi-sampling
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = 2; // use double buffering to enable flip
swapChainDesc.Scaling = DXGI_SCALING_NONE;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // all apps must use this SwapEffect
swapChainDesc.Flags = 0;
IDXGIAdapter * pDXGIAdapter = nullptr;
HResult( DXDevice.pDXGIDevice->GetAdapter(&pDXGIAdapter) );
IDXGIFactory2 * pDXGIFactory = nullptr;
HResult( pDXGIAdapter->GetParent(__uuidof(IDXGIFactory2), (LPVOID*)&pDXGIFactory) );
SafeRelease(&pDXGIAdapter);
HResult( pDXGIFactory->CreateSwapChainForHwnd(
DXDevice.pd3dDevice,
hWnd,
&swapChainDesc,
nullptr,
nullptr,
&swapChain
) );
SafeRelease(&pDXGIFactory);
HResult( DXDevice.pDXGIDevice->SetMaximumFrameLatency(1) );
D2D1_BITMAP_PROPERTIES1 bitmapProperties = D2D1::BitmapProperties1(
D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
D2D1:ixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE)
);
IDXGISurface * pDXGIBackBuffer = nullptr;
HResult( swapChain->GetBuffer(0, IID_PPV_ARGS(&pDXGIBackBuffer)) );
ID2D1Bitmap1 * pd2dTargetBitmap = nullptr;
HResult( DXDevice.pd2dDeviceContext->CreateBitmapFromDxgiSurface(
pDXGIBackBuffer,
&bitmapProperties,
&pd2dTargetBitmap
) );
SafeRelease(&pDXGIBackBuffer);
DXDevice.pd2dDeviceContext->SetTarget(pd2dTargetBitmap);
SafeRelease(&pd2dTargetBitmap);
HResult( DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(&pDWriteFactory)
) );
IDXGISwapChain1 * swapChain;
IDWriteFactory * pDWriteFactory;
作者: Susan﹏汪汪 发布时间: 2014-03-07
可以release的就先release掉
轻量版的Direct3D和Direct2D
因为要用Direct2D、所以全部都要用上最新的Directx 11.1 or 11.2
另外还要用window 8的SDK(因为只有window 8 SDK有提供这版本的Directx)
作者: Susan﹏汪汪 发布时间: 2014-03-07
d3d11.h和d2d1.h
而directx 11.1的系
d3d11_1.h和d2d1_1.h
两个版本共用
d3d11.lib和d2d1.lib
但directx 11.1里有些功能要用所以一定要追加11.1的header
作者: Susan﹏汪汪 发布时间: 2014-03-07
作者: Susan﹏汪汪 发布时间: 2014-03-07

作者: Susan﹏汪汪 发布时间: 2014-03-07
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28