3
\$\begingroup\$

I am trying to make a paint program and there is a sdl function called IMG_SavePNG() which requires a surface and destination file. How can I turn what I see in the window to a surface?

\$\endgroup\$
  • \$\begingroup\$ I haven't used SDL in a very long time however, since what your asking is equivalent to taking a screenshot, just get the backbuffers SDL Surface and pass it to your IMG_SavePNG(); \$\endgroup\$ – Grey Jan 30 '14 at 17:12
  • \$\begingroup\$ @Grey Can you explain? \$\endgroup\$ – saloomi2012 Jan 30 '14 at 18:15
  • \$\begingroup\$ Answered your question. Let me know if it works. \$\endgroup\$ – Grey Jan 30 '14 at 18:31
  • \$\begingroup\$ You can use SDL_GetWindowSurface() to get a surface from the window. See this answer: stackoverflow.com/a/20233470/1212968 \$\endgroup\$ – Lysol Jan 30 '14 at 20:28
  • \$\begingroup\$ @Grey uh there is no answer? \$\endgroup\$ – saloomi2012 Jan 31 '14 at 1:14
3
\$\begingroup\$

To achieve this in SDL, you need to use the SDL_GetWindowSurface() funcion. This function will return the surface associated with the window. You can then pass the surface to the IMG_SavePNG function to take a screenshot.

\$\endgroup\$

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.