1
\$\begingroup\$

I'd like to use the function

int SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture  *texture)

in my 2D game. At this point I am using only the SDL 2.0 API, and using openGL seems overkill to me. Rendering to an intermediate texture would greatly simplify the programming of a camera system and split-screen support. However, the (sparse) SDL wiki documentation states:

Before using this function, you should check the SDL_RENDERER_TARGETTEXTURE bit in the flags of SDL_RendererInfo to see if render targets are supported.

This raises the question wether or not can I rely on the availability of this function. I was unable to find any information on the subject on the web.

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

Internally SDL uses Framebuffer Objects to implement Render Targets on OpenGL/ES/ES2. The Direct3D backend uses D3D9 SetRenderTarget .

FWIW, the only system I found not to support this functionality is the sketchy OpenGL ES 1.x implementation in the nVidia binary driver for Linux, which is just an anecdote (you either just use regular OpenGL or GL ES 2), pretty much anything supports this functionality.

\$\endgroup\$
2
  • \$\begingroup\$ How is the camera in 2D games usually implemented? I can think of two methods: Individually adjust the coordinates and scaling of each sprite or primitive so that the correct part of the world is drawn to the framebuffer, or draw to an intermediate buffer, and only draw the wanted part of the intermediate buffer to the display, scaling if necessary. \$\endgroup\$
    – jms
    Commented Sep 24, 2013 at 21:59
  • \$\begingroup\$ I usually keep a "scene" space where the sprites are, and a screen space. When rendering I translate the screen rectangle to scene coordinates (apply zoom, scroll, etc), then pick up the sprites that fall in that translated rectangle and render them accordingly. I wouldn't advise rendering the entire scene to a texture and from that pick up a smaller section to render to screen, unless your particular game is suited for that (small scenes, probably low res pixel art) \$\endgroup\$
    – gabomdq
    Commented Sep 25, 2013 at 12:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .