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\$
8
  • \$\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
    Commented Jan 30, 2014 at 17:12
  • \$\begingroup\$ @Grey Can you explain? \$\endgroup\$ Commented Jan 30, 2014 at 18:15
  • \$\begingroup\$ Answered your question. Let me know if it works. \$\endgroup\$
    – Grey
    Commented Jan 30, 2014 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
    Commented Jan 30, 2014 at 20:28
  • \$\begingroup\$ @Grey uh there is no answer? \$\endgroup\$ Commented Jan 31, 2014 at 1:14

1 Answer 1

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\$

You must log in to answer this question.

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