SDL3 -Fenster kann D3D11 Swapchain nicht angezeigt werdenC++

Programme in C++. Entwicklerforum
Anonymous
 SDL3 -Fenster kann D3D11 Swapchain nicht angezeigt werden

Post by Anonymous »

Ich habe meine eigene Game Engine mit SDL3 und DX11 geschrieben. Ich konnte das HWND erhalten und auf swapchaNDesc.outputWindow einstellen und die Farbe auf Pink einstellen:

Code: Select all

#define SDL_MAIN_USE_CALLBACKS 1
#include "SDL3/SDL.h"
#include "SDL3/SDL_main.h"
#include "SDL3/SDL_events.h"

#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3dcompiler.lib")

#include 
#include 

#include 

SDL_Window* window;

ID3D11Device* pD3D11Dev = NULL;
ID3D11DeviceContext* pD3D11DevContext = NULL;
IDXGISwapChain *pSwapChain = NULL;
ID3D11Texture2D *pRenderTargetResource = NULL;
ID3D11RenderTargetView *pBackBuffer = NULL;

SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
if (!SDL_Init(SDL_INIT_VIDEO))
{
return SDL_APP_FAILURE;
}

window = SDL_CreateWindow("Doctrina Editor", 640, 480, SDL_WINDOW_RESIZABLE);

HWND hwnd = reinterpret_cast(SDL_GetWindowFromID(SDL_GetWindowID(window)));

int windowWidth, windowHeight;
SDL_GetWindowSize(window, &windowWidth, &windowHeight);

D3D_FEATURE_LEVEL  featureLevelsRequested = D3D_FEATURE_LEVEL_11_0;
D3D_FEATURE_LEVEL  featureLevelsSupported;

DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = windowWidth;
swapChainDesc.BufferDesc.Height = windowHeight;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = hwnd;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.Windowed = TRUE;

HRESULT d3dHR = D3D11CreateDeviceAndSwapChain(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
D3D11_CREATE_DEVICE_DEBUG,
&featureLevelsRequested,
1,
D3D11_SDK_VERSION,
&swapChainDesc,
&pSwapChain,
&pD3D11Dev,
&featureLevelsSupported,
&pD3D11DevContext
);

pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pRenderTargetResource);

if (pRenderTargetResource != NULL) {
pD3D11Dev->CreateRenderTargetView(pRenderTargetResource, NULL, &pBackBuffer);
pRenderTargetResource->Release();
pD3D11DevContext->OMSetRenderTargets(1, &pBackBuffer, NULL);
}

D3D11_VIEWPORT viewPort = {};
viewPort.TopLeftX = 0;
viewPort.TopLeftY = 0;
viewPort.Width = windowWidth;
viewPort.Height = windowHeight;

pD3D11DevContext->RSSetViewports(1, &viewPort);

return SDL_APP_CONTINUE;
}

SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {

if (event->type == SDL_EVENT_QUIT)
{
return SDL_APP_SUCCESS;
}

if (event->type == SDL_EVENT_WINDOW_RESIZED)
{
int newWidth = event->window.data1;
int newHeight = event->window.data2;
}

return SDL_APP_CONTINUE;
}

SDL_AppResult SDL_AppIterate(void* appstate)
{

float color[4];

color[0] = 255.0f;
color[1] = 0.0f;
color[2] = 255.0f;
color[3] = 1.0f;
pD3D11DevContext->ClearRenderTargetView(pBackBuffer, color);

pSwapChain->Present(1, 0);

return SDL_APP_CONTINUE;
}

void SDL_AppQuit(void* appstate, SDL_AppResult result)
{

pSwapChain->Release();
pBackBuffer->Release();
pD3D11Dev->Release();
pD3D11DevContext->Release();

SDL_Quit();
}
Aber das Fenster ist schwarz, obwohl es rosa sein soll? https://github.com/adoseofcodeyt/doctrinasdk

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post