file.open()找不到文件、c++、Xcode、OpenGL
file.open() not finding file, c++, Xcode, OpenGL
我已经试了一整天了,但没有找到有效的答案。我正在尝试在我的opengl程序中加载着色器,然而,该程序似乎无法找到文件。如有任何帮助,我们将不胜感激。这是代码
#include "Shader.hpp"
#include <fstream>
#include <iostream>
static std::string loadShader(const std::string& filename);
static void checkShaderError(GLuint shader, GLuint flag, bool isProgram, const std::string& errMessage);
static GLuint createShader(const std::string& text, GLenum shaderType);
Shader::Shader(const std::string& filename){
m_program = glCreateProgram();
m_shaders[0] = createShader(loadShader(filename + ".vs"), GL_VERTEX_SHADER);
m_shaders[1] = createShader(loadShader(filename +".fs"), GL_FRAGMENT_SHADER);
for(unsigned int i = 0; i < NUM_SHADERS; i++ ){
glAttachShader(m_program, m_shaders[i]);
}
glBindAttribLocation(m_program, 0, "position");
glLinkProgram(m_program);
checkShaderError(m_program, GL_LINK_STATUS, true, "Error: Program failed to link!");
glValidateProgram(m_program);
checkShaderError(m_program, GL_VALIDATE_STATUS, true, "Error: Program is invalid!");
}
Shader::~Shader(){
for(int i = 0; i < NUM_SHADERS; i++)
{
glDetachShader(m_program, m_shaders[i]);
glDeleteShader(m_shaders[i]);
}
glDeleteProgram(m_program);
}
static std::string loadShader(const std::string& filename){
std::ifstream file;
file.open((filename).c_str());
std::string output;
std::string line;
if(file.is_open()){
while(file.good()){
getline(file, line);
output.append(line + "n");
}
}else{
std::cerr << "Shader could not be loaded, shader id: " << filename << std::endl;
}
file.close();
return output;
}
我遇到了完全相同的问题。完全重新生成项目,然后尝试再次运行。
编辑:更改代码中的文件路径有一种奇怪的行为。我个人总是需要重建文件来解决这个问题。
相关文章:
- ld:bind_at_load和-bitcode_bundle(Xcode设置ENABLE_bitcode=YES)不能
- 在没有Xcode的情况下在Mac捆绑包中嵌入框架
- Xcode 语义问题引用或以前定义的代码
- 使用 Xcode 将双精度存储在数组C++中
- Xcode 9.4.1 中的 Apple Mach-O 链接器 (id) 错误
- 各种版本的 Mac OSX 向后兼容性如何?(Xcode C++
- MacOS 上的 Xcode 11 项目不在一个函数中使用 sin 和 cos:未定义的符号"___sincosf_stret"
- macOS 是内置在 clang 编译器中还是内置于 xcode ide 中?
- Qt - 从XCode上传到MacOS AppStore
- 在 xcode 10 上找不到 stdlibc++ 标头错误
- cmake add_custom_command + Xcode:多输出 = 多命令调用
- 在 xcode 上使用 stdlib.h
- 我可以在没有Xcode的情况下在Mac上使用带有C++的虚幻引擎吗?
- 为什么不支持 Xcode 1.5?
- C++ Xcode 9 - 无法从 Cimg 调用函数 display()
- Xcode 中的加速框架以获得 A 的 QR 分解,但找不到 zgeqrf
- 如何将 PhysX 库与 Xcode 链接
- Xcode Test Navigator 如何在纯C++项目中显示 Google 测试
- 适用于 macOS 的 Xcode 应用程序。这就是我设置从USB麦克风输入获取音频的方式。一年前工作,现在没有了。为什么
- Xcode 添加新库