Search code examples
c++game-enginedirectx-11

C++ File Not Found


Good morning, I am writing a Game Engine with DX11. My problem is that the helper files aren't being found. The path of the executable is C:\Users\aPlutonicCoder\Documents\Visual Studio 2017\Projects\GameEngine\Debug\GraphicsEngine.exe. The path of the helper files is C:\Users\aPlutonicCoder\Documents\Visual Studio 2017\Projects\GameEngine\Debug\Color Files\color.ps and C:\Users\aPlutonicCoder\Documents\Visual Studio 2017\Projects\GameEngine\Debug\Color Files\color.vs. The relevant code is:

    bool ColorShaderclass::InitializeShader(ID3D11Device* deviceContext, HWND hwnd, LPCSTR vsFileName, LPCSTR psFileName)
{
    HRESULT hresult;
    ID3DBlob* errorMessage;
    ID3DBlob* vertexShaderBuffer;
    ID3DBlob* pixelShaderBuffer;
    D3D11_INPUT_ELEMENT_DESC polygonLayout[2];
    unsigned int noElements;
    D3D11_BUFFER_DESC matrixBufferDesc;

    errorMessage = 0;
    vertexShaderBuffer = 0;
    pixelShaderBuffer = 0;

    hresult = D3DX11CompileFromFile(vsFileName, NULL, NULL, "ColorVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &vertexShaderBuffer, &errorMessage, NULL);

    if (FAILED(hresult))
    {
        if (errorMessage)
            OutputShaderErrorMessage(errorMessage, hwnd, vsFileName);
        else
            MessageBox(hwnd, vsFileName, "Missing Shader File", MB_OK);

        return false;
    }


    hresult = D3DX11CompileFromFile(psFileName, NULL, NULL, "ColorPixelShader", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &pixelShaderBuffer, &errorMessage, NULL);

    if (FAILED(hresult))
    {
        if(errorMessage)
            OutputShaderErrorMessage(errorMessage, hwnd, psFileName);
        else
            MessageBox(hwnd, vsFileName, "Missing Shader File", MB_OK);

        return false;
    }

bool ColorShaderclass::Initialize(ID3D11Device* device, HWND hwnd)
{
    return InitializeShader(device, hwnd, ".../Color Files/color.vs", ".../Color Files/color.ps");
}

Please help me. The files are there and they exist, but the messagebox pops up. Thank you in advance


Solution

  • You could try this:

    InitializeShader(device, hwnd, Path::GetFullPath("Color Files/color.vs"), Path::GetFullPath("Color Files/color.ps"));