D3DX11CompileFromFile doesn't work
Started by proanim, Oct 15 2012 02:24 PM
12 replies to this topic
#1 Members - Reputation: 392
Posted 15 October 2012 - 02:24 PM
I have been trying to make simple colored triangle, and everyting worked fine until i got to the point render a triangle with color shader. Why is it that D3DX11CompileFromFile function can't find the shader file even if it is placed in the project and in same folder as the exe file.
The program compiles without any errors or warning.
Also why is it that half of the program is messed up with LPCSTR and LPCWSTR conflicts when using #define UNICODE?
The program compiles without any errors or warning.
Also why is it that half of the program is messed up with LPCSTR and LPCWSTR conflicts when using #define UNICODE?
Sponsor:
#2 Moderators - Reputation: 5487
Posted 15 October 2012 - 02:41 PM
When you debug in Visual Studio, the working directory is set to the directory that the project is in. So if you're not going to use an absolute path to your shader file, you need to place the shader file in the same directory as the project. Are you sure your problem is that it can't find the file?
As for UNICODE, are you defining that manually? Usually you set this in the project properties instead of defining the macro yourself.
As for UNICODE, are you defining that manually? Usually you set this in the project properties instead of defining the macro yourself.
#4 Crossbones+ - Reputation: 5187
Posted 15 October 2012 - 03:44 PM
Again, set the Unicode character set in the project options, don’t define it manually.
Right-click your project -> Properties -> Configuration Properties -> General -> Character Set -> Use Unicode Character Set.
L. Spiro
Right-click your project -> Properties -> Configuration Properties -> General -> Character Set -> Use Unicode Character Set.
L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#6 Crossbones+ - Reputation: 5187
Posted 15 October 2012 - 11:18 PM
They are not the same. Once is scalable and reliable and one is not.i just did that, it is the same thing as #define UNICODE. In both cases i need to change LPCSTR to LPCWSTR
And yes, you need to change LPCSTR to LPCWSTR.
I am not sure why you are confused on this.
One is a char and one is a wchar_t. They are not the same type, and cannot be used interchangeably. By using UNICODE you have specified that you want to use wchar_t, so if you have any char’s being passed to those functions you will need to change them to wchar_t (or LPCWCHAR in your case), so what is the problem?
L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#7 Members - Reputation: 392
Posted 16 October 2012 - 07:59 AM
ok i understand UNICODE now, at this point i can change everything in my program, but i still don't see why D3DX11CompileFromFile or in this case D3DX11CompileFromFileW can't find the file even with absolute path. What can cause this to happen?
#9 Members - Reputation: 392
Posted 16 October 2012 - 10:20 AM
i think i tried every combination like:
L"color.hlsl" (and without L)
L"../shaders/color.hlsl" (and without L)
L"C:\\Documents and Settings\\...." (and without L)
L"C:/Documents and Settings/..." (and without L)
error is always the same if file is not found return file path like this:
[source lang="cpp"]// compile the vertex shader code result = D3DX11CompileFromFileW(ShaderFileName, NULL, NULL, "ColorVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &vertexShaderBuffer, &errorMessage, NULL); if(FAILED(result)) { // if the shader failed to compile it should have writen something to the error message if(errorMessage) OutputShaderErrorMessage(errorMessage, hwnd, ShaderFileName); // if there was nothing in the error message then // it simply could not find the shader file itself else MessageBoxW(hwnd, ShaderFileName, L"Missing Shader File", MB_OK); return false; }[/source]
L"color.hlsl" (and without L)
L"../shaders/color.hlsl" (and without L)
L"C:\\Documents and Settings\\...." (and without L)
L"C:/Documents and Settings/..." (and without L)
error is always the same if file is not found return file path like this:
[source lang="cpp"]// compile the vertex shader code result = D3DX11CompileFromFileW(ShaderFileName, NULL, NULL, "ColorVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &vertexShaderBuffer, &errorMessage, NULL); if(FAILED(result)) { // if the shader failed to compile it should have writen something to the error message if(errorMessage) OutputShaderErrorMessage(errorMessage, hwnd, ShaderFileName); // if there was nothing in the error message then // it simply could not find the shader file itself else MessageBoxW(hwnd, ShaderFileName, L"Missing Shader File", MB_OK); return false; }[/source]
#10 Crossbones+ - Reputation: 5187
Posted 16 October 2012 - 11:32 AM
Why not post the actual path of the shader?
And I mean via copy-and-paste.
Browse to the shader file, right-click it, select Properties, and copy/past the path.
Then add \ and select the file itself. Hit F2 and copy/paste.
Show result here.
L. Spiro
And I mean via copy-and-paste.
Browse to the shader file, right-click it, select Properties, and copy/past the path.
Then add \ and select the file itself. Hit F2 and copy/paste.
Show result here.
L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#13 Members - Reputation: 392
Posted 18 October 2012 - 10:11 AM
Well i found a solution, since i had .NET framework 4.5 installed, i found on the internet that it causes problems with visual studio 2010. So i uninstalled it. and reinstalled visual studio 2010 from maintanance option since it couldn't start any other way. This seems to solve every issue with the shader i had.






