Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Well I've been trying to read a .cso file to use as a shader for a DirectX program I'm currently making.

Problem is no matter how I implemented a way to read the file it never worked. And after fidgeting around I discover that it's only the .cso files I can't read.

I can read anything else (which means it works) even their .hlsl files. Which is strange because the .hlsl (high level shader language) files are supposed to turn into .cso (compiled shader object) files.

What I'm currently doing is:

vector<byte> Read(string File){
    vector<byte> Text;
    fstream file(File, ios::in | ios::ate | ios::binary);

    if(file.is_open()){
        Text.resize(file.tellg());
        file.seekg(0 , ios::beg);
        file.read(reinterpret_cast<char*>(&Text[0]), Text.size());
        file.close();
    }        

    return Text;
};

If I then implement it.

Read("VertexShader.hlsl"); //Works
Read("VertexShader.cso"); //Doesn't Works?!?!

And I need the .cso version of the shader to draw my sexy triangles. Without it my life and application will never continue and I have no idea what could be wrong.

(I've also asked this at stack overflow but still no answers.)

share|improve this question
2  
What do you mean, "doesn't work"? Is the problem with reading the file off disk somehow, or with creating a shader based on the contents of the file? You have to use D3DCompile to compile the HLSL before it can be used, while the .cso is already compiled, so you can pass it directly to CreateVertexShader and friends. –  Nathan Reed May 12 at 1:24
1  
Please don't cross post, only post on the site most appropriate for your question. Please remove one. –  Byte56 May 12 at 2:35
1  
Please stop using "doesn't work"!, please describe what happened and what exactly you want! –  zdd May 12 at 3:19

2 Answers 2

up vote 0 down vote accepted

Depending on how you've set up your project, you likely have your .cso files going to the project output $(OutDir), and your debug working directory set to the project directory $(ProjectDir). As a result, file paths are relative to the project directory. You should change your working directory to the output directory for debugging, and you should be able to load the .cso files.

Working Directory

Note that this will cause loading your .hlsl files to stop working though, unless you copy them to the output directory as well (but you shouldn't need them there if you're compiling at build-time).

share|improve this answer
    
This was it. Guess I'll have to read on relative paths too. –  Jader J Rivera Jun 9 at 23:12

Can be multiple things, don't have access to VS right now to give you exact answer but it can be:

  • VS shader compiler is not attached to your project. Right click on project-> build customization and check the list
  • shader file is not acctually set as shader file. Right click on shader file in your project and make sure it has selected shader type and properties
  • by default VS will compile your hlsl files into cso files before it compiles your main project and put them in //debug or //release, make sure you search in the right directory
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.