Search code examples
c++2dsdl-2hardware-acceleration

Huge fps drop when I add big image to sdl texture


So, there's absolutely no fps drop when i add smaller image to sdl screen, but then i added sdl background, with details and everything, on all my screen. Then i get drop from 350 to 150fps. Maybe there's a way to fix it? Add this texture to other screen or something like that ?

Here's how i add this image:

In loading of my game:

SDL_Texture* texture;
SDL_Rect rect;
texture = IMG_LoadTexture(renderer, "data/interiors/baznycia.png");
rect.x = 0;
rect.y = 0;
rect.w = screenWidth;
rect.h = screenHight;

In my game loop:

SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, &rect);
SDL_RenderPresent(renderer);

Solution

  • In your case, because you are drawing a background image of a game with constant window size, it could be beneficial to match the dimensions of your image to your screen size to avoid interpolation being applied to your texture (which takes computation time and thus might limit your FPS)

    Additionally, sometimes a texture pixel format mismatch might cause unneeded texture conversions, so check that you are using the correct format before drawing it to screen.