在不裁剪的情况下缩放 SDL Surface 的正确方法?
缩放 SDL Surface 的正确方法是什么? 我在网上找到了一种解释,但它需要逐像素地重新绘制表面。 似乎应该有某种方法可以通过 SDL 本地执行此操作,而不是像那样重新绘制图像。 我在 SDL 文档中找不到任何涉及此内容的内容。 我可以通过修改曲面宽度和高度来毫无问题地调整曲面大小,但生成的曲面会被剪裁。
what is the proper way to scale an SDL Surface? I found one explanation online but it required redrawing the Surface pixel by pixel. It seems like there should be some way of doing this natively through SDL rather than redrawing the image like that. I haven't been able to find anything in the SDL documentation that covers this. I am able to resize surfaces without any problem by modifying the surfaces width and height, but the resulting surface is clipped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这个答案太晚了,无法帮助提出这个问题的人,但我决定写这篇文章来帮助任何偶然发现这个问题的人。 在 SDL 2.0 中,您可以使用
SDL_BlitScaled()
函数将曲面缩放为目标SDL_Rect
。 LazyFoo 有一个教程对此进行了描述,或者查看此 文档。I know this answer is way too late to assist the person who asked it, but I decided to write this to help anyone who stumbles upon this question. In SDL 2.0 You can use the
SDL_BlitScaled()
function to scale a surface into a targetedSDL_Rect
. There's a tutorial by LazyFoo which describes this, or check out this documentation.SDL 不支持缩放位块传送。 根据 SDL_BlitSurface 的文档:
您可以在此处找到 SDL_gfx。 编写自己的位图传送函数并没有那么糟糕,它可能是一个有趣且有用的学习实验(尽管您会重新发明轮子)。 使用 OpenGL 也是一种选择,因为缩放和旋转等操作可以在单个函数调用中完成。
SDL doesn't support scaled blitting. According to the documentation of SDL_BlitSurface:
You could find SDL_gfx here. Writing your own blitting function isn't that bad, it might be a fun and useful learning experiment (though you'd be reinventing the wheel). Using OpenGL is also an option, as stuff like scaling and rotating could be done in a single function call.
为了完整起见,并且由于问题未指定 SDL 版本,因此可以使用 API 方法
SDL_RenderCopyEx
在 SDL2 中进行缩放。 除了基本的 SDL2 库之外,不需要其他库。通过设置 dstrect 的大小,可以将纹理缩放到整数像素。 还可以同时旋转和翻转纹理。
从技术上讲,这不是缩放表面,而是缩放纹理。 该过程应该是相关的,因为在基于 SDL2 的应用程序中进行渲染之前,表面几乎总是转换为纹理。
参考: https://wiki.libsdl.org/SDL_RenderCopyEx
像往常一样创建纹理:
何时合适要渲染它,请调用
SDL_RenderCopyEx
而不是SDL_RenderCopy
For completeness, and because the question does not specify SDL version, scaling is possible in SDL2 using the API method
SDL_RenderCopyEx
. No additional libs besides the basic SDL2 lib are needed.By setting the size of
dstrect
one can scale the texture to an integer number of pixels. It is also possible to rotate and flip the texture at the same time.Technically this is not scaling a surface but rather scaling a texture. The procedure should be as relevant though as surfaces are almost always converted to textures before the rendering happens in SDL2 based applications.
Reference: https://wiki.libsdl.org/SDL_RenderCopyEx
Create your textures as usual:
And when it's time to render it, call
SDL_RenderCopyEx
instead ofSDL_RenderCopy