将 PNG 纹理加载到 OpenGL
我正在开发一款游戏,我的所有图形都使用洋红色作为透明/魔法颜色。 它们都是 32 位的,洋红色只是为了方便。 不管怎样,如果有人能建议我应该使用什么库来加载图像(我需要以 GL_RGBA 格式加载它们,包括内部和纹理特定的),我将不胜感激。
I'm working on a game, and all of my graphics use magenta as transparent/magic color.
They are all 32-bit and the magenta is just for conveniency.
Anyway, I would appreciate if someone could advice me what library should I use to load my images (I need to load them in GL_RGBA format, both internal and texture specific).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果只需要 PNG 支持,请使用 libpng。 DevIL 应该很简单,但它有点臃肿(不仅仅是加载图像),并且在内部实际上调用了 OpenGL 函数,这可能会扰乱您自己的 OpenGL 逻辑。
我个人更喜欢 SDL_image,因为无论如何我都在我的项目中使用 SDL。虽然不是很明显,但 SDL_BlitSurface() 函数可以将 IMG_Load() 返回的任何内容转换为必要的像素格式。
If only PNG support is necessary, use libpng. DevIL is supposed to be easy, but it's somewhat bloated (does a lot more than just load images) and internally actually calls OpenGL functions which can mess with your own OpenGL logic.
I personally prefer SDL_image, since I'm using SDL in my projects anyway. While not immediately obvious, SDL_BlitSurface() function can do the conversion from whatever IMG_Load() returns to the necessary pixel format.
DevIL 可以加载几乎所有文件格式,并可以直接创建 OpenGL 纹理。这是最简单的方法。
您还应该使用支持 Alpha 通道的文件格式(PNG、TGA...)。在 32 位图像中使用“魔法颜色”确实已经过时了!
DevIL can load virtually every file format and can directly create OpenGL textures. It is the easiest way to go.
You should also use a file format which supports an alpha channel (PNG, TGA, ...). Using a "magic color" in 32-bit images is really out-dated!
除了提到 SDL 和 DevIL 的其他答案之外,还有两个选项需要考虑:
Apart from the other answers mentioning SDL and DevIL, there are two more options to consider:
这里有一个非常简单的单文件示例,将 png 加载到 openGL 中:
http: //tfc.duke.free.fr/coding/src/png.c
There is a very minimalist one file example of loading a png into openGL here:
http://tfc.duke.free.fr/coding/src/png.c
另一种选择是 OpenCV。
它的功能不仅仅是纹理加载,而且您很有可能会发现它的其他功能的用途。
Another option is OpenCV.
It does a lot more than just texture loading, but odds are good you'll find use of its other features as well.