Is there an easy way to convert a texture to a surface (or render a texture on a surface), so that the pixel data can be accessed, or would each texture need to keep the original surface ?
The only way I know of is to use a streaming texture. Depending on whether you create the texture or
not will be a factor. If you do create the texture, set the access mode to SDL_TEXTUREACCESS_STREAMING.
Then you can use SDL_UpdateTexture() to get the pixels. Check out
https://wiki.libsdl.org/SDL_UpdateTexture
You call SDL_LockTexture(), then SDL_UpdateTexture() to get the pixels, manipulate the pixels or
stuff them in a SDL_Surface first if you like, then call SDL_UnlockTexture() to give the pixels
(manipulated) back to the texture.
Check out the wiki as it has more details and some examples.
HTH
AlvinOn 27/08/14 17:41, MrTAToad wrote:
Is there an easy way to convert a texture to a surface (or render a texture on a surface), so that
the pixel data can be accessed, or would each texture need to keep the original surface ?
You can render a texture to another texture, but you can’t render a texture
to surface. However, you can access the texture data from the current
rendering target by using: SDL_RenderReadPixels(). So you might do:
- Create a renderaccess texture A.
- Set A as render target
- Render to it
- Read pixels by using SDL_RenderReadPixels().
- Revert to original render target
It would be an extremely slow process. SO perhaps its just better to cache
the original surface.
Pallav Nawani
IronCode Gaming Private Limited
Website: http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming
Mobile: 9997478768On Thu, Aug 28, 2014 at 2:11 AM, MrTAToad wrote:
Is there an easy way to convert a texture to a surface (or render a
texture on a surface), so that the pixel data can be accessed, or would
each texture need to keep the original surface ?
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Thanks for that - it is a shame as it means using a bit of extra memori