Why read pixels from the target texture in the end?
Also, you can't give SDL_CreateTexture a pixels pointer. Maybe you mean
Why do a render copy if later you do an SDL_UpdateTexture?
I had some issues figuring out what "pitch" is and how to get it. Turns out
that you use SDL_LockTexture for that. Also, you get the pixels the same
So no need for renderer hacks with targets and reads. A bit
It still doesn't work though:
SDL_QueryTexture(other, &other_format, &other_access, &other_w,
SDL_Texture* texture = SDL_CreateTexture(renderer, other_format,
other_access, other_w, other_h);
SDL_LockTexture(other, nullptr, (void**)&other_pixels, &other_pitch);
SDL_LockTexture(texture, nullptr, (void**)&pixels, &pitch);
for (int i = 0; i < pitch * other_h; ++i)
pixels[i] = other_pixels[i];
SDL_UnlockTexture(other);On Sun, Apr 20, 2014 at 7:18 PM, lorin <looorin at gmail.com> wrote:
I do not think copying of Textures is a good idea at all. They are (as
far as I know) stored somewhere on GPU memory. They are designed to fast
rendering, but not to access or change.
You always can set access flag SDL_TEXTUREACCESS_STREAMING to texture. In
that case pixels data are stored at RAM memory ( AFAIK ) and you can easily
edit it by SDL_LockTexture and SDL_UnlockTexture.
On the other hand, I would recomend to create new Texture from SDL_Surface
or whatever you load your graphics data from.
PS: I think there is a way how to copy texture.
SDL_QueryTexture - get info about original texture
SDL_CreateTexture - with flag TARGET (call it target texture)
SDL_SetRenderTarget - set it to target texture
SDL_RenderCopy - Render original to target texture
SDL_SetRenderTarget - reset it to default
SDL_RenderReadPixels - Read pixels from target texture
SDL_CreateTexture - Create copy of texture with pixels data from ReadPixels
I'm SDL newbie
SDL mailing list
SDL at lists.libsdl.org