Proper way to scale an SDL Surface without clipping?
缩放SDL表面的正确方法是什么?我在网上找到了一种解释,但它需要逐像素重新绘制Surface。似乎应该有某种方法可以通过SDL在本地进行此操作,而不是像这样重绘图像。我无法在涵盖此内容的SDL文档中找到任何内容。我可以通过修改曲面的宽度和高度来调整曲面的大小,但是不会剪切任何问题。
我知道这个答案为时已晚,无法帮助提出这个问题的人,但是我决定写这篇文章来帮助那些偶然发现这个问题的人。在SDL 2.0中,可以使用
SDL不支持按比例缩放。根据SDL_BlitSurface的文档:
Note: the SDL blitter does not (yet)
have the capability of scaling the
blitted surfaces up or down like it is
the case with other more sophisticated
blitting mechanisms. You have to
figure something out for yourself if
you want to scale images (e.g. use
SDL_gfx).
您可以在此处找到SDL_gfx。编写自己的blitting函数还不错,这可能是一个有趣而有用的学习实验(尽管您会重新发明轮子)。也可以使用OpenGL,因为可以在单个函数调用中完成缩放和旋转之类的操作。
出于完整性考虑,并且由于问题未指定SDL版本,因此可以使用API??方法
1 2 3 4 5 6 7 | int SDL_RenderCopyEx(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect, const double angle, const SDL_Point* center, const SDL_RendererFlip flip) |
通过设置
从技术上讲,这不是缩放表面,而是缩放纹理。尽管在基于SDL2的应用程序中进行渲染之前,几乎总是将表面转换为纹理,但该过程也应具有相关性。
参考:https://wiki.libsdl.org/SDL_RenderCopyEx
照常创建纹理:
1 2 | surface = IMG_Load(filePath); texture = SDL_CreateTextureFromSurface(renderer, surface); |
当需要渲染它时,请调用