2

I have created a texture which is GDI compatible but the DC I have got from it is used to draw lines from on point to another point which are not showing on the view window. Also no exception is thrown. Am I missing anything? Is there anyone done the same and successfully draw 2D shapes or something using GDI compatible DC ? Please help.

// get texture surface1 and overlay DC from GDI compatible texture 2D
D3D11_TEXTURE2D_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.Width = width;
desc.Height = height;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
desc.CPUAccessFlags = 0;
desc.MipLevels = 1;
desc.SampleDesc.Count = 1;
desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;

ID3D11Texture2DPtr texture2D;
IF_FAILED_THROW_HR(renderer->Device()->CreateTexture2D(&desc, nullptr, &texture2D));

// Create the shader resource view.
ID3D11ShaderResourceViewPtr shaderResourceView;
IF_FAILED_THROW_HR(device->CreateShaderResourceView(texture2D, nullptr, &shaderResourceView));

ID3D11ResourcePtr resource;
view->GetResource(&resource);
m_texture2D = resource;

m_dxgiSurface1 = m_texture2D;
TRY_CONDITION(m_dxgiSurface1);
HDC hdc{};
IF_FAILED_THROW_HR(m_dxgiSurface1->GetDC(FALSE, &hdc));

DXGI_SURFACE_DESC descOverlay = {0};
m_dxgiSurface1->GetDesc(&descOverlay);


// Draw on the DC using GDI
// fill the texture with the color key
::SetBkColor(overlayDC, m_keyColor);
const auto overlayRect = CRect{ 0, 0, gsl::narrow_cast<int>(descOverlay.Width), gsl::narrow_cast<int>(descOverlay.Height) };
::ExtTextOut(overlayDC, 0, 0, ETO_OPAQUE, overlayRect, nullptr, 0, nullptr);

m_dxgiSurface1->ReleaseDC(nullptr);

Update: I have edited the above source code where I have created the shader resource view from the GDI compatible texture then took the texture back from resource to the surface1. Then surface1 provides a DC which is used for GDI Drawing. Now smooth rendering but no GDI drawing is visible.

1 Answers1

0

The texture created after this GDI drawing is used for mixing with other textures. I was finding these drawings over those textures but later found my mistakes that this GDI drawing texture was not mixed with other textures in shader programs thus it was not rendered as an overlay. So it looked like the drawing was missing.