• Create Account

### #Actualrip-off

Posted 28 December 2012 - 02:17 PM

As the others have mentioned, you really have (at least) two distinct problems here. The first is loading the file contents into memory, and the second relates to loading and applying shaders. You should approach these as different problems, and solve and test them in isolation.

As others have demonstrated, use a hard coded string literal to test your shader code.

Likewise, write a small program to demonstrate and test file loading. For example, you can load a file into a string fairly simply using streambuf iterators:
#include <string>
#include <iterator>
#include <fstream>
#include <iostream>

std::istreambuf_iterator<char> begin(stream);
std::istreambuf_iterator<char> end;
return std::string(begin, end);
}

int main() {
if(in) {
std::cout << "The file contents are:\n";
std::cout << data;
} else {
std::cerr << "Failed to open the file" << std::endl;
return 1;

}
}

It is also possible to make read() a one liner, but it falls afoul of the most vexing parse.

Once you've verified that you can load strings correctly, and that you can create and use shaders correctly, then is the time to create a program that does both. Breaking a complex task into simpler sub-tasks is called "divide and conquer" and is absolutely necessary for writing functioning and maintainable software.

### #1rip-off

Posted 28 December 2012 - 02:16 PM

As the others have mentioned, you really have (at least) two distinct problems here. The first is loading the file contents into memory, and the second relates to loading and applying shaders. You should approach these as different problems, and solve and test them in isolation.

As others have demonstrated, use a hard coded string literal to test your shader code.

Likewise, write a small program to demonstrate and test file loading. For example, you can load a file into a string fairly simply using streambuf iterators:


</p><div>#include <string></div>
<div>#include <iterator></div>
<div>#include <fstream></div>
<div>#include <iostream></div>
<div> </div>
<div>    std::istreambuf_iterator<char> begin(stream);</div>
<div>    std::istreambuf_iterator<char> end;</div>
<div>    return std::string(begin, end);</div>
<div>}</div>
<div> </div>
<div>int main() {</div>
<div>    if(in) {</div>
<div>         std::cout << "The file contents are:\n";</div>
<div>         std::cout << data;</div>
<div>    } else {</div>
<div>        std::cerr << "Failed to open the file" << std::endl;</div>
<div>        return 1;</div>
<div> </div>
<div>    }</div>
<div>}</div>

It is also possible to make read() a one liner, but it falls afoul of the most vexing parse.

Once you've verified that you can load strings correctly, and that you can create and use shaders correctly, then is the time to create a program that does both. Breaking a complex task into simpler sub-tasks is called "divide and conquer" and is absolutely necessary for writing functioning and maintainable software.

PARTNERS