2013-01-22 2 views
1

ClearRenderTargetView 호출시 실패합니다. Im 내 오류가 어디에 있는지 잘 모르겠다 - 튜토리얼을 따른다. 그리고 내가 잘못 알지도 못한다. 도움을 주셔서 감사합니다.DirectX11 ClearRenderTargetView

// DX6.cpp : 응용 프로그램의 진입 점을 정의합니다. 는 // CreateRenderTargetViewRenderFramebackbuffer에서라고 때문에

#include "stdafx.h" 
#include "DX6.h" 
#include <d3d11.h> 
#include <d3dx11.h> 
#include <d3d10.h> 
#include <d3dx9core.h> 

// include the Direct3D Library file 
#pragma comment (lib, "d3d11.lib") 
#pragma comment (lib, "d3dx11.lib") 
#pragma comment (lib, "d3dx10.lib") 

//forward declares 
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 
void InitD3D(HWND hWnd);  // sets up and initializes Direct3D 
void RenderFrame(void); 
void CleanD3D(void);   // closes Direct3D and releases memory 

// Global Variables: 
HWND hWnd; 
HINSTANCE hInst; 
IDXGISwapChain *swapchain;    // the pointer to the swap chain interface 
ID3D11Device *dev;      // the pointer to our Direct3D device interface 
ID3D11DeviceContext *devcon;   // the pointer to our Direct3D device context 
ID3D11RenderTargetView *backbuffer; // global declaration 




int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow) 
{ 
    WNDCLASSEX wc; 
    ZeroMemory(&wc,sizeof(WNDCLASSEX)); 
    wc.cbSize = sizeof(WNDCLASSEX); 
    wc.style = CS_HREDRAW | CS_VREDRAW; 
    wc.lpfnWndProc = WndProc; 
    wc.hInstance = hInstance; 
    wc.hCursor = LoadCursor(NULL, IDC_ARROW); 
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW; 
    wc.lpszClassName = L"WindowClass1"; 
    RegisterClassEx(&wc); 

    // TODO: Place code here. 
    MSG msg={0}; 

    hInst = hInstance; // Store instance handle in our global variable 

    hWnd = CreateWindow(L"WindowClass1", L"Test Title", WS_OVERLAPPEDWINDOW, 
     CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); 

    if (!hWnd) 
    { 
     return 1; 
    } 

    ShowWindow(hWnd, nCmdShow); 

    // Main message loop: 
    while (true) 
    { 
     if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
     { 
      // translate keystroke messages into the right format 
      TranslateMessage(&msg); 

      // send the message to the WindowProc function 
      DispatchMessage(&msg); 

      // check to see if it's time to quit 
      if(msg.message == WM_QUIT) 
       break; 
     } 
     else{ 
      RenderFrame(); 
     } 
    } 

    return (int) msg.wParam; 
} 
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 
{ 
    int wmId, wmEvent; 
    PAINTSTRUCT ps; 
    HDC hdc; 

    switch (message) 
    { 
    case WM_COMMAND: 
     wmId = LOWORD(wParam); 
     wmEvent = HIWORD(wParam); 
     // Parse the menu selections: 
     switch (wmId) 
     { 
     case IDM_EXIT: 
      DestroyWindow(hWnd); 
      break; 
     default: 
      return DefWindowProc(hWnd, message, wParam, lParam); 
     } 
     break; 
    case WM_PAINT: 
     hdc = BeginPaint(hWnd, &ps); 
     // TODO: Add any drawing code here... 
     EndPaint(hWnd, &ps); 
     break; 
    case WM_DESTROY: 
     PostQuitMessage(0); 
     break; 
    default: 
     return DefWindowProc(hWnd, message, wParam, lParam); 
    } 
    return 0; 
} 

//D3D 
void InitD3D(HWND hWnd){ 
    DXGI_SWAP_CHAIN_DESC scd; 
    ZeroMemory(&scd,sizeof(DXGI_SWAP_CHAIN_DESC)); 

    scd.BufferCount=1; 
    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;  // use 32-bit color 
    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;  // how swap chain is to be used 
    scd.OutputWindow = hWnd;        // the window to be used 
    scd.SampleDesc.Count = 4;        // how many multisamples 
    scd.Windowed = TRUE; 
    D3D11CreateDeviceAndSwapChain(NULL,D3D_DRIVER_TYPE_HARDWARE,NULL,NULL,NULL,NULL,D3D11_SDK_VERSION,&scd,&swapchain,&dev,NULL,&devcon); 

    ID3D11Texture2D *pBackBuffer; 
    swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); 

    // use the back buffer address to create the render target 
    dev->CreateRenderTargetView(pBackBuffer, NULL, &backbuffer); 
    pBackBuffer->Release(); 

    // set the render target as the back buffer 
    devcon->OMSetRenderTargets(1, &backbuffer, NULL); 

    //create viewport 
    D3D11_VIEWPORT viewport; 
    ZeroMemory(&viewport,sizeof(D3D11_VIEWPORT)); 
    viewport.TopLeftX=0; 
    viewport.TopLeftY=0; 
    viewport.Width=800; 
    viewport.Height=800; 

    //set viewport 
    devcon->RSSetViewports(1,&viewport); 


} 
void RenderFrame(void){ 
    //FAILS HERE!!! 
    //Unhandled exception at 0x002e1a9f in DX6.exe: 0xC0000005: Access violation  //reading location 0x00000000. 
    devcon->ClearRenderTargetView(backbuffer,D3DXCOLOR(0.0f,0.2f,0.4f,1.0f)); 

    //switch back & front buffer 
    swapchain->Present(0,0); 
} 

void CleanD3D() 
{ 
    // close and release all existing COM objects 
    swapchain->Release(); 
    dev->Release(); 
    devcon->Release(); 
} 

답변

2

당신은 InitD3D를 호출하지가 아직 설정되지 않았습니다.

+1

예. 나는 휴식을 취하고 비디오 게임을했는데 디버깅 중이었고 나는 InitD3D를 호출하지 않았다는 것을 알았다. 내가 그걸 알아 냈을 때 얼마나 화가 났는지 상상해 보라. LOL 프로페셔널 프로그래머 5 + yrs와 나는 지긋 지긋한 방법을 부르는 것을 잊어 버렸다. .. 긴 하루였다 :) 타이! –

관련 문제