gpt4 book ai didi

c++ - 找不到我的着色器(Obj-C++、ios、opengles2.0)

转载 作者:行者123 更新时间:2023-11-30 04:29:31 25 4
gpt4 key购买 nike

我正在尝试加载我的着色器,但我似乎无法在代码中找到它们。我正在将它们复制到包中,它们就在可执行文件旁边,但我仍然找不到它们。我正在用 C++ 编写渲染代码。

这是主要的包...

Here's the main bundle...

我的代码有望在某一天加载着色器。我现在正试图找到它,这就是为什么什么都没有发生的原因......

void RenderingEngine::ReadShader()
{
char* buffer;
long size;
std::ifstream file;
file.open("Shader.frag");

if (!file.is_open())
{
std::cout << "FILE NOT OPENED!\n";
}
}

最佳答案

如果您使用的是 Objective-C,那么打开文件的标准方式如下:

// get the path to the shader file, without having to duplicate logic about
// how the bundle is laid out from the OS
NSString *pathToShader = [[NSBundle mainBundle] pathForResource:@"Shader"
ofType:@"Frag"];

// load the source from pathToShader by whatever means... probably you'd
// actually get a file URL above and use the relevant NSString method,
// but that's not necessarily helpful here

所以你会明确地让操作系统告诉你你的文件的路径,因为它在主(应用程序)包中。

相反,您似乎假设当前工作目录设置为包内的资源区域(在 iOS 中与可执行文件的路径相同,但在 OS X 上是分开的),我不知道认为在任何地方都是有保证的。

假设你有一些 Objective-C 代码来设置相关的 UIKit 东西,然后再分支到 C++,你可能想要添加如下内容:

[[NSFileManager defaultManager]
changeCurrentDirectoryPath:[[NSBundle mainBundle] resourcePath]];

确定您希望主包将其资源放置在当前工作目录的任何位置。

关于c++ - 找不到我的着色器(Obj-C++、ios、opengles2.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9301340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com