First, why would you use a streaming texture?
Static textures are designed for sprites and backgrounds and other images that don't change much. You update them with pixels using SDL_UpdateTexture().
Streaming textures are designed for things that update frequently, every few seconds, or every frame. You can also update them with SDL_UpdateTexture(), but for optimal performance you lock them, write the pixels, and then unlock them.
Conceptually they're very simple to use:
- Call SDL_CreateTexture() with the SDL_TEXTUREACCESS_STREAMING access type
- Call SDL_LockTexture() to get raw access to the pixels
- Do any pixel manipulation you want
- Call SDL_UnlockTexture()
- Use the texture in rendering normally.
You might also want to create a surface from the texture pixels if you're doing old style blitting using other SDL surfaces. You can do this by creating a surface with no pixel data and then filling the pixel and pitch info in later:
texture = SDL_CreateTexture(renderer,
surface = SDL_CreateRGBSurfaceFrom(NULL,
... draw to surface
I put together a very simple example based on the running moose by Mike Gorchak: