gpt4 book ai didi

c++ - 无法检索 effect.fx 文件

转载 作者:太空宇宙 更新时间:2023-11-04 04:58:05 25 4
gpt4 key购买 nike

我在从 directx 加载 effect.fx 时遇到问题。当我进入我的应用程序时,我的 ID3D10Effect *m_pDefaultEffect;指针保持为空。地址保持在 0x000000

下面是我的代码

#pragma once
#include "stdafx.h"
#include "resource.h"
#include "d3d10.h"
#include "d3dx10.h"
#include "dinput.h"


#define MAX_LOADSTRING 100

class RenderEngine {
protected:

RECT m_screenRect;

//direct3d Members
ID3D10Device *m_pDevice; // The IDirect3DDevice10
// interface
ID3D10Texture2D *m_pBackBuffer; // Pointer to the back buffer
ID3D10RenderTargetView *m_pRenderTargetView; // Pointer to render target view
IDXGISwapChain *m_pSwapChain; // Pointer to the swap chain
RECT m_rcScreenRect; // The dimensions of the screen

ID3D10Texture2D *m_pDepthStencilBuffer;
ID3D10DepthStencilState *m_pDepthStencilState;
ID3D10DepthStencilView *m_pDepthStencilView;

//transformation matrixs
D3DXMATRIX g_mtxWorld;
D3DXMATRIX g_mtxView;
D3DXMATRIX g_mtxProj;

//Effect members
ID3D10Effect *m_pDefaultEffect;
ID3D10EffectTechnique *m_pDefaultTechnique;

ID3DX10Font *m_pFont; // The font used for rendering text
// Sprites used to hold font characters
ID3DX10Sprite *m_pFontSprite;

ATOM RegisterEngineClass();
void DoFrame(float);
bool LoadEffects();

public:
static HINSTANCE m_hInst;
HWND m_hWnd;
int m_nCmdShow;
TCHAR m_szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR m_szWindowClass[MAX_LOADSTRING]; // the main window class name

void DrawTextString(int x, int y, D3DXCOLOR color, const TCHAR *strOutput);

//static functions
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
static INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);

bool InitWindow();
bool InitDirectX();
bool InitInstance();
int Run();
void ShutDown();

RenderEngine()
{
m_screenRect.right = 800;
m_screenRect.bottom = 600;
}

};

下面是实现

bool RenderEngine::LoadEffects()
{
HRESULT hr;

ID3D10Blob *pErrors = 0;
// Create the default rendering effect
LPCWSTR effectFilename = L"effect.fx";

hr = D3DX10CreateEffectFromFile(effectFilename, NULL, NULL,
"fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, m_pDevice, NULL, NULL, &m_pDefaultEffect,
&pErrors, NULL);


if(pErrors)// at this point, m_pDefaultEffect is still empty but pErrors returns data which means there is
{//errors
return false; //ends here
}

//m_pDefaultTechnique = m_pDefaultEffect->GetTechniqueByName("DefaultTechnique");

return true;
}

我的 directx 设备可以正常工作。我的 effect.fx 文件与我的解决方案文件(.cpp 和头文件)位于同一文件夹中

alt text

[编辑]

alt text

我也试过将 effect.fx 放在与可执行文件相同的文件夹中

我一直在摆弄一些其他可用的代码。我不知道这一点,但似乎 .fx 文件的布局会影响我是否成功上传文件。所以我也提供了我的效果代码

matrix g_mtxWorld;
matrix g_mtxView;
matrix g_mtxProj;

#define MAX_LIGHTS 10 // Ensure this is the same as the C++ value

int4 g_viLightStatus;
float4 g_vLightColors[MAX_LIGHTS];
float4 g_vLightDirections[MAX_LIGHTS];

struct VS_INPUT
{
float3 vPosition : POSITION;
float3 vNormal : NORMAL;
float4 vColor : COLOR0;
float2 vTexCoords : TEXCOORD;
};

struct VS_OUTPUT
{
float4 vPosition : SV_POSITION;
float3 vNormal : NORMAL;
float4 vColor : COLOR0;
};

VS_OUTPUT DefaultVS(VS_INPUT dataIn)
{
VS_OUTPUT result;

float4 vPos = float4(dataIn.vPosition, 1.0f);
float4 vFinalPos = mul(vPos, g_mtxWorld);
vFinalPos = mul(vFinalPos, g_mtxView);
vFinalPos = mul(vFinalPos, g_mtxProj);
result.vPosition = vFinalPos;
result.vNormal = float3(0,0,0);
result.vColor = float4(1,0,0,0);
return result;
}

float4 DefaultPS(VS_OUTPUT dataIn) : SV_Target
{
return dataIn.vColor;
}

technique10 DefaultTechnique
{
pass Pass0
{
SetGeometryShader(NULL);
SetVertexShader(CompileShader(vs_4_0, VS()));
SetPixelShader(CompileShader(ps_4_0, PS()));
}
}

最佳答案

想通了

SetVertexShader(CompileShader(vs_4_0, VS()));
SetPixelShader(CompileShader(ps_4_0, PS()));

应该是

SetVertexShader(CompileShader(vs_4_0, DefaultVS()));
SetPixelShader(CompileShader(ps_4_0, DefaultPS()));

结果。错误的 HLSL 代码可能导致 D3DX10CreateEffectFromFile 失败。

关于c++ - 无法检索 effect.fx 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2894007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com