开发者

Faster way to scale SDL view than SDL_gfx zoomSurface?

开发者 https://www.devze.com 2023-04-06 00:30 出处:网络
I\'m programming a game with SDL. I\'ve implemented scalable window size via the SDL_gfx library\'s zoomSurface function, but boy does the framerate take a hit (presumably because every time you call

I'm programming a game with SDL. I've implemented scalable window size via the SDL_gfx library's zoomSurface function, but boy does the framerate take a hit (presumably because every time you call zoomSurface, it creates an entirely new SDL_Surface instance, and in order to be continuously z开发者_运维技巧oomed you need to call it every frame).

I'm pretty new to programming with SDL so I'm not aware of any other functions it might have. Is there a faster way to go about doing this?


SDL doesn't really support this.

The most 'correct' way is to use the underlying graphics API (OpenGL or DirectX) to do the scaling. For example, calling glScale{f,d} if you're using OpenGL under the hood. I believe SDL on Windows is compiled to use DirectX, however, so this isn't a portable solution.

An alternative is to re-create all surfaces when you need to zoom everything by some factor. This is slow, but it doesn't need to be done every frame; it only needs to be done once when the scaling factor changes, and then the scaled surface can be kept in memory and re-used for each frame.

Keep in mind that it usually doesn't make sense for 2D games to allow scaled resizing, because sprites tend to look horrible when stretched unless some filter is used.

0

精彩评论

暂无评论...
验证码 换一张
取 消