DirectX 11 Grauer Bildschirm
-
Hey Leute!
Ich bin mal wieder am Direct3D üben, und ich wollte jetzt meine einzige Klasse auf ein paar mehr aufteilen, auch aufgrund der neuen Möglichkeiten. Nun ja, es funktioniert nicht.
Der ganze Code debuggt ohne Probleme, aber wenn ich dann eigentlich einen Boden und einen Lichtfleck sehen müsste, sehe ich auf einmal die Maus und einen grau-Schwarzen Bildschirm. Ich werde unten die InitDirect3D und die InitDirect2D Funktion anhängen... Und das ganze Projekt hochladen.
Wenn jemand so nett wäre, sich meiner anzunehmen und sich den Code anzusehen wäre ich ihm sehr verbunden.
MFG
FERNmanbool CGame::InitDirect3D() { //Buffer der Swapchain DXGI_MODE_DESC BufferDesc; ZeroMemory(&BufferDesc, sizeof(BufferDesc)); BufferDesc.Width = ResX; BufferDesc.Height = ResY; BufferDesc.RefreshRate.Numerator = 60; BufferDesc.RefreshRate.Denominator = 1; BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; // //Swapchain DXGI_SWAP_CHAIN_DESC SwapChainDesc; ZeroMemory(&SwapChainDesc, sizeof(SwapChainDesc)); SwapChainDesc.BufferDesc = BufferDesc; SwapChainDesc.SampleDesc.Count = 1; SwapChainDesc.SampleDesc.Quality = 0; SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; SwapChainDesc.BufferCount = 1; SwapChainDesc.OutputWindow = hWnd; SwapChainDesc.Windowed = true; SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; // //DXGI Factory IDXGIFactory1* DXGIFactory; hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&DXGIFactory); IDXGIAdapter1* Adapter; hr = DXGIFactory->EnumAdapters1(0, &Adapter); DXGIFactory->Release(); //Swap Chain Erstellen hr = D3D11CreateDeviceAndSwapChain(Adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, D3D11_CREATE_DEVICE_BGRA_SUPPORT, NULL, NULL, D3D11_SDK_VERSION, &SwapChainDesc, &SwapChain, &D3D11Device, NULL, &D3D11DevCon); // //2D InitDirect2D(Adapter); // Adapter->Release(); hr = SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&BackBuffer11); hr = D3D11Device->CreateRenderTargetView(BackBuffer11, NULL, &RenderTargetView); // //Depth/Stencil Buffer D3D11_TEXTURE2D_DESC DepthStencilDesc; ZeroMemory(&DepthStencilDesc, sizeof(DepthStencilDesc)); DepthStencilDesc.Width = ResX; DepthStencilDesc.Height = ResY; DepthStencilDesc.MipLevels = 1; DepthStencilDesc.ArraySize = 1; DepthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; DepthStencilDesc.SampleDesc.Count = 1; DepthStencilDesc.SampleDesc.Quality = 0; DepthStencilDesc.Usage = D3D11_USAGE_DEFAULT; DepthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; DepthStencilDesc.CPUAccessFlags = 0; DepthStencilDesc.MiscFlags = 0; D3D11Device->CreateTexture2D(&DepthStencilDesc, NULL, &DepthStencilBuffer); D3D11Device->CreateDepthStencilView(DepthStencilBuffer, NULL, &DepthStencilView); // return true; } bool CGame::InitDirect2D(IDXGIAdapter1* Adapter) { //Create our Direc3D 10.1 Device/////////////////////////////////////////////////////////////////////////////////////// hr = D3D10CreateDevice1(Adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, D3D10_CREATE_DEVICE_BGRA_SUPPORT, D3D10_FEATURE_LEVEL_9_3, D3D10_1_SDK_VERSION, &D3D101Device); //Create Shared Texture that Direct3D 10.1 will render on////////////////////////////////////////////////////////////// D3D11_TEXTURE2D_DESC sharedTexDesc; ZeroMemory(&sharedTexDesc, sizeof(sharedTexDesc)); sharedTexDesc.Width = ResX; sharedTexDesc.Height = ResY; sharedTexDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; sharedTexDesc.MipLevels = 1; sharedTexDesc.ArraySize = 1; sharedTexDesc.SampleDesc.Count = 1; sharedTexDesc.Usage = D3D11_USAGE_DEFAULT; sharedTexDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; sharedTexDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX; hr = D3D11Device->CreateTexture2D(&sharedTexDesc, NULL, &SharedTex11); // Get the keyed mutex for the shared texture (for D3D11)/////////////////////////////////////////////////////////////// hr = SharedTex11->QueryInterface(__uuidof(IDXGIKeyedMutex), (void**)&KeyedMutex11); // Get the shared handle needed to open the shared texture in D3D10.1/////////////////////////////////////////////////// IDXGIResource *sharedResource10; HANDLE sharedHandle10; hr = SharedTex11->QueryInterface(__uuidof(IDXGIResource), (void**)&sharedResource10); hr = sharedResource10->GetSharedHandle(&sharedHandle10); sharedResource10->Release(); // Open the surface for the shared texture in D3D10.1/////////////////////////////////////////////////////////////////// IDXGISurface1 *sharedSurface10; hr = D3D101Device->OpenSharedResource(sharedHandle10, __uuidof(IDXGISurface1), (void**)(&sharedSurface10)); hr = sharedSurface10->QueryInterface(__uuidof(IDXGIKeyedMutex), (void**)&KeyedMutex10); // Create D2D factory/////////////////////////////////////////////////////////////////////////////////////////////////// ID2D1Factory *D2DFactory; hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), (void**)&D2DFactory); D2D1_RENDER_TARGET_PROPERTIES renderTargetProperties; ZeroMemory(&renderTargetProperties, sizeof(renderTargetProperties)); renderTargetProperties.type = D2D1_RENDER_TARGET_TYPE_HARDWARE; renderTargetProperties.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED); hr = D2DFactory->CreateDxgiSurfaceRenderTarget(sharedSurface10, &renderTargetProperties, &D2DRenderTarget); sharedSurface10->Release(); D2DFactory->Release(); // Create a solid color brush to draw something wit hr = D2DRenderTarget->CreateSolidColorBrush(D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f), &Brush); //DirectWrite/////////////////////////////////////////////////////////////////////////////////////////////////////////// hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast<IUnknown**>(&DWriteFactory)); hr = DWriteFactory->CreateTextFormat( L"Script", NULL, DWRITE_FONT_WEIGHT_REGULAR, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 24.0f, L"en-us", &TextFormat ); hr = TextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING); hr = TextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR); D3D101Device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST); return true; }
Und der Konstruktor:
CGame::CGame(HINSTANCE hInstance, int ShowWnd) :ResX(1920), ResY(1080) { //Initialize Variables hInst = hInstance; WndClassName = L"Boxhead 3D"; NumElements = ARRAYSIZE(Layout); // //Initialize Funktions if (!InitWindow(ShowWnd)) { MessageBox(NULL, L"Fehler beim erstellen des Fensters", L"Fehler", MB_OK); exit(0); } if (!InitDirect3D()) { MessageBox(NULL, L"Fehler beim Initialisieren von Direct3D", L"Fehler", MB_OK); exit(0); } if (!InitScene()) { MessageBox(NULL, L"Fehler beim Initialisieren der Gegenstände", L"Fehler", MB_OK); exit(0); } if (!InitInput()) { MessageBox(NULL, L"Fehler beim Initalisieren der Eingabegeräte", L"Fehler", MB_OK); exit(0); } // Run(); }
Und zu guter Letzt, der Download: http://www.4shared.com/rar/xAqjWZr0ce/Fix.html
-
FERNman schrieb:
hr = ...; hr = ...; hr = ...; hr = ...; hr = ...;
Bist schon lustig, es bringt nichts die Rückgabewerte nur entgegenzunehmen, man muss sie auch prüfen. Welchen Sinn hätten sie denn sonst??
Am einfachsten so:if(FAILED(hr)){ //Dann halt irgendwas machen, sodass du bemerkst das da ein Fehler ist z.B. MessageBoxA(0, "Funktion XYZ() ist fehlgeschlagen",0,0); }
Dann noch schauen welcher Fehler es ist: http://msdn.microsoft.com/de-de/library/windows/desktop/ff476174(v=vs.85).aspx
und anschließend das Problem lösen.floorball
-
Danke!
MFG
FERNman