<分区>
我想让opengl读取着色器文件并在主cpp中使用它
我尝试了 thechernoproject channel 的教程,但是有问题
struct ShaderProgramSource
{
std::string VertexSource;
std::string FragmentSource;
};
static ShaderProgramSource ParseShader(const std::string& filepath) {
std::fstream stream(filepath);
enum class ShaderType {
NONE = -1, VERTEX = 0, FRAGMENT = 1
};
std::string line;
std::stringstream ss[2];
ShaderType type = ShaderType::NONE;
while (getline(stream, line))
{
if (line.find("#shader") != std::string::npos) {
if (line.find("vertex") != std::string::npos) {
ShaderType type = ShaderType::VERTEX;
}
else if (line.find("fragment") != std::string::npos) {
ShaderType type = ShaderType::FRAGMENT;
}
}
else
{
ss[int(type)] << line << '\n';
}
}
return{ ss[0].str(), ss[1].str() };
}
我希望它能工作,但它没有显示它正在获取文件