Accessing texture pixels (SDL1.3)

Hello,

I need to read individual pixels from a SDL_Texture (to check whether the texture is transparent at a given point).

I’m creating the textures with SDL_TEXTUREACCESS_STREAMING flag. When I need to read the pixel, I lock the texture, access the pixel and unlock. This works fine with Direct3D renderer, but it doesn’t work with OpenGL renderer, because GL_LockTexture doesn’t seem to download existing texture from video memory, so SDL_LockTexture only gives me an empty pixel buffer. Is that an expected behavior? And if it is, what other strategy would you suggest for accessing pixel data of an existing SDL_Texture?

Thank you.

The behavior you’re seeing is unexpected, but is that way for performance to
avoid an extra memory copy in the general case.

If you really need to check the data of a streaming texture, I would
recommend keeping a separate copy of the data locally. Especially if the
area you need to check is constant, just keep that data, or if possible
check it while you’re updating the texture.On Tue, Apr 5, 2011 at 9:48 AM, wrote:

Hello,

I need to read individual pixels from a SDL_Texture (to check whether the
texture is transparent at a given point).

I’m creating the textures with SDL_TEXTUREACCESS_STREAMING flag. When I
need to read the pixel, I lock the texture, access the pixel and unlock.
This works fine with Direct3D renderer, but it doesn’t work with OpenGL
renderer, because GL_LockTexture doesn’t seem to download existing texture
from video memory, so SDL_LockTexture only gives me an empty pixel buffer.
Is that an expected behavior? And if it is, what other strategy would you
suggest for accessing pixel data of an existing SDL_Texture?

Thank you.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and CEO, Galaxy Gameworks