The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Convert texture to surface
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
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 ?
Convert texture to surface
Pallav Nawani


Joined: 19 May 2011
Posts: 122
Location: Dehradun, India
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:


1. Create a renderaccess texture A.
2. Set A as render target
3. Render to it
4. Read pixels by using SDL_RenderReadPixels().
5. 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: 9997478768



On Thu, Aug 28, 2014 at 2:11 AM, MrTAToad wrote:
Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Thanks for that - it is a shame as it means using a bit of extra memori