Visual Studio C++当我最大化窗口D3D11和D2D1时,如何阻止图像被缩放错误

发布于 2025-01-22 11:18:33 字数 10205 浏览 3 评论 0原文

因此,我试图弄清我如何用直接内容渲染图像的问题。现在,它可以用DXGISWAPCHAIN使用D3D11,并且我制作了一个ID2D1RenderTarget,我绘制了使用位图。我的问题是,当我点击窗口上的“最大化”按钮时,我的图像关闭了,或者至少是使用getClientRect抓住的窗口中的数据(其他看起来都足够近,但可能仍然关闭,我想能够能够使用客户空间来扩展并以后绘制内容)。当窗口的高度和宽度通过getClientRect抓住时,我有一个D2D1 :: RECTF设置,左上角为0.0F,右下是右下角(以及其他一些只是为了额外的欺骗)。环顾四周,看来我需要称呼重新创建ID2D1RenderTarget和/或调整缓冲区大小。在制作包含位图的对象和吸引它们的功能之前,调用函数以重新创建ID2D1RenderTarget,这根本无济于事。我尝试调整缓冲区的大小,但我一直遇到错误,第一组是关于参数的,但是在解决我意识到我需要释放对象之前他们有问题。 client.h正在调用一个例外:未签名的long internalRelease()函数“访问违规执行位置”。这是在调整缓冲区和目标的功能时发生的。因此,现在我为了获得理想的效果而迷失了方向。只需注意的其他内容是我制作的ID3D11RenderTargetView用于清除颜色,因为我在调用Clear(d2d1 :: Colorf(d2d1 :: colorf :: colorf :: white)中遇到了错误(d2d1 :: white :: white));在我的ID2D1RenderTarget上。我不在乎解决此问题是否大大化ID3DD11RenderTargetView的大小,除非它会提高程序的速度或防止其他地方的某种不可预见的问题,因为我不打算为此使用它。如果我可以在ID2D1RENDERTARGET上进行清楚,而不再需要ID311RenderTargetView并保持Swapchain,同时解决也可以正常工作的问题。另外,我打算接下来要制定全屏模式,以便使用该方法也非常需要。我也愿意在这里接受任何其他建议,虽然没有抛光,并且只是以一种使事情首先工作的形式,但即使整理好事,我也可能会错过事情。无论如何,这是代码:

这是我制作Swapchain,“缓冲区”和“ RenderTargets”等图形课程,以及我尝试重置缓冲区的功能。旁注,我在这里的路上遵循了一些教程,以使我了解足够多的直接内容,以便到达这里,直到我研究Microsoft上的东西,并在某种程度上了解它以解决我遇到的问题。无论如何,其中一个经历了一些例外,这就是诸如graphic_throw_failure()之类的东西。 (尽管我做错了,或者错误正在做某事,但我看不到弹出窗口的一半时间,有时它在异常代码中停止,但我仍然可以阅读消息

//not in the cpp file but just how some variables exist for clarity.
private:
    
    Microsoft::WRL::ComPtr<ID3D11Device> pDevice = nullptr;
    Microsoft::WRL::ComPtr < IDXGISwapChain> pSwapChain = nullptr;
    Microsoft::WRL::ComPtr < ID3D11DeviceContext> pContext = nullptr;
    Microsoft::WRL::ComPtr < ID3D11RenderTargetView> pRTarget = nullptr;
    ID2D1RenderTarget* p2dRenderTarget = nullptr;
    ID2D1Factory* p2DFactory = nullptr;
    

Graphics::Graphics(HWND hwnd) {
    
    DXGI_SWAP_CHAIN_DESC swapchainDesc = {};
    ZeroMemory(&swapchainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
    swapchainDesc.Windowed = true;
    swapchainDesc.BufferCount = 1;
    swapchainDesc.BufferDesc.Height = 0;
    swapchainDesc.BufferDesc.Width = 0;
    swapchainDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    swapchainDesc.SampleDesc.Count = 1;
    swapchainDesc.SampleDesc.Quality = 0;
    swapchainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
    swapchainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    swapchainDesc.BufferDesc.RefreshRate.Numerator = 1;
    swapchainDesc.BufferDesc.RefreshRate.Denominator = 60;
    swapchainDesc.OutputWindow = hwnd;
    HRESULT hre;
    Graphic_Throw_Failure(D3D11CreateDeviceAndSwapChain(
        nullptr,
        D3D_DRIVER_TYPE_HARDWARE,
        nullptr,
        D3D11_CREATE_DEVICE_BGRA_SUPPORT,
        levels,
        4,
        D3D11_SDK_VERSION,
        &swapchainDesc,
        &pSwapChain,
        &pDevice,
        nullptr,
        &pContext
    ));

  
   
    
   //3Dbuffer setup
    wrl::ComPtr<ID3D11Resource> p3dbuffer = nullptr;
    Graphic_Throw_Failure(pSwapChain->GetBuffer(0, __uuidof(ID3D11Resource), &p3dbuffer));
    Graphic_Throw_Failure(pDevice->CreateRenderTargetView(p3dbuffer.Get(), nullptr, &pRTarget));

    //2D buffer Setup
    

    IDXGISurface* pBackBuffer = nullptr;
    Graphic_Throw_Failure(pSwapChain->GetBuffer(0,IID_PPV_ARGS(&pBackBuffer)));

    //makes 2d Factory
    Graphic_Throw_Failure(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &p2DFactory));
    
    //sets up DXGI buffer for 2d
    FLOAT dpi;
    dpi = GetDpiForWindow(hwnd);
    //p2DFactory->GetDesktopDpi(&dpiX, &dpiY);

    D2D1_RENDER_TARGET_PROPERTIES p2dRTprops =
        D2D1::RenderTargetProperties(
            D2D1_RENDER_TARGET_TYPE_DEFAULT,
            D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED),
            dpi,
            dpi
        );
        

    Graphic_Throw_Failure(p2DFactory->CreateDxgiSurfaceRenderTarget(
        pBackBuffer, &p2dRTprops, &p2dRenderTarget

    ));

    

    if(pBackBuffer!=nullptr)
    pBackBuffer->Release();
}



//the adjusting function I failed to make. could also be missing somethings I need to clear before
//calling ResizeBuffers


void Graphics::adjustRenderTargets(HWND hwnd) {
  HRESULT hre;


    pContext->ClearState();
    p2dRenderTarget->Release();
    pRTarget->Release();

    //3Dbuffer setup
    wrl::ComPtr<ID3D11Resource> p3dbuffer = nullptr;
    Graphic_Throw_Failure(pSwapChain->GetBuffer(0, __uuidof(ID3D11Resource), &p3dbuffer));
    Graphic_Throw_Failure(pDevice->CreateRenderTargetView(p3dbuffer.Get(), nullptr, &pRTarget));

    //2D buffer Setup


    IDXGISurface* pBackBuffer = nullptr;
    Graphic_Throw_Failure(pSwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)));

    //makes 2d Factory
    Graphic_Throw_Failure(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &p2DFactory));

    //sets up DXGI buffer for 2d
    FLOAT dpi;
    dpi = GetDpiForWindow(hwnd);
    //p2DFactory->GetDesktopDpi(&dpiX, &dpiY);

    D2D1_RENDER_TARGET_PROPERTIES p2dRTprops =
        D2D1::RenderTargetProperties(
            D2D1_RENDER_TARGET_TYPE_DEFAULT,
            D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED),
            dpi,
            dpi
        );


    Graphic_Throw_Failure(p2DFactory->CreateDxgiSurfaceRenderTarget(
        pBackBuffer, &p2dRTprops, &p2dRenderTarget

    ));



    if (pBackBuffer != nullptr)
        pBackBuffer->Release();
    
};
//and the destructor in case there is something still wrong there though 
//currently not giving me issues since I set the objects in it to nullptr after releasing it. 
//didn't work for the ComPtr.

  Graphics::~Graphics() {
        if (p2DFactory != nullptr) {
            p2DFactory->Release();
        }

        if (p2dRenderTarget != nullptr) {
            p2dRenderTarget->Release();
        }
    }


)与他们打交道并绘制它们。我再次为此类别做了一些例外,

//some variables in the header file
ID2D1Bitmap* Bittmap=nullptr;
     Graphics* GFX;

Sprites::Sprites(const wchar_t* filename, Graphics* gfx) {
    
    HRESULT hre;
    GFX = gfx;


    //makes WIC Factory
    
    IWICImagingFactory* WICfactory = NULL;
    Sprite_Throw_Failure(CoCreateInstance(
        CLSID_WICImagingFactory,
        NULL,
        CLSCTX_INPROC_SERVER,
        IID_IWICImagingFactory,
        (LPVOID*)&WICfactory
    ));

    //Makes the Decoder

    IWICBitmapDecoder* WICdecode = NULL;
    Sprite_Throw_Failure(WICfactory->CreateDecoderFromFilename(
        filename,
        NULL,
        GENERIC_READ,
        WICDecodeMetadataCacheOnLoad,
        &WICdecode
    ));
    
    //Read the frame (should be only one so read the image)
    IWICBitmapFrameDecode* WICframe = NULL;
    Sprite_Throw_Failure(WICdecode->GetFrame(0, &WICframe));

    //Format converter
    IWICFormatConverter* WICconverter = NULL;
    Sprite_Throw_Failure(WICfactory->CreateFormatConverter(&WICconverter));

    //makes the converter set up to create a 32bpp BGRA bitmap
    Sprite_Throw_Failure(WICconverter->Initialize(
        WICframe,
        GUID_WICPixelFormat32bppPBGRA,
        WICBitmapDitherTypeNone,
        NULL,
        0.0,
        WICBitmapPaletteTypeCustom
    ));

    //makes the bitmap
    
    Sprite_Throw_Failure(GFX->Get2DRenderTarget()->CreateBitmapFromWicBitmap(
    WICconverter,
    NULL,
    &Bittmap
    ));

    if (WICfactory) WICfactory->Release();
    if (WICdecode) WICdecode->Release();
    if (WICconverter)WICconverter->Release();
    if (WICframe)WICframe->Release();

}
//draws the sprites
void Sprites::Draw(D2D1_RECT_F location) {
    HRESULT hre;
    GFX->Get2DRenderTarget()->BeginDraw();
    GFX->Get2DRenderTarget()->DrawBitmap(
        Bittmap,
        location, //destination rect
        1.0f, //opacity
        D2D1_BITMAP_INTERPOLATION_MODE::D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
        D2D1::RectF(
            1980.0f, 2850.0f, 3000.0f, 
            3600.0f) //source rect
        );
    

    Sprite_Throw_Failure(GFX->Get2DRenderTarget()-> EndDraw());
}


Sprites::~Sprites() {
    //bitmapsheet.clear();
    if (Bittmap != nullptr) {
        Bittmap->Release();
    }



}

这是主循环处理的类是我制作和管理窗口的窗口类。我在这里使用它来获取具有所有直接内容的窗口使用的图形对象。这是一些出现的变量,请原谅鲍勃这个名字。

//in header file
private:
    Window wnd;

//in cpp file
Sprites* testsprite;
Sprites* testsprite2;
D2D1_RECT_F bob;

在我渲染的部分过程中,在程序的持续时间内反复调用的功能中:

//inefficient constant adjusting of rendering just so I can quickly assess 
//the change and make sure it works so when I implement how I intend the windows to be scaled it 
//will already be done
  wnd.GFX().adjustRenderTargets(wnd.getwindowhandle());

//clearing the ID3D11RenderTargetView to a color
  wnd.GFX().ClearBuffer(0.3f, 0.5f, 1.0f);
//drawing calls



       
        const wchar_t* filename = L"\environmentsketches 02.png";

        //this creates a Sprites object getGraphix returns the a pointer to the graphics object
        //only really used to get the ID2D1RenderTarget but I may use it for other things, will
        //remove later if not needed and just pass the render target unless issues arise.
        testsprite = new Sprites(filename, wnd.GFX().getGraphix());

      
        bob = D2D1::RectF(
            0.0f, 0.0f, wnd.getwindowWidth(),
            wnd.getwindowHeight());
         //This draws the bitmap of a predetermined portion of the image but uses bob to
         // to determine where to draw the bitmap  
        testsprite->Draw(bob);

        bob = D2D1::RectF(
            0.0f, 0.0f, wnd.getwindowWidth()/(16.0f/9.0f),
            wnd.getwindowHeight());

       testsprite->Draw(bob);


        filename= L"\envrioment sketch march 1.png";
        bob = D2D1::RectF(
            100.0f, 100.0f, 600.f,
            300.f);
        
        testsprite2 = new Sprites(filename, wnd.GFX().getGraphix());
        testsprite2->Draw(bob);

        //EndFrame just calls present on the IDXGISwapChain
        wnd.GFX().EndFrame();
        testsprite->~Sprites();
        testsprite2->~Sprites();

如果您阅读了此信息,请感谢您,并感谢您提供的任何建议。

So I'm trying to iron out kinks of how I'm rendering images with direct stuff. Right now it works as a DXGISwapchain with D3D11 and I make a ID2D1RenderTarget which I draw to using bitmaps. My issue is when I hit the maximize button on the window my images are off, or at least the ones using data from the window grabbed with GetClientRect (the others seem... close enough but probably still off and I want to be able to use the client space to scale and draw things later as well). I have a D2D1::RectF set with the top left at 0.0f and the bottom right as the window's height and width grabbed via GetClientRect (along with a few others just for additional fooling around). Looked around and it seems like I need to call recreate the ID2D1RenderTarget and/or resize the buffers. Calling a function to recreate the ID2D1RenderTarget before making objects which contain the bitmaps and the functions which draw them did not help with the issue at all. I tried resizing the buffers but I keep getting errors, first set were regarding parameters, but before fixing that I realized I needed to release the objects, but now my it seems since I have made the objects with ComPtr it seems how it deals with deleting them is having issues. client.h is calling an exception: "Access violation executing location " with the unsigned long InternalRelease() function. This occurs with the function to adjust the buffers and target. So right now I'm lost as to what to do in order to get the desired effect. Only other things to note is the ID3D11RenderTargetView I made is used to clear to a color since for I had errors with calling Clear(D2D1::ColorF(D2D1::ColorF::White)); on my ID2D1RenderTarget. I don't care if the solution to this resizes the ID3D11RenderTargetView unless it will improve speed for the program or prevent some sort of unforeseen issue elsewhere since I don't intend to use it aside for that. If I could call clear on the ID2D1RenderTarget and no longer need the ID311RenderTargetView and keep the swapchain while resolving the issue that would work too. Also I intend to work out fullscreen mode next so a method that works with that would also be very much desired. I'm also open to take any other advice here, while it's not polished and just in a form to get things working first, I probably will miss things even when tidying up. Anyway here's the code:

Here's the Graphics class where I make the swapchain, buffers and rendertargets and such and the function in which I try and reset the buffers. Side note I followed some tutorials on my way here to get me to understand enough of the direct stuff to get here and get to the point where I'm looking into to stuff on Microsoft and understanding it somewhat to solve problems I have. Anyway one of them went through making some exceptions and that is what stuff like Graphic_Throw_Failure() are for. (though I did it wrong or the errors are doing something and I can't see the pop up window half the time, sometimes it stops in the exception code but I can still read the message)

//not in the cpp file but just how some variables exist for clarity.
private:
    
    Microsoft::WRL::ComPtr<ID3D11Device> pDevice = nullptr;
    Microsoft::WRL::ComPtr < IDXGISwapChain> pSwapChain = nullptr;
    Microsoft::WRL::ComPtr < ID3D11DeviceContext> pContext = nullptr;
    Microsoft::WRL::ComPtr < ID3D11RenderTargetView> pRTarget = nullptr;
    ID2D1RenderTarget* p2dRenderTarget = nullptr;
    ID2D1Factory* p2DFactory = nullptr;
    

Graphics::Graphics(HWND hwnd) {
    
    DXGI_SWAP_CHAIN_DESC swapchainDesc = {};
    ZeroMemory(&swapchainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
    swapchainDesc.Windowed = true;
    swapchainDesc.BufferCount = 1;
    swapchainDesc.BufferDesc.Height = 0;
    swapchainDesc.BufferDesc.Width = 0;
    swapchainDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    swapchainDesc.SampleDesc.Count = 1;
    swapchainDesc.SampleDesc.Quality = 0;
    swapchainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
    swapchainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    swapchainDesc.BufferDesc.RefreshRate.Numerator = 1;
    swapchainDesc.BufferDesc.RefreshRate.Denominator = 60;
    swapchainDesc.OutputWindow = hwnd;
    HRESULT hre;
    Graphic_Throw_Failure(D3D11CreateDeviceAndSwapChain(
        nullptr,
        D3D_DRIVER_TYPE_HARDWARE,
        nullptr,
        D3D11_CREATE_DEVICE_BGRA_SUPPORT,
        levels,
        4,
        D3D11_SDK_VERSION,
        &swapchainDesc,
        &pSwapChain,
        &pDevice,
        nullptr,
        &pContext
    ));

  
   
    
   //3Dbuffer setup
    wrl::ComPtr<ID3D11Resource> p3dbuffer = nullptr;
    Graphic_Throw_Failure(pSwapChain->GetBuffer(0, __uuidof(ID3D11Resource), &p3dbuffer));
    Graphic_Throw_Failure(pDevice->CreateRenderTargetView(p3dbuffer.Get(), nullptr, &pRTarget));

    //2D buffer Setup
    

    IDXGISurface* pBackBuffer = nullptr;
    Graphic_Throw_Failure(pSwapChain->GetBuffer(0,IID_PPV_ARGS(&pBackBuffer)));

    //makes 2d Factory
    Graphic_Throw_Failure(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &p2DFactory));
    
    //sets up DXGI buffer for 2d
    FLOAT dpi;
    dpi = GetDpiForWindow(hwnd);
    //p2DFactory->GetDesktopDpi(&dpiX, &dpiY);

    D2D1_RENDER_TARGET_PROPERTIES p2dRTprops =
        D2D1::RenderTargetProperties(
            D2D1_RENDER_TARGET_TYPE_DEFAULT,
            D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED),
            dpi,
            dpi
        );
        

    Graphic_Throw_Failure(p2DFactory->CreateDxgiSurfaceRenderTarget(
        pBackBuffer, &p2dRTprops, &p2dRenderTarget

    ));

    

    if(pBackBuffer!=nullptr)
    pBackBuffer->Release();
}



//the adjusting function I failed to make. could also be missing somethings I need to clear before
//calling ResizeBuffers


void Graphics::adjustRenderTargets(HWND hwnd) {
  HRESULT hre;


    pContext->ClearState();
    p2dRenderTarget->Release();
    pRTarget->Release();

    //3Dbuffer setup
    wrl::ComPtr<ID3D11Resource> p3dbuffer = nullptr;
    Graphic_Throw_Failure(pSwapChain->GetBuffer(0, __uuidof(ID3D11Resource), &p3dbuffer));
    Graphic_Throw_Failure(pDevice->CreateRenderTargetView(p3dbuffer.Get(), nullptr, &pRTarget));

    //2D buffer Setup


    IDXGISurface* pBackBuffer = nullptr;
    Graphic_Throw_Failure(pSwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)));

    //makes 2d Factory
    Graphic_Throw_Failure(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &p2DFactory));

    //sets up DXGI buffer for 2d
    FLOAT dpi;
    dpi = GetDpiForWindow(hwnd);
    //p2DFactory->GetDesktopDpi(&dpiX, &dpiY);

    D2D1_RENDER_TARGET_PROPERTIES p2dRTprops =
        D2D1::RenderTargetProperties(
            D2D1_RENDER_TARGET_TYPE_DEFAULT,
            D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED),
            dpi,
            dpi
        );


    Graphic_Throw_Failure(p2DFactory->CreateDxgiSurfaceRenderTarget(
        pBackBuffer, &p2dRTprops, &p2dRenderTarget

    ));



    if (pBackBuffer != nullptr)
        pBackBuffer->Release();
    
};
//and the destructor in case there is something still wrong there though 
//currently not giving me issues since I set the objects in it to nullptr after releasing it. 
//didn't work for the ComPtr.

  Graphics::~Graphics() {
        if (p2DFactory != nullptr) {
            p2DFactory->Release();
        }

        if (p2dRenderTarget != nullptr) {
            p2dRenderTarget->Release();
        }
    }


This is the class which holds the bitmaps and deals with them and drawing them. Once again I made some exceptions for this class

//some variables in the header file
ID2D1Bitmap* Bittmap=nullptr;
     Graphics* GFX;

Sprites::Sprites(const wchar_t* filename, Graphics* gfx) {
    
    HRESULT hre;
    GFX = gfx;


    //makes WIC Factory
    
    IWICImagingFactory* WICfactory = NULL;
    Sprite_Throw_Failure(CoCreateInstance(
        CLSID_WICImagingFactory,
        NULL,
        CLSCTX_INPROC_SERVER,
        IID_IWICImagingFactory,
        (LPVOID*)&WICfactory
    ));

    //Makes the Decoder

    IWICBitmapDecoder* WICdecode = NULL;
    Sprite_Throw_Failure(WICfactory->CreateDecoderFromFilename(
        filename,
        NULL,
        GENERIC_READ,
        WICDecodeMetadataCacheOnLoad,
        &WICdecode
    ));
    
    //Read the frame (should be only one so read the image)
    IWICBitmapFrameDecode* WICframe = NULL;
    Sprite_Throw_Failure(WICdecode->GetFrame(0, &WICframe));

    //Format converter
    IWICFormatConverter* WICconverter = NULL;
    Sprite_Throw_Failure(WICfactory->CreateFormatConverter(&WICconverter));

    //makes the converter set up to create a 32bpp BGRA bitmap
    Sprite_Throw_Failure(WICconverter->Initialize(
        WICframe,
        GUID_WICPixelFormat32bppPBGRA,
        WICBitmapDitherTypeNone,
        NULL,
        0.0,
        WICBitmapPaletteTypeCustom
    ));

    //makes the bitmap
    
    Sprite_Throw_Failure(GFX->Get2DRenderTarget()->CreateBitmapFromWicBitmap(
    WICconverter,
    NULL,
    &Bittmap
    ));

    if (WICfactory) WICfactory->Release();
    if (WICdecode) WICdecode->Release();
    if (WICconverter)WICconverter->Release();
    if (WICframe)WICframe->Release();

}
//draws the sprites
void Sprites::Draw(D2D1_RECT_F location) {
    HRESULT hre;
    GFX->Get2DRenderTarget()->BeginDraw();
    GFX->Get2DRenderTarget()->DrawBitmap(
        Bittmap,
        location, //destination rect
        1.0f, //opacity
        D2D1_BITMAP_INTERPOLATION_MODE::D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
        D2D1::RectF(
            1980.0f, 2850.0f, 3000.0f, 
            3600.0f) //source rect
        );
    

    Sprite_Throw_Failure(GFX->Get2DRenderTarget()-> EndDraw());
}


Sprites::~Sprites() {
    //bitmapsheet.clear();
    if (Bittmap != nullptr) {
        Bittmap->Release();
    }



}

This is the class which the main loop is handled wnd is the windowclass I made which makes and manages the window. I use it here to get the graphics object the window uses which has all the direct stuff. here are some variables that appear, forgive the name bob.

//in header file
private:
    Window wnd;

//in cpp file
Sprites* testsprite;
Sprites* testsprite2;
D2D1_RECT_F bob;

within the function that calls over and over for the duration of the program at the part where I render:

//inefficient constant adjusting of rendering just so I can quickly assess 
//the change and make sure it works so when I implement how I intend the windows to be scaled it 
//will already be done
  wnd.GFX().adjustRenderTargets(wnd.getwindowhandle());

//clearing the ID3D11RenderTargetView to a color
  wnd.GFX().ClearBuffer(0.3f, 0.5f, 1.0f);
//drawing calls



       
        const wchar_t* filename = L"\environmentsketches 02.png";

        //this creates a Sprites object getGraphix returns the a pointer to the graphics object
        //only really used to get the ID2D1RenderTarget but I may use it for other things, will
        //remove later if not needed and just pass the render target unless issues arise.
        testsprite = new Sprites(filename, wnd.GFX().getGraphix());

      
        bob = D2D1::RectF(
            0.0f, 0.0f, wnd.getwindowWidth(),
            wnd.getwindowHeight());
         //This draws the bitmap of a predetermined portion of the image but uses bob to
         // to determine where to draw the bitmap  
        testsprite->Draw(bob);

        bob = D2D1::RectF(
            0.0f, 0.0f, wnd.getwindowWidth()/(16.0f/9.0f),
            wnd.getwindowHeight());

       testsprite->Draw(bob);


        filename= L"\envrioment sketch march 1.png";
        bob = D2D1::RectF(
            100.0f, 100.0f, 600.f,
            300.f);
        
        testsprite2 = new Sprites(filename, wnd.GFX().getGraphix());
        testsprite2->Draw(bob);

        //EndFrame just calls present on the IDXGISwapChain
        wnd.GFX().EndFrame();
        testsprite->~Sprites();
        testsprite2->~Sprites();

If you read through this thank you and thank you for any advice you have to offer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

她比我温柔 2025-01-29 11:18:33

不要迟到或疲倦。因此,我意识到的第一件事是在此处发布代码时,我忘了将swapchain-&gt; resizeBuffers的调用(0,宽度,高度,dxgi_format_unknown,0))是错误。我将指针从Smart更改为常规,为此手动管理其发行版,但是更重要的是,最后一个参数不是0,它是D3D11_CREATE_DEVICE_BGRA_BGRA_SUPPORT,而不是适当的Swapchain Flag,而不是读书(我相信DXGI_SWAP_SWAP_CHAP_CHAP_CHAP_FLAG_FLAG_DISPLAY_ONLY)我无法使用它是因为我如何使自己的Swapchain导致错误,但它只是没有运行。

在解决问题的所有解决方案中,是释放渲染目标(我制作目标后已经发布了缓冲区),调整缓冲区大小,然后重新制作ID2D1RendArget。只是不要在其中放置错误的旗帜(或确保在将其发布以表示对错误的反馈时,可能会被其他人抓住。)

Don't code late or tired. So first thing I realized is one when posting the code here I forgot to include the call for SwapChain->ResizeBuffers(0,width,height, DXGI_FORMAT_UNKNOWN, 0)) which is where the mistake was. I changed my pointers from smart to regular to manage their release manually for this, but the issue was more so that the last parameter wasn't 0, it was D3D11_CREATE_DEVICE_BGRA_SUPPORT instead of a proper swapchain flag and was reading as another (I believe DXGI_SWAP_CHAIN_FLAG_DISPLAY_ONLY) which I couldn't use because of how I made my swapchain resulting in an error and it just not running.

In all the solution to my problem was to release my render targets (I already released by buffers after I made the targets), resize the buffers and then remake the ID2D1RenderTarget. Just don't put a wrong flag in, (or make sure the call is in when posting it for feedback to the mistake might be caught by others.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文