如何在 OS X 10.5 上使用 SDL 和 Xcode 加载图像?
编辑:在toastie的建议下使用bmp后,我在加载图像时仍然遇到问题:
我正在将SDL和OpenGL与Xcode一起使用,并且我正在尝试加载图像以用作立方体上的纹理。 该图像是 256x256 RBG jpeg。 该图像与我的所有源代码位于同一目录中,并且位于 Xcode 项目中的 Resources 文件夹下。 该文件名为texture.bmp,
if (textureSurface = SDL_LoadBMP("texture.bmp"))
{
// ...
}
else printf("%s", SDL_GetError());
我继续运行它并收到控制台错误:无法打开texture.bmp
在这些条件下加载文件的路径或正确语法是什么?
Edit: After using a bmp at toastie's suggestion, I'm still having problems loading the image:
I'm using SDL and OpenGL with Xcode and I'm trying to load an image to use as a texture on a cube. The image is a 256x256 RBG jpeg. The image is in the same directory as all of my source code, and it's under the Resources folder in the Xcode project. The file is named texture.bmp
if (textureSurface = SDL_LoadBMP("texture.bmp"))
{
// ...
}
else printf("%s", SDL_GetError());
I keep running it and getting the console error: Couldn't open texture.bmp
What is the path, or proper syntax for loading a file under these conditions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
SDL_LoadBMP 仅加载 BMP 文件,正如其名称所示:)
您将需要另一个库来加载其他图像格式。
尝试SDL_image:
http://www.libsdl.org/projects/SDL_image/
或 DevIL:
http://openil.sourceforge.net/
或者推出您自己的加载程序:
http://www.libpng.org/pub/png/libpng.html
SDL_LoadBMP only loads BMP files as its name would suggest :)
You will need another library to load other image formats.
Try SDL_image:
http://www.libsdl.org/projects/SDL_image/
or DevIL:
http://openil.sourceforge.net/
Or roll your own loader:
http://www.libpng.org/pub/png/libpng.html
我面前没有 Xcode,但我认为如果您右键/选择单击资源列表中的文件以获取文件的首选项,您可以将其设置为相对于项目、包含目录等。
I don't have Xcode in front of me, but I think if you right/option click on the file in your resources listing to get at the preferences for the file you can set it to be relative to the project, containing directory, etc.
在此处找到了答案。 本质上,图像路径是相对于正在运行的应用程序的,因此我必须移动图像或使路径相对于调试版本。
Found the answer here. Essentially the image path is relative to the application being run, so I had to move the image or make the path relative to the debug build.