尝试检索directX的效果文件时遇到问题。如果我不包含D3DX10CreateEffectFromFile()方法,则应用程序将正确编译。如果我确实包含它。我收到以下错误
1>GXDX.obj : error LNK2019: unresolved external symbol _D3DX10CreateEffectFromFileW@48 referenced in function "public: virtual void __thiscall GXDX::StartUp(struct HWND__ * *,int,int)" (?StartUp@GXDX@@UAEXPAPAUHWND__@@HH@Z)
1>C:\Users\numerical25\Desktop\Intro ToDirectX\GODFILES\GXRenderManager\GXRenderManager\Debug\GXRenderManager.exe : fatal error LNK1120: 1 unresolved externals
我的第一个想法是,它可能没有正确链接directx库。但我发现,因为我包括lib文件,我正在使用其他方法没有问题。下面是我的代码。
#ifndef GXDX_
#define GXDX_
#include "GXRenderer.h"
#include <d3d10.h>
#include <d3dx10.h>
#include "GXExceptions.h"
#pragma comment (lib, "d3d10.lib")
#pragma comment (lib, "d3dx10.lib")
class GXDX: public GXRenderer {
protected:
ID3D10Device* gm_dxDevice;
IDXGISwapChain* gm_swapChain;
ID3D10RenderTargetView* gm_renderTargetView;
ID3D10Effect *gm_shader;
ID3D10EffectTechnique *gm_tech;
public:
void CleanUp();
void StartUp(HWND* window,int w, int h);
void SetupScene();
void DisplayScene();
void LoadMesh(GXVector*,UINT*);
void DrawText(LPSTR);
};
#endif
以下是实施
void GXDX::StartUp(HWND* mainWindow,int w, int h)
{
width = w;
height = h;
this->m_mainWindow = mainWindow;
//Get size of window
RECT rectangle;
GetClientRect(*m_mainWindow,&rectangle);
ID3D10Texture2D *backBufferSurface;
DXGI_SWAP_CHAIN_DESC swapChainDesc;
SecureZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
swapChainDesc.BufferCount = 2;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.OutputWindow = *mainWindow;
swapChainDesc.Windowed = TRUE;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
D3D10_DRIVER_TYPE driverType = D3D10_DRIVER_TYPE_HARDWARE;
HRESULT hr = D3D10CreateDeviceAndSwapChain(NULL,driverType,NULL,0,
D3D10_SDK_VERSION, &swapChainDesc,&gm_swapChain,&gm_dxDevice);
if(FAILED(hr))
throw GXVideoException(L"Problems retrieving directX device");
hr = gm_swapChain->GetBuffer(0,__uuidof(ID3D10Texture2D), (LPVOID*)&backBufferSurface);
if(FAILED(hr))
throw GXVideoException(L"Failure to retrieve buffer from swap chain");
hr = gm_dxDevice->CreateRenderTargetView(backBufferSurface, NULL,&gm_renderTargetView);
backBufferSurface->Release();
if(FAILED(hr))
throw GXVideoException(L"Failure to create Render Target View");
//In the future, you might want to change this to something that allows multiple views
//Like for an editor
gm_dxDevice->OMSetRenderTargets(1, &gm_renderTargetView, NULL);
UINT rectangle_width = rectangle.right - rectangle.left;
UINT rectangle_height = rectangle.bottom - rectangle.top;
D3D10_VIEWPORT viewport;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = rectangle_width;
viewport.Height = rectangle_height;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
//bind viewport
gm_dxDevice->RSSetViewports(1,&viewport);
D3D10_INPUT_ELEMENT_DESC layout[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA},
};
hr = D3DX10CreateEffectFromFile(L"shader.fx", NULL, NULL,
"fx_4_0",D3D10_SHADER_DEBUG,0,gm_dxDevice,NULL,NULL, &gm_shader,NULL,NULL);// Error here and dont know why
}
答案 0 :(得分:0)
喜欢链接器错误。我目前大多使用DX9,但我记得DX11开沟效果(但仍然可以使用)。但是,DX10应该仍然拥有它们。通过d3dx10async.h查看显示CompileEffectFromFile仍在那里(2010年6月sdk)。我注意到D3DX10CompileEffectFromFile在MSDN中被列为已弃用,其中D3DX10CompileFromFile是其替代品。仔细检查您的库链接并尝试给D3DX10CompileFromFile函数一个镜头(虽然理论上如果CompileEffect func仍然完全存在并且库正确链接它应该工作)。
答案 1 :(得分:0)
我想问题是我在解决方案选项区域中没有提供附加lib目录中提供的lib路径。我应该知道,但它让我失望,因为我在此问题之前调用的任何其他方法都运行良好。