# Drawing geometry to an SDL_Texture?

As a direct result of this question that I asked a few days ago, I want to draw potentially-complex geometry to a SDL_Texture or, I suppose, an SDL_Surface. Ultimately, I want the foreground of a 2D platformer on this texture so that I cant draw a specific portion to the screen, as explained in the above link. Most of the geometry will be simple rectangles, but I would also like to draw slopes and possibly circles. Diving into OpenGL seems like a viable option at this point, but if I could avoid it, that would be grand.

• You might be interested in the SDL_gpu library found at code.google.com/p/sdl-gpu . It looks like it may be a good middle ground between only being able to draw lines and rectangles, and diving fully into OpenGL. Jun 13, 2014 at 20:05

SDL_SetRenderTarget(SDL_Renderer *renderer,SDL_Texture *texture)
After calling this, any drawing functions using this renderer will be drawn into the specified texture, instead of to the screen. (Passing NULL for the texture will make subsequent drawing functions draw to the screen again)
Note that the texture must have been created using the SDL_TEXTUREACCESS_TARGET flag.