Вопрос

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 zoomed 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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top