通过资源文件获取opengl的纹理图片(c++/visual studio 2008)

发布于 2024-10-03 05:47:21 字数 200 浏览 0 评论 0原文

当您在 Visual Studio 2008 中创建一个新的 opengl 项目时,您会得到三个文件夹:一个用于头文件,一个用于源文件,一个用于资源文件。

将jpg图片放在资源文件中然后链接到它以将其加载为纹理是否可行? 我想加载 jpg 图片作为纹理,但我想通过资源文件来做到这一点,以便调试 exe 包含这些文件。

如何链接到我放入资源文件中的图片?

when you create a new opengl project in visual studio 2008, you get three folders: one for header files, one for source files and one for resource files.

Is it feasible to put a jpg picture in resource files and then link to it to load it as a texture?
i want to load jpg pictures as textures, but i want to do that through resource files so that the debug exe contains those files.

how can i link to the pictures that i put in resource files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一世旳自豪 2024-10-10 05:47:22

在项目的资源视图中,右键单击yourproject.rc。单击导入...按钮。选择要插入的 JPEG 文件。当它要求您命名类型时,将其命名为“JPEG”之类的名称。从那里,JPEG 将被编译到您的可执行文件中。

要加载它,请使用 FindResource 获取资源句柄,然后 LoadResource 将其加载到内存中,然后LockResource 获取其地址。从那里您可以使用普通的 JPEG 解码器将其转换为可用作纹理的形式。或者,您可以下载 DevIL 来为您处理几乎所有的事情。

In the project's resource view, right click yourproject.rc. Click the Import... button. Select the JPEG file(s) you want to insert. When it asks you to name the type, name it something like "JPEG". From there, the JPEG will be compiled into your executable.

To load it, you use FindResource to get a handle to the resource, then LoadResource to load it into memory, then LockResource to get its address. From there you can use a normal JPEG decoder to get it into a form that you can use as a texture. Alternatively, you could download DevIL to handle almost all of that for you.

十年九夏 2024-10-10 05:47:22

我相信如果您将纹理链接为资源,它将存储在您的.exe文件中。这不是常用的解决方案 - 通常您希望将资源存储在 .exe 旁边的单独文件夹(或存档/VFS 文件)中 - 然后纹理将从该文件加载你运行你的程序。这也意味着每当替换或修改纹理时,您都不必重新编译大 .exe 文件。所以我对你的第一个问题的回答是 - 不,这实际上并不可行,除非你需要将整个应用程序和资源放在一个 .exe 中。

如果您喜欢文件的后一个选项(我推荐),那么使用文件中的纹理的最简单方法是使用加载器库,例如 SOIL 将 OpenGL 纹理加载从任何格式简化为一行代码。

I believe If you link the texture as a resource, it will be stored inside your .exe file. That's not a commonly used solution - usually you'd want to store resources in a separate folder (or an archive/VFS file) next to your .exe - then the texture will be loaded from this file after you run your program. This also means that you won't have to recompile the big .exe file whenever you replace or modify a texture. So my answer to your first question is - no, it's not really feasible, unless you need to have the whole application with resources in a single .exe.

If you like the latter option with files (which I recommend), then the easiest way to use the texture from file is to use a loader library like SOIL which simplifies OpenGL texture loading from any format to a single line of code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文