Search code examples
c++performancesdlsurfaceframe-rate

C++ - SDL: Blitting performance issues


I am a beginner to C++ and SDL, but I have been developing games for several years.

I chose SDL for its simplicity since all I wanted was a 2D game, but I am not satisfied. The functions working with surfaces eat a lot of power, way too much to be honest.

When I first started using SDL I got like 30 FPS. Then I found out about optimizing surfaces, framerate jumped to 60. Also switching pixel format from 24-bit to 32-bit improved it to 100.

In my opinion this performance compared to other libraries for game development and programming languages is weak. I kept thinking it was still my fault and my FPS could skyrocket if I had everything set correctly.

So I kept testing to find that having no code running (excluding my FPS indicator) yields me 400 FPS. However clearing the screen with SDL_FillRect() function drops it to 100. Then for every sprite drawn the framerate gets even lower and lower.

Is it really supposed to be this slow?


Solution

  • First off, 100 FPS is not slow. Anything about 60 is irrelevant in most cases due to monitor refresh rates anyway.

    Second, what kinds of surfaces are you blitting? I remember when I made a big SDL game, I was really surprised to discover that a particular image I had was taking forever to blit. But fiddling with the quality a bit to remove dithering caused it to start blitting almost instantly again. I think SDL using run length encoding internally, so images that contain runs will blit faster.