Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- In my mission to use DirectWrite as a font rasterizer on Windows I have gone down many roads.
- Today on this mission I learned to:
- Initialize D3D10 and D3D10_1
- Create a D3D10 texture
- Get a DXGI surface
- Set a debug mode flag on a D2D factory
- What I never even got around to before I ran out of ideas on how to get the below code to work:
- Initializing DirectWrite
- Any advice would be appreciated: @AllenWebster4th
- */
- int main(){
- HRESULT error = 0;
- ID3D10Device1 *d3d_device = 0;
- error = D3D10CreateDevice1(0,
- D3D10_DRIVER_TYPE_HARDWARE,
- 0,
- D3D10_CREATE_DEVICE_SINGLETHREADED|
- D3D10_CREATE_DEVICE_DEBUG|
- D3D10_CREATE_DEVICE_BGRA_SUPPORT|
- 0,
- D3D10_FEATURE_LEVEL_10_0,
- D3D10_1_SDK_VERSION,
- &d3d_device);
- D3D10_TEXTURE2D_DESC d3d_texture_desc = {0};
- d3d_texture_desc.Width = 200;
- d3d_texture_desc.Height = 200;
- d3d_texture_desc.MipLevels = 1;
- d3d_texture_desc.ArraySize = 1;
- d3d_texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UINT;
- d3d_texture_desc.SampleDesc.Count = 1;
- d3d_texture_desc.SampleDesc.Quality = 0;
- d3d_texture_desc.Usage = D3D10_USAGE_STAGING;
- d3d_texture_desc.BindFlags = 0;
- d3d_texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ|D3D10_CPU_ACCESS_WRITE;
- d3d_texture_desc.MiscFlags = 0;
- ID3D10Texture2D *d3d_texture = 0;
- error = d3d_device->CreateTexture2D(&d3d_texture_desc, 0, &d3d_texture);
- IDXGISurface *dxgi_surface = 0;
- error = d3d_texture->QueryInterface(__uuidof(IDXGISurface), (void**)&dxgi_surface);
- D2D1_FACTORY_OPTIONS d2d_factory_options = {};
- d2d_factory_options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
- ID2D1Factory *d2d_factory = 0;
- error = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), &d2d_factory_options, (void**)&d2d_factory);
- D2D1_RENDER_TARGET_PROPERTIES render_target_properties = {};
- render_target_properties.type = D2D1_RENDER_TARGET_TYPE_DEFAULT;
- render_target_properties.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_R8G8B8A8_UINT, D2D1_ALPHA_MODE_IGNORE);
- render_target_properties.dpiX = 96.f;
- render_target_properties.dpiY = 96.f;
- render_target_properties.usage = D2D1_RENDER_TARGET_USAGE_NONE;
- render_target_properties.minLevel = D2D1_FEATURE_LEVEL_10;
- ID2D1RenderTarget *render_target = 0;
- error = d2d_factory->CreateDxgiSurfaceRenderTarget(dxgi_surface, render_target_properties, &render_target);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement