2010-05-23 6 views
0

NULL Je suis en train de créer mon rendre vue cible, mais je reçois cette erreur directe XUn RenderTargetView ne peut être créé à partir d'une ressource

A RenderTargetView cannot be created from a NULL Resource 

A ma connaissance, il semble que je dois remplir le pointeur de RenderTarget avec des données avant de le passer. Mais j'ai du mal à comprendre comment. Ci-dessous ma déclaration et la mise en œuvre

déclaration

#pragma once 
#include "stdafx.h" 
#include "resource.h" 
#include "d3d10.h" 
#include "d3dx10.h" 
#include "dinput.h" 


#define MAX_LOADSTRING 100 

class RenderEngine { 
protected: 

    RECT m_screenRect; 

    //direct3d Members 
    ID3D10Device *m_pDevice; // The IDirect3DDevice10 
    // interface 
    ID3D10Texture2D *m_pBackBuffer; // Pointer to the back buffer 
    ID3D10RenderTargetView *m_pRenderTargetView; // Pointer to render target view 
    IDXGISwapChain *m_pSwapChain; // Pointer to the swap chain 
    RECT m_rcScreenRect; // The dimensions of the screen 

    ID3DX10Font *m_pFont; // The font used for rendering text 
    // Sprites used to hold font characters 
    ID3DX10Sprite *m_pFontSprite; 

    ATOM RegisterEngineClass(); 
    void Present(); 

public: 
    static HINSTANCE m_hInst; 
    HWND m_hWnd; 
    int m_nCmdShow; 
    TCHAR m_szTitle[MAX_LOADSTRING];     // The title bar text 
    TCHAR m_szWindowClass[MAX_LOADSTRING];   // the main window class name 

    void DrawTextString(int x, int y, D3DXCOLOR color, const TCHAR *strOutput); 

    //static functions 
    static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 
    static INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); 

    bool InitWindow(); 
    bool InitDirectX(); 
    bool InitInstance(); 
    int Run(); 

    RenderEngine() 
    { 
     m_screenRect.right = 800; 
     m_screenRect.bottom = 600; 
    } 

}; 

ma mise en œuvre

bool RenderEngine::InitDirectX() 
{ 
    //potential error. You did not set to zero memory and you did not set the scaling property 
    DXGI_MODE_DESC bd; 
    bd.Width     = m_screenRect.right; 
    bd.Height     = m_screenRect.bottom; 
    bd.Format     = DXGI_FORMAT_R8G8B8A8_UNORM; 
    bd.RefreshRate.Numerator = 60; 
    bd.RefreshRate.Denominator = 1; 

    DXGI_SAMPLE_DESC sd; 
    sd.Count = 1; 
    sd.Quality = 0; 

    DXGI_SWAP_CHAIN_DESC swapDesc; 
    ZeroMemory(&swapDesc, sizeof(swapDesc)); 

    swapDesc.BufferDesc  = bd; 
    swapDesc.SampleDesc  = sd; 
    swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 
    swapDesc.OutputWindow = m_hWnd; 
    swapDesc.BufferCount = 1; 
    swapDesc.SwapEffect  = DXGI_SWAP_EFFECT_DISCARD, 
    swapDesc.Windowed  = true; 
    swapDesc.Flags   = 0; 

    HRESULT hr; 

    hr = D3D10CreateDeviceAndSwapChain(NULL, 
     D3D10_DRIVER_TYPE_HARDWARE, 
     NULL, 
     D3D10_CREATE_DEVICE_DEBUG, 
     D3D10_SDK_VERSION , 
     &swapDesc, &m_pSwapChain, &m_pDevice); 

    if(FAILED(hr)) 
     return false; 

    // Create a render target view 
    hr = m_pDevice->CreateRenderTargetView(
        m_pBackBuffer, NULL, &m_pRenderTargetView); // FAILS RIGHT HERE 
    // 

    if(FAILED(hr)) 
     return false; 



    return true; 
} 

Répondre

0

figured it out. J'ai oublié de récupérer le tampon en premier. en appelant

m_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*) &m_pBackBuffer); 

puis je passe le tampon dans la méthode de rendu de la cible de rendu.

Questions connexes