Since the missile always looks the same, I’d like to create the corresponding object once in a surface or the like, and instead of recreating it on demand, just copyRect it to the destination.
I did not find a possibility to draw such a figure to a figure in a way I can reuse it. Using a loaded bitmap file is not an alternative for me here, since the size of the missile is computed dynamically. Is there anyway to draw to an in-memory buffer/surface, and to copy this to the appropriate position on the screen?
1.) Create a new texture.
2.) Use SDL_SetRenderTarget to set the target to the new texture
3.) Draw my object as before
4.) Copy the texture to the window
The point is you have to clear the texture and redraw a new object into that texture only when it needs to (eg. size changed). Otherwise it will be the same as draw it to the screen directly, even worse render target can cause performance drop.
thanx, I got it working. Still it got not expected results. I thought drawing a triangle every frame would be slower than to create it once in a texture and to copy it at the appropriate position all the time. Maybe I was misled here, a graphics processor may be faster in drawing directly to the window than copying the containing SDL_Rect to the window.
Anyway, your proposal did work, although not with the expected performance gain.