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\$
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\$
  • \$\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 Sep 24 '13 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 Sep 25 '13 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.