0

I am new to windows world and trying to learn direct manipulation. I am able to handle the scroll and screen updating in that case. With zoom direct manipulation maps existing pixel to new pixel size. For eg say I have a 400x 400 window and it has 4 images 200x200 each. When I zoom to 2x one of the images will get drawn on 400x400 and thus appear pixelated. Now I am trying to update the viewport content in OnViewportUpdated call to draw a sharp image of size 400x400. when I do so it gets drawn at the original image position I am providing and with original scale only and thus 4 images are replaced by 1. I am using below methodology

ComPtr<IDXGISurface1> dxSurface;
 screenSurface->BeginDraw(&rect, IID_PPV_ARGS(&dxSurface), &point);
hr = dxSurface->GetDC(FALSE, &hSurfaceDC);

if (SUCCEEDED(hr))
{
            HBITMAP hBitmapOld = NULL;

            // Create a compatible DC and select the surface 
            // into the DC.
            hBitmapDC = CreateCompatibleDC(hSurfaceDC);
            if (hBitmapDC != NULL)
            {
                HBITMAP hBitmap = CreateCompatibleBitmap(GetDC(_hWnd), 400, 400);
                hBitmapOld = (HBITMAP)SelectObject(hBitmapDC, hBitmap);
                SelectObject(hBitmapDC, GetStockObject(DC_BRUSH));
                SetDCBrushColor(hBitmapDC, RGB(255, 0, 0));
                Rectangle(hBitmapDC, 0, 0, 400, 400);
                BitBlt(hSurfaceDC, 0, 0,
                    400, 400, hBitmapDC, 0, 0, SRCCOPY);
                
            }
}

I am wondering if using IDXGISurface1 is the right methodology or not. How can I use directcomposition for drawing in conjunction with directmanipulation

Illuminati
  • 111
  • 7
  • 1
    You have interop between GDI and Direct technologies (DXGI/DirectX/Direct2D/DirectComposition) but it's mostly useful when you have existing GDI code. If you have specific hi-tech imaging needs and start from scratch on Windows, I suggest to take a deep look at WinUI3 which uses Direct Composition underneath (it's called now Visual Layer and is a WinRT API https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/composition). Otherwise explain more, show reproducing code, explain what doesn't work with it https://stackoverflow.com/help/minimal-reproducible-example – Simon Mourier Mar 07 '23 at 11:15
  • Thanks for the response @SimonMourier problem my application architecture is dependent on bitmaps for rendering finer content winui3 might not be an option for me – Illuminati Mar 07 '23 at 14:01
  • Ok then stick with bitmaps and GDI (it's not because you throw DXGI in the picture that it will magically accelerate things) and post a reproducible example of your issue. – Simon Mourier Mar 07 '23 at 14:18
  • @SimonMourier I observed new problem when I am creating IDCompositionSurface greater than 8192 (using https://learn.microsoft.com/en-us/windows/win32/api/dcomp/nf-dcomp-idcompositiondevice-createsurface )it returns empty surface object .Also tried virtualsurface (https://learn.microsoft.com/en-us/windows/win32/api/dcomp/nf-dcomp-idcompositiondevice-createvirtualsurface) I am able to create surfaces greater than 8192 but drawing over them results in uniform colored screen. Is there some limitation or I am doing something wrong? – Illuminati Mar 28 '23 at 07:47

0 Answers0