Hi I would like to know if it is possible to simply take a screenshot with SDL2.
I tried SDL_GetWindowSurface
but I get an error saying:
No hardware accelerated renderers available.
I took the code from here.
Another solution I thought about is converting a texture to a surface but I didn't manage to do so...
Do you have any solution?
It seems like you are mixing the rendering systems. That method will only work in the context of software rendering. For hardware rendering you should use the method
SDL_RenderReadPixels()
. To save the screenshot you would need a code like that:Where w and h are the screen width and height (you can get these values using
SDL_GetRendererOutputSize()
).In C SDL2 version 2.0.3, it works with:
/!\ ATTENTION /!\
...must previously be set somewhere (in a .h file for example)
EDIT: corrections needed
Don't put the previous paragraph in .h file, cause it may lead to a multiple definition of the variables *mask... if you use multiple source files in a project... put this in a function implementation instead...