I'm в настоящее время работает на D3D видеообработки и i'm получаю эти ошибки:Получение этих 2 ошибки в C++ (DirectX)
1.) ПЕРВАЯ ОШИБКА
2.) ВТОРАЯ ОШИБКА
ЗА РЕКОМЕНДУЕМ я буду очень благодарен :) + оШИБКИ помечаются в коде AS // 1. ERROR -> и //2.ERROR -> //
DXApp.cpp
#include "DXApp.h"
#include <d3dcommon.h>
namespace
{
//USED TO FORWARD MSGS TO USER DEFINED PROC FUNCTION //
DXApp* g_pApp = nullptr;
}
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (g_pApp) return g_pApp->MsgProc(hwnd, msg, wParam, lParam);
else return DefWindowProc(hwnd, msg, wParam, lParam);
}
DXApp::DXApp(HINSTANCE hInstance)
{
m_hAppInstance = hInstance;
m_hAppWnd = NULL;
m_ClientHeight = 800;
m_ClientWidth = 600;
m_AppTitle = "DX11 APP";
m_WndStyle = WS_OVERLAPPEDWINDOW;
m_pDevice = nullptr;
m_pImmediateContext = nullptr;
m_pRenderTargetView = nullptr;
m_pSwapChain = nullptr;
}
DXApp::~DXApp()
{
}
int DXApp::Run()
{
//MAIN MESSAGE LOOP//
MSG msg = { 0 };
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
//UPDATE..//
Update(0.0f);
//RENDER//
Render(0.0f);
}
}
return static_cast<int>(msg.wParam);
}
bool DXApp::Init()
{
if (!InitWindow())
return false;
return true;
}
bool DXApp::InitWindow()
{
//WNDCLASSGENDER
WNDCLASSEX wcex;
ZeroMemory(&wcex, sizeof(WNDCLASSEX));
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_VREDRAW | CS_HREDRAW;
wcex.hInstance = m_hAppInstance;
wcex.lpfnWndProc = MainWndProc;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "DXAPPWNDCLASS";
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&wcex))
{
OutputDebugString("\nFAILED TO CREATE WINDOW CLASS !\n");
return false;
}
RECT r = { 0, 0, m_ClientWidth, m_ClientHeight };
AdjustWindowRect(&r, m_WndStyle, FALSE);
UINT width = r.right - r.left;
UINT height = r.bottom - r.top;
UINT x = GetSystemMetrics(SM_CXSCREEN)/2 - width/2;
UINT y = GetSystemMetrics(SM_CYSCREEN)/2 - height/2;
m_hAppWnd = CreateWindow("DXAPPWNDCLASS", m_AppTitle.c_str(), m_WndStyle,
x, y, width, height, NULL, NULL, m_hAppInstance, NULL);
if (!m_hAppWnd)
{
OutputDebugString("\nFAILED TO CREATE WINDOW CLASS !\n");
return false;
}
ShowWindow(m_hAppWnd, SW_SHOW);
return true;
}
bool DXApp::InitDirect3D()
{
UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif // _DEBUG
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE
};
UINT numDriverTypes = ARRAYSIZE(driverTypes);
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
};
UINT numFeatureLevels = ARRAYSIZE(featureLevels);
DXGI_SWAP_CHAIN_DESC swapDesc;
ZeroMemory(&swapDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
swapDesc.BufferCount = 1; //Double buffer 0 = 1, 1 = 2
swapDesc.BufferDesc.Width = m_ClientWidth;
swapDesc.BufferDesc.Height = m_ClientHeight;
swapDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapDesc.BufferDesc.RefreshRate.Numerator = 60;
swapDesc.BufferDesc.RefreshRate.Denominator = 1;
swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapDesc.OutputWindow = m_hAppWnd;
swapDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
swapDesc.Windowed = true;
swapDesc.SampleDesc.Count = 1;
swapDesc.SampleDesc.Quality = 0;
swapDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; //FULLSCREEN CEZ ALT-ENTER
HRESULT result;
for (int i = 0; i < numDriverTypes; ++i)
{
D3D11CreateDeviceAndSwapChain(NULL, driverTypes[i], NULL, createDeviceFlags,
featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &swapDesc, &m_pSwapChain, &m_pDevice,
//1.ERROR-->// &featureLevels, &m_pImmediateContext);
if (SUCCEEDED(result))
{
//2.ERROR-->// m_DriverType = driverTypes[i];
break;
}
}
}
LRESULT DXApp::MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
DXApp.h
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <string>
#include "DXUtil.h"
class DXApp
{
public:
DXApp(HINSTANCE hInstance);
virtual ~DXApp(void);
//MAIN APP LOOP//
int Run();
//FRAMEWORK//
virtual bool Init();
virtual void Update(float dt) = 0;
virtual void Render(float dt) = 0;
virtual LRESULT MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
protected:
//WIN 32 ATTRIBUTES//
HWND m_hAppWnd;
HINSTANCE m_hAppInstance;
UINT m_ClientWidth;
UINT m_ClientHeight;
std::string m_AppTitle;
DWORD m_WndStyle;
//DirectX ATTRIBUTES//
ID3D11Device* m_pDevice;
ID3D11DeviceContext* m_pImmediateContext;
IDXGISwapChain* m_pSwapChain;
ID3D11RenderTargetView* m_pRenderTargetView;
D3D_DRIVER_TYPE* m_DriverType;
D3D_FEATURE_LEVEL* m_FeatureLevel;
D3D11_VIEWPORT* m_Viewport;
protected:
//INIT WIN32 WINDOW//
bool InitWindow();
//INIT DirectX
bool InitDirect3D();
};
DXUtil.h
#pragma once
#include <d3d11.h>
#pragma comment(lib, "d3d11.lib")
namespace Memory
{
template <class T> void SafeDelete(T& t)
{
if (t)
{
delete t;
t = nullptr;
}
}
template <class T> void SafeDeleteArr(T& t)
{
if (t)
{
delete[];
t = nullptr;
}
}
template <class T> void SafeRelease(T& t)
{
if (t)
{
t->Release();
t = nullptr;
}
}
}
winmain.cpp
#include "DXApp.h"
class TestApp : public DXApp
{
public:
TestApp(HINSTANCE hInstance);
~TestApp();
bool Init() override;
void Update(float dt) override;
void Render(float dt) override;
};
TestApp::TestApp(HINSTANCE hInstance) : DXApp(hInstance)
{
}
TestApp::~TestApp()
{
}
bool TestApp::Init()
{
if (!DXApp::Init())
return false;
return true;
}
void TestApp::Update(float dt)
{
}
void TestApp::Render(float dt)
{
}
int WINAPI WinMain(__in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nShowCmd)
{
TestApp tApp(hInstance);
if (!tApp.Init()) return 1;
return tApp.Run();
}
Как я рекомендую проверить некоторые уроки :). В настоящее время я начинаю с кодирования, и я видел это на yt. –