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?
\$\begingroup\$ \$\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– Grey2014-01-30 17:12:54 +00:00Commented Jan 30, 2014 at 17:12
- \$\begingroup\$ @Grey Can you explain? \$\endgroup\$saloomi2012– saloomi20122014-01-30 18:15:11 +00:00Commented Jan 30, 2014 at 18:15
- \$\begingroup\$ Answered your question. Let me know if it works. \$\endgroup\$Grey– Grey2014-01-30 18:31:41 +00:00Commented 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– Lysol2014-01-30 20:28:54 +00:00Commented Jan 30, 2014 at 20:28
- \$\begingroup\$ @Grey uh there is no answer? \$\endgroup\$saloomi2012– saloomi20122014-01-31 01:14:22 +00:00Commented Jan 31, 2014 at 1:14
| Show 3 more comments
1 Answer
\$\begingroup\$ \$\endgroup\$
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.