我正在尝试找到在 SDL 中进行 alpha 混合的最有效方法。我不想回去重写渲染代码以使用 OpenGL(我读到使用 alpha 混合效率更高),所以我试图找出如何从 SDL 的 alpha 中获得最大收益混合。
我读过,我可以从使用硬件表面中受益,但这意味着我必须全屏运行游戏。有人可以对此发表评论吗?或者还有其他关于 SDL 中 alpha 透明度的信息吗?
I'm trying to find the most efficient way to alpha blend in SDL. I don't feel like going back and rewriting rendering code to use OpenGL instead (which I've read is much more efficient with alpha blending), so I'm trying to figure out how I can get the most juice out of SDL's alpha blending.
I've read that I could benefit from using hardware surfaces, but this means I'd have to run the game in fullscreen. Can anyone comment on this? Or anything else regarding alpha transparency in SDL?
发布评论
评论(3)
我曾经玩过 sdl 硬件表面,但这并不是最愉快的体验。 SDL 确实很容易使用,但是当它达到效率时,您真的应该坚持使用专门为此类任务设计的东西。 OpenGL 在这里是一个不错的选择。您始终可以将 SDL(窗口和事件管理)与 openGL(图形)混合并使用一些已经编写的代码。
您可以在此处和此处
I have once playing with sdl hardware surfaces ant it wasn't the most pleasant experience. SDL is really easy to use, but when it gets to efficiency you should really stick with something that was especially designed for such task. OpenGL is a good choice here. You can always mix SDL (window and event management) with openGL (graphics) and use some of the already written code.
You can find some info on hardware surfaces here and here
决定对该部分不使用 alpha 混合。像素混合对于软件表面来说太多了,当您需要硬件的强大功能时,就需要 OpenGL。
Decided to just not use alpha blending for that part. Pixel blending is too much for software surfaces, and OpenGL is needed when you want the power of your hardware.
将 OpenGL 与 SDL 结合使用。了解 GL 库是件好事(现在我几乎看不到非图形加速的东西有什么用途,甚至现在 GUI 也使用它)。 SDL_image 有一种方法来检查 Alpha 通道。我从图像文件的路径创建纹理的函数(使用 SDL_image 的 IMG_Load() 函数)具有以下功能:
pow2() 只是将数字四舍五入到下一个最接近的 2 的幂。现在很多显卡都可以处理非幂纹理大小有 2 个值,但据我所知,它们绝对没有针对它进行优化(测试帧速率)。其他显卡将拒绝渲染,您的应用程序可能会崩溃等。
代码位于:http://www.tatsh.net/2010-06-19/using-sdlimage-and-sdlttf-opengl
Use OpenGL with SDL. It's good to get to know the GL library (I hardly see a use for non-graphics accelerated stuff these days, even GUIs use it now). SDL_image has a way to check for alpha channel. My function that creates textures from a path to an image file (uses SDL_image's IMG_Load() function) has this:
pow2() just rounds the number to the next closest power of 2. A lot of video cards nowadays can handle non-power of 2 values for texture sizes but as far as I can tell, they are definitely NOT optimised for it (tested framerates). Other video cards will just refuse to render, your app may crash, etc etc.
Code is here: http://www.tatsh.net/2010-06-19/using-sdlimage-and-sdlttf-opengl