I am working with SDL-1.3.0-5538. My project is to realize a real time strategy game. First: I used the search engine and found some possible solutions, but they did not work for me. Here is my problem:
I implemented a "fog of war". If I run my game with fog of war deactivated, I have a framerate of ~25 fps (that's also too low, but this is another topic...).
If I activate the fog of war, the framerate falls down to ~8 fps.
Here is my game with fog of war enabled:
As you can see unexplored areas are completly dark, explored but currently not visible areas are transparent gray und currently visible areas are... visible ;)
This is how I realized the fog of war:
- I once create two SDL_Surfaces 'A' and 'B'
- Both have a color key: White
- SDL_Surface 'A' is filled with gray as color and has in addition to the white color key a tranparency value of 175. The dimensions of 'A' are the same as the screen dimensions, in this case 1024x768
- SDL_Surface 'B' is filled with black as color and has the dimension of the map which has to be explored: w=h=4096*4096
I render the currently visible map area. Without the fog i now have ~25fps.
If i render SDL_Surface 'A' on my screen and after this Surface 'B' to archieve the result as shown in the image, the framerate is ~8fps. I know that Surface 'B' is bigger as the screen dimensions, so I only render the actual needed part.
I dont know why these simple 2 blitting operations are so incredible slow? In another topic a user said that you have to use the function 'SDL_DisplayFormat', but if I do so for Surface 'A' and 'B' the framerate falls down to ~0.2 fps.
SDL_Surface *pConverted= SDL_DisplayFormat(pSurface); // Setting color key and transparency is done befor calling SDL_DisplayFormat
SDL_FreeSurface(pSurface);
pSurface = pConverted;
Thanks for reading...