-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07ecf2a
commit 880891d
Showing
6 changed files
with
133 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include "StdAfx.h" | ||
|
||
#include <d3d11.h> | ||
#include <Windows.h> | ||
|
||
IDXGISwapChain* g_pSwapChain = nullptr; | ||
ID3D11Device* g_pd3dDevice = nullptr; | ||
ID3D11DeviceContext* g_pImmediateContext = nullptr; | ||
ID3D11RenderTargetView* g_pRenderTargetView = nullptr; | ||
|
||
#include "CreateDirectXDevice.hpp" | ||
|
||
//using namespace RenderLibary; | ||
|
||
void CreateCustomDirectXScene(HWND hwnd) | ||
{ | ||
// Описание цепочки свопа | ||
DXGI_SWAP_CHAIN_DESC sd = {}; | ||
sd.BufferCount = 1; | ||
sd.BufferDesc.Width = 800; | ||
sd.BufferDesc.Height = 600; | ||
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; | ||
sd.BufferDesc.RefreshRate.Numerator = 60; | ||
sd.BufferDesc.RefreshRate.Denominator = 1; | ||
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; | ||
sd.OutputWindow = hwnd; | ||
sd.SampleDesc.Count = 1; | ||
sd.SampleDesc.Quality = 0; | ||
sd.Windowed = TRUE; | ||
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; | ||
sd.Flags = 0; | ||
|
||
D3D_FEATURE_LEVEL featureLevel; | ||
HRESULT hr = D3D11CreateDeviceAndSwapChain | ||
( | ||
nullptr, | ||
D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, nullptr, 0, | ||
D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, | ||
&featureLevel, &g_pImmediateContext | ||
); | ||
|
||
if (FAILED(hr)) | ||
{ | ||
MessageBox(hwnd, L"Failed to create Direct3D device and swap chain!", L"Error", MB_ICONERROR); | ||
return; | ||
} | ||
|
||
ID3D11Texture2D* pBackBuffer = nullptr; | ||
g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); | ||
g_pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &g_pRenderTargetView); | ||
pBackBuffer->Release(); | ||
|
||
// Установка представления цели рендеринга | ||
g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView, nullptr); | ||
|
||
D3D11_VIEWPORT vp; | ||
|
||
vp.Width = (FLOAT)800; | ||
vp.Height = (FLOAT)600; | ||
vp.MinDepth = 0.0f; | ||
vp.MaxDepth = 1.0f; | ||
vp.TopLeftX = 0; | ||
vp.TopLeftY = 0; | ||
|
||
g_pImmediateContext->RSSetViewports(1, &vp); | ||
} | ||
|
||
// Очистка ресурсов DirectX | ||
void CleanupDirectX() | ||
{ | ||
if (g_pImmediateContext) | ||
{ | ||
g_pImmediateContext->ClearState(); | ||
} | ||
|
||
if (g_pRenderTargetView) | ||
{ | ||
g_pRenderTargetView->Release(); | ||
} | ||
|
||
if (g_pSwapChain) | ||
{ | ||
g_pSwapChain->Release(); | ||
} | ||
|
||
if (g_pImmediateContext) | ||
{ | ||
g_pImmediateContext->Release(); | ||
} | ||
|
||
if (g_pd3dDevice) | ||
{ | ||
g_pd3dDevice->Release(); | ||
} | ||
} | ||
|
||
bool RenderFrame() | ||
{ | ||
const float clearColor[4] = { 0.0f, 0.2f, 0.4f, 1.0f }; | ||
g_pImmediateContext->ClearRenderTargetView(g_pRenderTargetView, clearColor); | ||
|
||
g_pSwapChain->Present(0, 0); | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
extern "C" | ||
{ | ||
void CreateCustomDirectXScene(HWND hwnd); | ||
void CleanupDirectX(); | ||
bool RenderFrame(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters