[C++] Engine Work
So I am working on my engine finally (I'm hoping I can get it sorted before tomorrow night). There may be a few questions over the next day or two, I am just not completely accustomed to C++ yet like I used to be (it seems).
~~//~~
The first error I am pulling up is:
Error LNK2019 unresolved external symbol _CreateDXGIFactory@8 referenced in function "public: bool __thiscall DXManager::Initialize(int,int,bool,struct HWND__ * *,bool)" (?Initialize@DXManager@@QAE_NHH_NPAPAUHWND__@@0@Z) edg3 Engine Proto C:\Ernest\Gamedev\Engine Proto\1. DirectX Engine Proto\edg3 Engine Proto\edg3 Engine Proto\edg3 Engine Proto\DXManager.obj
~~//~~
h:
cpp:
The initial work should be compiling but I can't even compile this (it has been shown it works like this in VS2010 however I'm using 2017
Sorry if quotes arent working, have to be afk for a few hours.
~~//~~
The first error I am pulling up is:
Error LNK2019 unresolved external symbol _CreateDXGIFactory@8 referenced in function "public: bool __thiscall DXManager::Initialize(int,int,bool,struct HWND__ * *,bool)" (?Initialize@DXManager@@QAE_NHH_NPAPAUHWND__@@0@Z) edg3 Engine Proto C:\Ernest\Gamedev\Engine Proto\1. DirectX Engine Proto\edg3 Engine Proto\edg3 Engine Proto\edg3 Engine Proto\DXManager.obj
~~//~~
h:
~~//~~#ifndef _DX_MANAGER_H
#define _DX_MANAGER_H
#include <DXGI.h>
#include <D3Dcommon.h>
#include <D3D11.h>
class DXManager
{
public:
DXManager();
~DXManager();
bool Initialize(int screenWidth, int screenHeight, bool vsync, HWND* hwnd, bool fullscreen);
void BeginScene(float r, float g, float b, float a);
void EndScene();
void EnableAlphaBlending(bool enable);
void EnableZBuffer(bool enable);
ID3D11Device* GetDevice();
ID3D11DeviceContext* GetDeviceContext();
private:
bool InitializeSwapChain(HWND* hwnd, bool fullscreen, int screenWidth, int screenHeight, unsigned int numerator, unsigned int denom);
bool InitializeDepthBuffer(int screenWidth, int screenHeight);
bool InitializeDepthStencilBuffer();
bool InitializeStencilView();
bool InitializeRasterizerState();
bool InitializeViewpoer(int screenWifth, int screenHeight);
bool InitializeAlphaBlending();
bool InitializeZBuffer();
bool m_vsync_enabled;
int m_videoCardMemory;
char* m_videoCardDescription[128];
IDXGISwapChain* m_swapChain;
ID3D11Device* m_device;
ID3D11DeviceContext* m_deviceContext;
ID3D11RenderTargetView* m_renderTargetView;
ID3D11Texture2D* m_depthStencilBuffer;
ID3D11DepthStencilState* m_depthStencilState;
ID3D11DepthStencilView* m_depthStencilView;
ID3D11RasterizerState* m_rasterState;
ID3D11BlendState* m_alphaEnableBlendingState;
ID3D10BlendState* m_alphaDisabledBlendingState;
ID3D11DepthStencilState* m_depthDisabledStencilState;
};
#endif
cpp:
~~//~~#include "DXManager.h"
DXManager::DXManager()
{
m_swapChain = 0;
m_device = 0;
m_deviceContext = 0;
m_renderTargetView = 0;
m_depthStencilBuffer = 0;
m_depthStencilState = 0;
m_depthStencilView = 0;
m_rasterState = 0;
m_alphaEnableBlendingState = 0;
m_alphaDisabledBlendingState = 0;
m_depthDisabledStencilState = 0;
}
DXManager::~DXManager()
{
// Removes fullscreen, prevents exceptions
if (m_swapChain)
m_swapChain->SetFullscreenState(false, NULL);
if (m_alphaEnableBlendingState)
{
m_alphaEnableBlendingState->Release();
m_alphaEnableBlendingState = 0;
}
if (m_alphaDisabledBlendingState)
{
m_alphaDisabledBlendingState->Release();
m_alphaDisabledBlendingState = 0;
}
if (m_depthDisabledStencilState)
{
m_depthDisabledStencilState->Release();
m_depthDisabledStencilState = 0;
}
if (m_rasterState)
{
m_rasterState->Release();
m_rasterState = 0;
}
if (m_depthStencilView)
{
m_depthStencilView->Release();
m_depthStencilView = 0;
}
if (m_depthStencilState)
{
m_depthStencilState->Release();
m_depthStencilState = 0;
}
if (m_depthStencilBuffer)
{
m_depthStencilBuffer->Release();
m_depthStencilBuffer = 0;
}
if (m_renderTargetView)
{
m_renderTargetView->Release();
m_renderTargetView = 0;
}
if (m_deviceContext)
{
m_deviceContext->Release();
m_deviceContext = 0;
}
if (m_device)
{
m_device->Release();
m_device = 0;
}
if (m_swapChain)
{
m_swapChain->Release();
m_swapChain = 0;
}
}
bool DXManager::Initialize(int screenWidth, int screenHeight, bool vsync, HWND* hwnd, bool fullscreen)
{
HRESULT result;
IDXGIFactory* factory;
IDXGIAdapter* adapter;
IDXGIOutput* adapterOutput;
unsigned int numNodes, numerator = 0, denominator = 0, stringLength;
DXGI_MODE_DESC* displayModeList;
DXGI_ADAPTER_DESC adapterDesc;
int error;
ID3D11Texture2D* backBufferPtr;
char m_videoCardDescription[128];
// Store vsync settings
m_vsync_enabled = vsync;
// Create DirectX graphics interface
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(result))
{
return false;
}
// Use the factory we created on top to create an adapter
result = factory->EnumAdapters(0, &adapter);
if (FAILED(result))
{
return false;
}
// Enumerate the primary adapter output
result = adapter->EnumOutputs(0, &adapterOutput);
if (FAILED(result))
{
return false;
}
// Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNIFORM for output adapter
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numNodes, NULL);
if (FAILED(result))
{
return false;
}
// Create list to hold all possible modes for this monitor/vid card combo
displayModeList = new DXGI_MODE_DESC[numNodes];
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numNodes, displayModeList);
if (FAILED(result))
{
return false;
}
// Loop through to see what screen width height fits
for (int i = 0; i < (int)numNodes; i++)
{
if (displayModeList[i].Width == (unsigned int)screenWidth)
if (displayModeList[i].Height == (unsigned int)screenHeight)
{
numerator = displayModeList[i].RefreshRate.Numerator;
denominator = displayModeList[i].RefreshRate.Denominator;
i = numNodes; // potential error Ernest
}
}
if (numerator == 0 && denominator == 0)
{
return false;
}
//get adapter desc
result = adapter->GetDesc(&adapterDesc);
if (FAILED(result))
{
return false;
}
// Store dedicated video memory in mb
m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
// Convert name of vid card to char array
error = wcstombs_s(&stringLength, m_videoCardDescription, 128, adapterDesc.Description, 128);
if (FAILED(error))
{
return false;
}
// Release memory use
delete[] displayModeList;
displayModeList = 0;
adapterOutput->Release();
adapterOutput = 0;
adapter->Release();
adapter = 0;
factory->Release();
factory = 0;
if (!InitializeSwapChain(hwnd, fullscreen, screenWidth, screenHeight, numerator, denominator))
{
return false;
}
return true;
}
void DXManager::BeginScene(float r, float g, float b, float a)
{
}
void DXManager::EndScene()
{
}
void DXManager::EnableAlphaBlending(bool enable)
{
}
void DXManager::EnableZBuffer(bool enable)
{
}
ID3D11Device* DXManager::GetDevice()
{
return NULL;
}
ID3D11DeviceContext* DXManager::GetDeviceContext()
{
return NULL;
}
bool DXManager::InitializeSwapChain(HWND* hwnd, bool fullscreen, int screenWidth, int screenHeight, unsigned int numerator, unsigned int denom)
{
DXGI_SWAP_CHAIN_DESC swapChainDesc;
D3D_FEATURE_LEVEL featureLevel;
HRESULT result;
// Init
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
// Single back buffer
swapChainDesc.BufferCount = 1;
// Set withs and hight
swapChainDesc.BufferDesc.Width = screenWidth;
swapChainDesc.BufferDesc.Height = screenHeight;
// 32 bit back buffer
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
// Set refresh rate
if (m_vsync_enabled)
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
swapChainDesc.BufferDesc.RefreshRate.Denominator = denom;
}
else
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
}
// set usage of the back buffer
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
// set window handle
swapChainDesc.OutputWindow = (HWND)hwnd;
// Turn multi-sampling off
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
// Set fullscreen/window
swapChainDesc.Windowed = fullscreen;
//set the scan line order and scale to unspec
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
// discard back buffer contents after presenting
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
swapChainDesc.Flags = 0;
// Set feature level to DX11
featureLevel = D3D_FEATURE_LEVEL_11_0;
// Create chain
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);
if (FAILED(result))
{
return false;
}
return true;
}
bool DXManager::InitializeDepthBuffer(int screenWidth, int screenHeight)
{
return true;
}
bool DXManager::InitializeDepthStencilBuffer()
{
return true;
}
bool DXManager::InitializeStencilView()
{
return true;
}
bool DXManager::InitializeRasterizerState()
{
return true;
}
bool DXManager::InitializeViewpoer(int screenWifth, int screenHeight)
{
return true;
}
bool DXManager::InitializeAlphaBlending()
{
return true;
}
bool DXManager::InitializeZBuffer()
{
return true;
}
The initial work should be compiling but I can't even compile this (it has been shown it works like this in VS2010 however I'm using 2017
Sorry if quotes arent working, have to be afk for a few hours.
Comments
In your project settings, make sure the directory where DXGI.dll AND DXGI.lib is located, is in the list of directories.
You may also need to put the following line in you implementation:
Let met know how it goes.
Executable: $(DXSDK_DIR)Utilities\bin\x86
Include Directories: $(DXSDK_DIR)Include
Library Directories: $(DXSDK_DIR)Lib\x86
Shouldn't the DXGI lib and dll also be there? (No idea where DXSDK refers to, Windows search is roughly not working unfortunately)
I had to do this to compile a DX application since VS 2017 didn't have the required DX references. I can't find DXGI.lib or .dll currently using my Windows search. Unfortunately, the latest update changes it so I nearly can't find anything with Win search...
~~//~~
EDIT: Thought about it and remember in the past I had to use Nuget to get this to work, the only option is SharpDX.DXGI but it doesnt work on my project targets preferences: ~~//~~
Second EDIT: Found it was "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)" however the references arent necessarily wrong at all (using DXSDK). Adding each of the folders as references still shares that apparently SXGI doesnt exist (have the cpp and h files and read through them, theyre in the above folders)
~~//~~
Third edit: damn, thanks - realised after direct folder references I should try the #pragma again and it works now.