I think using SDL_LockTexture might not be best solution.
What I don’t like in it, is that it’s marked as a write-only function in
its documentation, and it doesn’t work for every texture. The second thing
is that it involves a lot of copy, and it’s slow, maybe too slow.
An alternative for it, which works really awesome in c++, but sadly not
that good in c, is to store an SDL_Surface copy of the image too. Basically
in c++ you can make your own image class that can be edited like an
SDL_Surface and is copied as fast as a texture. Also you can copy pictures
to each other just by using opeator=(), however without storing surfaces
you couldn’t blit textures to each other. And the best in it, is that the
surface part can stay locked, you can access its pixels like it was 2d
array, without any slowdown caused by locking, at still be able to render
the texture to the screen with full speed. Basically you can use this class
everywhere where you can use SDL_Texture* or SDL_Surface* if you make the
appropriate cast operators, but you can also handle a lot of exception
pretty easily, which makes debugging thousand times easier, and you can’t
do with the SDL’s built in structs. And of course you can make constructor
to be able to create only the SDL_Texture part in your image class, if
don’t need the extra features or is in lack of memory.
In c, well, the basic idea still works, you can still have a struct that
contains a surface and a texture, and you can write functions for it, but
it won’t be as convenient to use it.On Apr 11, 2013 10:06 AM, “Michael Parker” wrote:
A search of the archives showed someone asked this question a while
ago, but it was never answered. How does one go about getting the
pixels from a texture now that SDL_QueryTexturePixels has been
removed?
I have a D binding to SDL 2 and someone recently asked me to expose
the SDL_Texture struct as defined in sysrender.h. Of course, I’m not
about to do that. Apparently, in C, he’s bypassing the public API and
accessing the struct field directly. But this has got me curious.
I don’t trust the wiki anymore as being up-to-date, but skimming
through the headers nothing stands out at me as a way to get at a
texture’s pixels. Am I missing something?
–
Mike Parker
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.orhttp://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org