当我开始使用 VS2019 本地调试器运行程序时,一切都工作得很好。当我打开 .exe 文件时,我的程序找不到这些文件。我正在尝试从项目存储库文件夹中的 x64/Debug 文件夹启动我的程序。
我的第一个想法是关于路径。我包含了 .PNG 文件的完整路径,但我的程序无论如何都找不到它。
这是我用于加载纹理文件的代码:
Texture texSpecularMap;
if (!texSpecularMap.LoadPNG("assets/textures/container_specular_map.png"))
{
Debug::logWarning("Failed to load texture: assets/textures/container_specular_map.png");
}
bool Texture::LoadPNG(const char* filePath)
{
stbi_set_flip_vertically_on_load(true);
unsigned char* data = stbi_load(filePath, &width, &height, &nChannels, 0);
if (data) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
}
else
{
return false;
}
stbi_image_free(data);
return true;
}
不要看我愚蠢的警告消息。我知道我应该指定一个变量存储路径。
使用 stb_image 加载图像时,stbi_failure_reason() 是你最好的朋友。 您能做的最好的事情就是给出文件的绝对路径。