# How do I make my game render faster?

**URL:** <https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913>\
**Category:** SDL Development\
**Created:** [May 7, 2012, 5:19pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913 "2012-05-07T17:19:09Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Goswin\_von\_Brederlow](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@Goswin\_von\_Brederlow](https://discourse.libsdl.org/u/Goswin_von_Brederlow)\
**Post date:** [May 7, 2012, 5:19pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/1 "2012-05-07T17:19:09Z")

</div>

Hi,

I’m pretty new to sdl so I’m probably doing some basic mistakes.  
Currently my game takes about 120ms to render a frame, which consists of  
just a bunch of blit() calls. I want to get this to below 40ms,  
hopefully way below.

I already about doubled the speed by calling SDL\_DisplayFormat() for all  
surfaces. What other pitfalls are there to avoid?

I tried setting my main window / surface to HWSURFACE but that slowed  
things down. Is that because then I’m blitting from a SWSURFACE to a  
HWSURFACE lots of times per frame?

MfG  
Goswin

---

<div class="post-metadata">

**Author:** ![Alex\_Barry](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/alex_barry/32/515_2.png) [@Alex\_Barry](https://discourse.libsdl.org/u/Alex_Barry)\
**Post date:** [May 7, 2012, 5:21pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/2 "2012-05-07T17:21:09Z")

</div>

It may be good to keep track of which surfaces have been updated and which  
haven’t - there may be cases where you don’t need to update something that  
you are currently blitting.  
-AlexOn Mon, May 7, 2012 at 1:19 PM, Goswin von Brederlow wrote:

> Hi,
> 
> I’m pretty new to sdl so I’m probably doing some basic mistakes.  
> Currently my game takes about 120ms to render a frame, which consists of  
> just a bunch of blit() calls. I want to get this to below 40ms,  
> hopefully way below.
> 
> I already about doubled the speed by calling SDL\_DisplayFormat() for all  
> surfaces. What other pitfalls are there to avoid?
> 
> I tried setting my main window / surface to HWSURFACE but that slowed  
> things down. Is that because then I’m blitting from a SWSURFACE to a  
> HWSURFACE lots of times per frame?
> 
> MfG  
> Goswin
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![JonnyD](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/jonnyd/32/1604_2.png) [@JonnyD](https://discourse.libsdl.org/u/JonnyD)\
**Post date:** [May 7, 2012, 5:36pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/3 "2012-05-07T17:36:44Z")

</div>

Is there any code to peruse? It would tell a lot more than we can guess.

Jonny D

---

<div class="post-metadata">

**Author:** ![Scott\_Smith](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/8797f3/32.png) [@Scott\_Smith](https://discourse.libsdl.org/u/Scott_Smith)\
**Post date:** [May 7, 2012, 5:41pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/4 "2012-05-07T17:41:35Z")

</div>

Are you using alpha blending? If so that can be a high consumer of the CPU.  
Use SDL\_UpdateRects to only update parts of screen (requires more logic to  
handle, and may not be worth it if the background changes)  
Lower the bpp for your images i.e from 32 bpp to 16 bpp.  
Switch to opengl if you platform can support it.  
Profile your code\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
From: [goswin-v-b@web.de](mailto:goswin-v-b@web.de) (Goswin von Brederlow)  
To: SDL Development List   
Sent: Mon, May 7, 2012 1:19:46 PM  
Subject: [SDL] How do I make my game render faster?

Hi,

I’m pretty new to sdl so I’m probably doing some basic mistakes.  
Currently my game takes about 120ms to render a frame, which consists of  
just a bunch of blit() calls. I want to get this to below 40ms,  
hopefully way below.

I already about doubled the speed by calling SDL\_DisplayFormat() for all  
surfaces. What other pitfalls are there to avoid?

I tried setting my main window / surface to HWSURFACE but that slowed  
things down. Is that because then I’m blitting from a SWSURFACE to a  
HWSURFACE lots of times per frame?

MfG  
Goswin

* * *

SDL mailing list  
SDL at [lists.libsdl.org](http://lists.libsdl.org)  
[http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Pallav\_Nawani](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/pallav_nawani/32/237_2.png) [@Pallav\_Nawani](https://discourse.libsdl.org/u/Pallav_Nawani)\
**Post date:** [May 8, 2012, 4:39am UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/5 "2012-05-08T04:39:10Z")

</div>

Hi,

Are you using the latest version of SDL (SDL2)?  
If so, then SDL\_Surfaces(s) are usually not hardware accelerated.  
Switch to using SDL\_texture and SDL\_Render instead.

Ignore my comments if using SDL 1.2.xx.

PallavOn 07-05-2012 22:49, Goswin von Brederlow wrote:

> Hi,
> 
> I’m pretty new to sdl so I’m probably doing some basic mistakes.  
> Currently my game takes about 120ms to render a frame, which consists of  
> just a bunch of blit() calls. I want to get this to below 40ms,  
> hopefully way below.
> 
> I already about doubled the speed by calling SDL\_DisplayFormat() for all  
> surfaces. What other pitfalls are there to avoid?
> 
> I tried setting my main window / surface to HWSURFACE but that slowed  
> things down. Is that because then I’m blitting from a SWSURFACE to a  
> HWSURFACE lots of times per frame?
> 
> MfG  
> Goswin
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

–  
_Pallav Nawani_  
_Game Designer/CEO_

> **[Ironcode Gaming](https://ironcode.com/)**
>
> Founded in 2004 Ironcode is an independent developer and publisher of quality games. Here at Ironcode we develop and produce original games and also provide end

Twitter: [x.com](http://twitter.com/Ironcode_Gaming)  
Facebook: [Ironcode Gaming](http://www.facebook.com/Ironcode.Gaming)

---

<div class="post-metadata">

**Author:** ![Goswin\_von\_Brederlow](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@Goswin\_von\_Brederlow](https://discourse.libsdl.org/u/Goswin_von_Brederlow)\
**Post date:** [May 8, 2012, 3:29pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/6 "2012-05-08T15:29:49Z")

</div>

Jonathan Dearborn writes:

> Is there any code to peruse? ?It would tell a lot more than we can guess.
> 
> Jonny D

I’m not sure how much help that will be since I’m using ocaml. But here  
we go:

[http://mrvn.homeip.net/gitweb/?p=settler;a=tree](http://mrvn.homeip.net/gitweb/?p=settler;a=tree)  
git clone [http://mrvn.homeip.net/git/settler](http://mrvn.homeip.net/git/settler)

MfG  
Goswin

---

<div class="post-metadata">

**Author:** ![Goswin\_von\_Brederlow](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@Goswin\_von\_Brederlow](https://discourse.libsdl.org/u/Goswin_von_Brederlow)\
**Post date:** [May 8, 2012, 3:53pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/7 "2012-05-08T15:53:50Z")

</div>

Scott Smith writes:

> Are you using alpha blending? If so that can be a high consumer of the CPU.

I need transparency but I have considered using COLORKEY. I suspected  
that alpha blending might be expensive but it is good to see it  
confirmed. I will have to add some code to convert images to COLORKEY  
after loading and compare the two. Alpha blending would allow better  
graphics though.

> Use SDL\_UpdateRects to only update parts of screen (requires more logic to  
> handle, and may not be worth it if the background changes)

There is a minimap of 300x200 pixel that changes every frame and a main  
map of (width - 200) \* height that also changes every frame. What’s left  
is a 200 \* (height - 200) region for GUI elements that will change  
ocasionaly (when the user switches tabs) or frequently (when the user  
switches to a statistics tab), but probably less than every frame.

But the main map is where all the work is spend. I 'm using a hexagonal  
grid so I’m blitting in a lots of triangles for the terrain, ontop each  
another for terrain modification (rivers so far). After that it is  
buildings, items and units as present on the tiles. That comes to up to  
6 surfaces per tile (up+down triangle, up+down modifier, building | item

- unit).

Idealy I want terrain to be animated. Wind going through the grass,  
little waves on the ocean, … Then the terrain would change every  
frame.

Units are to be animated even when stationary (cleaning their nose,  
looking around, that kind of thing) and most certainly while moving. So  
they often change between frames. And that means items and buildings  
must be drawn too in case they overlap. Buildings can be animated too,  
smoke in the chimeny or the like. Not that I have that yet but it should  
be an option. Tracking where items or buildings overlap units or when  
units change their look between frames would be complicated.

> Lower the bpp for your images i.e from 32 bpp to 16 bpp.

Won’t that be slower when running on a 32 bpp display (as I usualy do)?

> Switch to opengl if you platform can support it.  
> Profile your code

MfG  
Goswin

---

<div class="post-metadata">

**Author:** ![Scott\_Smith](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/8797f3/32.png) [@Scott\_Smith](https://discourse.libsdl.org/u/Scott_Smith)\
**Post date:** [May 8, 2012, 4:54pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/8 "2012-05-08T16:54:18Z")

</div>

Colorkey will be much better, especially if the image being copied is just  
replacing the destination colors. It also shouldnt look any worse.  
Based on the description on what your doing I think using opengl to accelerate  
all of your blending and blits would be a huge speed increase. But of course  
that requires a good rewrite on the rendering engine.\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
From: [goswin-v-b@web.de](mailto:goswin-v-b@web.de) (Goswin von Brederlow)  
To: SDL Development List   
Sent: Tue, May 8, 2012 11:54:24 AM  
Subject: Re: [SDL] How do I make my game render faster?

Scott Smith \<@Scott\_Smith\> writes:

> Are you using alpha blending? If so that can be a high consumer of the CPU.

I need transparency but I have considered using COLORKEY. I suspected  
that alpha blending might be expensive but it is good to see it  
confirmed. I will have to add some code to convert images to COLORKEY  
after loading and compare the two. Alpha blending would allow better  
graphics though.

> Use SDL\_UpdateRects to only update parts of screen (requires more logic to  
> handle, and may not be worth it if the background changes)

There is a minimap of 300x200 pixel that changes every frame and a main  
map of (width - 200) \* height that also changes every frame. What’s left  
is a 200 \* (height - 200) region for GUI elements that will change  
ocasionaly (when the user switches tabs) or frequently (when the user  
switches to a statistics tab), but probably less than every frame.

But the main map is where all the work is spend. I 'm using a hexagonal  
grid so I’m blitting in a lots of triangles for the terrain, ontop each  
another for terrain modification (rivers so far). After that it is  
buildings, items and units as present on the tiles. That comes to up to  
6 surfaces per tile (up+down triangle, up+down modifier, building | item

- unit).

Idealy I want terrain to be animated. Wind going through the grass,  
little waves on the ocean, … Then the terrain would change every  
frame.

Units are to be animated even when stationary (cleaning their nose,  
looking around, that kind of thing) and most certainly while moving. So  
they often change between frames. And that means items and buildings  
must be drawn too in case they overlap. Buildings can be animated too,  
smoke in the chimeny or the like. Not that I have that yet but it should  
be an option. Tracking where items or buildings overlap units or when  
units change their look between frames would be complicated.

> Lower the bpp for your images i.e from 32 bpp to 16 bpp.

Won’t that be slower when running on a 32 bpp display (as I usualy do)?

> Switch to opengl if you platform can support it.  
> Profile your code

MfG  
Goswin

* * *

SDL mailing list  
SDL at [lists.libsdl.org](http://lists.libsdl.org)  
[http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![JonnyD](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/jonnyd/32/1604_2.png) [@JonnyD](https://discourse.libsdl.org/u/JonnyD)\
**Post date:** [May 8, 2012, 5:10pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/9 "2012-05-08T17:10:32Z")

</div>

If you do want to make an easy transition to OpenGL (avoiding such a  
rewrite as Scott mentions), I made a C library that has an API similar to  
SDL’s surface API:  
[http://code.google.com/p/sdl-gpu/](http://code.google.com/p/sdl-gpu/)

It would be nice to have a wider usage base than just me. 🙂

It has rotation, scaling, and other good stuff. The main difference  
semantically is that it draws images at their center instead of at the  
top-left corner. It also differentiates render targets from image sources.

There are a bunch of demo programs that show how to use it in lieu of  
formal documentation.

Jonny D

---

<div class="post-metadata">

**Author:** ![Goswin\_von\_Brederlow](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@Goswin\_von\_Brederlow](https://discourse.libsdl.org/u/Goswin_von_Brederlow)\
**Post date:** [May 9, 2012, 9:13am UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/10 "2012-05-09T09:13:00Z")

</div>

Scott Smith writes:

> Colorkey will be much better, especially if the image being copied is just  
> replacing the destination colors. It also shouldnt look any worse.

Rivers have a start and end point and there the rivers sandy edge  
(didn’t blend the water itself unfortunaetly) blends smoothly into the  
terrain [1]. Makes it look much better than having a hard edge as  
required by colorkey. So there will be some drawbacks. Probably nothing  
that can’t be solved by pre rendering tiles with river and then blitting  
the combined tile with colorkey.

> Based on the description on what your doing I think using opengl to accelerate  
> all of your blending and blits would be a huge speed increase. But of course  
> that requires a good rewrite on the rendering engine.

I’m afraid GL is not always an option. Not everyone has it and I don’t  
have it everywhere myself. And software GL will be much slower. I will  
probably provide a GL flavour but I want this to also run without.

MfG  
Goswin–  
1 [http://mrvn.homeip.net/map/foo.png](http://mrvn.homeip.net/map/foo.png)

---

<div class="post-metadata">

**Author:** ![David\_Olofson](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/david_olofson/32/115_2.png) [@David\_Olofson](https://discourse.libsdl.org/u/David_Olofson)\
**Post date:** [May 9, 2012, 7:23pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/11 "2012-05-09T19:23:31Z")

</div>

I haven’t been following this thread closely (in fact, I’ve been completely  
cut off from email for a few days), but if you have plenty of detail and/or  
expensive operations (blending) on the maps, it might be an option to render  
the background into an offscreen cache of some sort and update the screen from  
that instead. This way, the per-frame fullscreen blits will be simple  
rectangular opaque copy operations, whereas the heavy rendering only has to be  
done for the areas exposed as the view scrolls across the map.On Wednesday 09 May 2012, at 11.13.00, Goswin von Brederlow wrote:

> Scott Smith writes:
> 
> > Colorkey will be much better, especially if the image being copied is  
> > just replacing the destination colors. It also shouldnt look any worse.
> 
> Rivers have a start and end point and there the rivers sandy edge  
> (didn’t blend the water itself unfortunaetly) blends smoothly into the  
> terrain [1]. Makes it look much better than having a hard edge as  
> required by colorkey. So there will be some drawbacks. Probably nothing  
> that can’t be solved by pre rendering tiles with river and then blitting  
> the combined tile with colorkey.

–  
//David Olofson - Consultant, Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.  
| [http://consulting.olofson.net](http://consulting.olofson.net)[http://olofsonarcade.com](http://olofsonarcade.com) |  
‘---------------------------------------------------------------------’

---

<div class="post-metadata">

**Author:** ![Goswin\_von\_Brederlow](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@Goswin\_von\_Brederlow](https://discourse.libsdl.org/u/Goswin_von_Brederlow)\
**Post date:** [May 10, 2012, 12:03pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/12 "2012-05-10T12:03:52Z")

</div>

David Olofson writes:\> On Wednesday 09 May 2012, at 11.13.00, Goswin von Brederlow wrote:

> > Scott Smith writes:
> > 
> > > Colorkey will be much better, especially if the image being copied is  
> > > just replacing the destination colors. It also shouldnt look any worse.
> > 
> > Rivers have a start and end point and there the rivers sandy edge  
> > (didn’t blend the water itself unfortunaetly) blends smoothly into the  
> > terrain [1]. Makes it look much better than having a hard edge as  
> > required by colorkey. So there will be some drawbacks. Probably nothing  
> > that can’t be solved by pre rendering tiles with river and then blitting  
> > the combined tile with colorkey.
> 
> I haven’t been following this thread closely (in fact, I’ve been completely  
> cut off from email for a few days), but if you have plenty of detail and/or  
> expensive operations (blending) on the maps, it might be an option to render  
> the background into an offscreen cache of some sort and update the screen from  
> that instead. This way, the per-frame fullscreen blits will be simple  
> rectangular opaque copy operations, whereas the heavy rendering only has to be  
> done for the areas exposed as the view scrolls across the map.

That idea has crossed my mind too.

Problem there comes when the background is animated. I would have to  
render X copies covering a full animation cycle. And if the animation  
cycles of individual tiles differ (river has 7 frames, ocean has 11 =\> X  
= 77) then X can become rather large.

It is a possibility if nothing else helps and by picking the number of  
frames per animation right the total number of frames needed could be  
kept small.

MfG  
Goswin

---

<div class="post-metadata">

**Author:** ![David\_Olofson](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/david_olofson/32/115_2.png) [@David\_Olofson](https://discourse.libsdl.org/u/David_Olofson)\
**Post date:** [May 10, 2012, 12:19pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/13 "2012-05-10T12:19:39Z")

</div>

[…off-screen cache…]

> That idea has crossed my mind too.
> 
> Problem there comes when the background is animated. I would have to  
> render X copies covering a full animation cycle. And if the animation  
> cycles of individual tiles differ (river has 7 frames, ocean has 11 =\> X  
> = 77) then X can become rather large.
> 
> It is a possibility if nothing else helps and by picking the number of  
> frames per animation right the total number of frames needed could be  
> kept small.

Are tiles aligned to a fixed grid, or can they be placed arbitrarily?

If you’re sticking with aligned tiles, multilayering is basically a form of  
compression, and you might get away with “decompressing” at load time by pre-  
rendering all combinations of tiles that will be used in the map.

Or, you can maintain a cache of prerendered combined tiles for the current  
view only, so new sets/animation cycles only have to be rendered once as they  
come into view.

All sorts of variants here - but of course, this stuff does complicate the  
engine quite a bit. Can’t blame people for relying on hardware acceleration  
and/or raw CPU power… 🙂

BTW, you are using RLE acceleration, right…? That restricts the impact of  
alpha blending to only the areas that actually need blending (opaque areas ore  
copied and transparent areas are skipped), rather than forcing the blitter to  
blend every pixel of RGBA surfaces.On Thursday 10 May 2012, at 14.03.52, Goswin von Brederlow wrote:

–  
//David Olofson - Consultant, Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.  
| [http://consulting.olofson.net](http://consulting.olofson.net)[http://olofsonarcade.com](http://olofsonarcade.com) |  
‘---------------------------------------------------------------------’

---

<div class="post-metadata">

**Author:** ![Goswin\_von\_Brederlow](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@Goswin\_von\_Brederlow](https://discourse.libsdl.org/u/Goswin_von_Brederlow)\
**Post date:** [May 10, 2012, 6:34pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/14 "2012-05-10T18:34:24Z")

</div>

David Olofson writes:\> On Thursday 10 May 2012, at 14.03.52, Goswin von Brederlow \<@Goswin\_von\_Brederlow\> wrote:

> […off-screen cache…]
> 
> > That idea has crossed my mind too.
> > 
> > Problem there comes when the background is animated. I would have to  
> > render X copies covering a full animation cycle. And if the animation  
> > cycles of individual tiles differ (river has 7 frames, ocean has 11 =\> X  
> > = 77) then X can become rather large.
> > 
> > It is a possibility if nothing else helps and by picking the number of  
> > frames per animation right the total number of frames needed could be  
> > kept small.
> 
> Are tiles aligned to a fixed grid, or can they be placed arbitrarily?
> 
> If you’re sticking with aligned tiles, multilayering is basically a form of  
> compression, and you might get away with “decompressing” at load time by pre-  
> rendering all combinations of tiles that will be used in the map.
> 
> Or, you can maintain a cache of prerendered combined tiles for the current  
> view only, so new sets/animation cycles only have to be rendered once as they  
> come into view.
> 
> All sorts of variants here - but of course, this stuff does complicate the  
> engine quite a bit. Can’t blame people for relying on hardware acceleration  
> and/or raw CPU power… 🙂
> 
> BTW, you are using RLE acceleration, right…? That restricts the impact of  
> alpha blending to only the areas that actually need blending (opaque areas ore  
> copied and transparent areas are skipped), rather than forcing the blitter to  
> blend every pixel of RGBA surfaces.

I havent a clue. I’m not specifically turning on RLE. In ocaml some  
functions have it as optional argument and I just skipped it. No idea if  
that means it is on or off but I suspect off. I didn’t see it in the  
surface infos when I looked at specific surfaces.

Here are some surprising timings:

Alpha blending: 120ms/frame  
Color key : 145ms/frame  
Opaque : 100ms/frame

I would have expected color key to be faster than or at least equal to  
alpha blending even if all but river tiles have only totaly transparent  
or totaly opaque for now.

MfG  
Goswin

---

<div class="post-metadata">

**Author:** ![Benjamin\_Shadwick](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@Benjamin\_Shadwick](https://discourse.libsdl.org/u/Benjamin_Shadwick)\
**Post date:** [May 10, 2012, 7:51pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/15 "2012-05-10T19:51:19Z")

</div>

Just out of curiosity: how long does it take to render frames if you  
comment out the actual blit() calls?

It might be useful to see what the performance of your rendering logic is  
before SDL enters the picture, especially if you’re traversing a bunch of  
data structures or doing a lot of other bookkeeping in the middle of it.On Thu, May 10, 2012 at 11:34 AM, Goswin von Brederlow wrote:

> David Olofson writes:
> 
> > On Thursday 10 May 2012, at 14.03.52, Goswin von Brederlow \< goswin-v-b at [web.de](http://web.de)\> wrote:  
> > […off-screen cache…]
> > 
> > > That idea has crossed my mind too.
> > > 
> > > Problem there comes when the background is animated. I would have to  
> > > render X copies covering a full animation cycle. And if the animation  
> > > cycles of individual tiles differ (river has 7 frames, ocean has 11 =\> X  
> > > = 77) then X can become rather large.
> > > 
> > > It is a possibility if nothing else helps and by picking the number of  
> > > frames per animation right the total number of frames needed could be  
> > > kept small.
> > 
> > Are tiles aligned to a fixed grid, or can they be placed arbitrarily?
> > 
> > If you’re sticking with aligned tiles, multilayering is basically a form  
> > of  
> > compression, and you might get away with “decompressing” at load time by  
> > pre-  
> > rendering all combinations of tiles that will be used in the map.
> > 
> > Or, you can maintain a cache of prerendered combined tiles for the  
> > current  
> > view only, so new sets/animation cycles only have to be rendered once as  
> > they  
> > come into view.
> > 
> > All sorts of variants here - but of course, this stuff does complicate  
> > the  
> > engine quite a bit. Can’t blame people for relying on hardware  
> > acceleration  
> > and/or raw CPU power… 🙂
> > 
> > BTW, you are using RLE acceleration, right…? That restricts the impact  
> > of  
> > alpha blending to only the areas that actually need blending (opaque  
> > areas ore  
> > copied and transparent areas are skipped), rather than forcing the  
> > blitter to  
> > blend every pixel of RGBA surfaces.
> 
> I havent a clue. I’m not specifically turning on RLE. In ocaml some  
> functions have it as optional argument and I just skipped it. No idea if  
> that means it is on or off but I suspect off. I didn’t see it in the  
> surface infos when I looked at specific surfaces.
> 
> Here are some surprising timings:
> 
> Alpha blending: 120ms/frame  
> Color key : 145ms/frame  
> Opaque : 100ms/frame
> 
> I would have expected color key to be faster than or at least equal to  
> alpha blending even if all but river tiles have only totaly transparent  
> or totaly opaque for now.
> 
> MfG  
> Goswin
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

–

- Ben S.

---

<div class="post-metadata">

**Author:** ![Goswin\_von\_Brederlow](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@Goswin\_von\_Brederlow](https://discourse.libsdl.org/u/Goswin_von_Brederlow)\
**Post date:** [May 11, 2012, 8:18am UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/16 "2012-05-11T08:18:05Z")

</div>

Benjamin Shadwick writes:

> Just out of curiosity: how long does it take to render frames if you comment  
> out the actual blit() calls?
> 
> It might be useful to see what the performance of your rendering logic is  
> before SDL enters the picture, especially if you’re traversing a bunch of data  
> structures or doing a lot of other bookkeeping in the middle of it.

~12ms for the flip, ~8ms for the minimap, ~95ms for terrain, ~7ms for  
buildings, items and units

MfG  
Goswin

MfG  
Goswin

---

<div class="post-metadata">

**Author:** ![Benjamin\_Shadwick](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@Benjamin\_Shadwick](https://discourse.libsdl.org/u/Benjamin_Shadwick)\
**Post date:** [May 11, 2012, 11:47pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/17 "2012-05-11T23:47:42Z")

</div>

So even without rendering terrain, you’d only be able to achieve 37 FPS  
(1000 / (12 + 8 + 7)).On Fri, May 11, 2012 at 1:18 AM, Goswin von Brederlow wrote:

> Benjamin Shadwick \<@Benjamin\_Shadwick\> writes:
> 
> > Just out of curiosity: how long does it take to render frames if you  
> > comment  
> > out the actual blit() calls?
> > 
> > It might be useful to see what the performance of your rendering logic is  
> > before SDL enters the picture, especially if you’re traversing a bunch  
> > of data  
> > structures or doing a lot of other bookkeeping in the middle of it.
> 
> ~12ms for the flip, ~8ms for the minimap, ~95ms for terrain, ~7ms for  
> buildings, items and units
> 
> MfG  
> Goswin
> 
> MfG  
> Goswin
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

–

- Ben S.

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [May 12, 2012, 1:37pm UTC](https://discourse.libsdl.org/t/how-do-i-make-my-game-render-faster/18913/18 "2012-05-12T13:37:17Z")

</div>

You’re likely to get much better performance if you switch to SDL 2.0  
and/or a 3D solution.On Fri, May 11, 2012 at 7:47 PM, Benjamin Shadwick wrote:

> So even without rendering terrain, you’d only be able to achieve 37 FPS  
> (1000 / (12 + 8 + 7)).
> 
> On Fri, May 11, 2012 at 1:18 AM, Goswin von Brederlow wrote:
> 
> > Benjamin Shadwick writes:
> > 
> > > Just out of curiosity: how long does it take to render frames if you  
> > > comment  
> > > out the actual blit() calls?
> > > 
> > > It might be useful to see what the performance of your rendering logic  
> > > is  
> > > before SDL enters the picture, especially if you’re traversing a bunch  
> > > of data  
> > > structures or doing a lot of other bookkeeping in the middle of it.
> > 
> > ~12ms for the flip, ~8ms for the minimap, ~95ms for terrain, ~7ms for  
> > buildings, items and units
> > 
> > MfG  
> > Goswin
> > 
> > MfG  
> > Goswin
> > 
> > * * *
> > 
> > SDL mailing list  
> > SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> > [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> 
> –
> 
> - Ben S.
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
