Re: reading pixels from a TARGET texture

"ancientcc" <[email protected]>
Newsgroups gmane.comp.lib.sdl
Message-ID <[email protected]>
* do you means that the current GL_RenderReadPixels does not work ?

------------------

Yes, If you want to read pixels from SDL_TEXTUREACCESS_TARGET's SDL_texture,
current GL_RenderReadPixels will work  unsuccessfully. Of course,
GL_RenderReadPixels is corresponding to Open GL, for example Microsoft
Windows with SDL_WINDOW_OPENGL. If your app use OpenGL ES2, for example iOS
and Android, you require modify GLES2_RenderReadPixels. Their modification
are the same.

 

* the doc says "WARNING: This is a very slow operation, and should not

  be used frequently." Is this still the case with your version ?

------------------

This still the case with my version, modify don't touch that. You should
absolutely not use SDL_RenderReadPixels(), ever, for anything other than
screenshots and the like.

 

* Ideally I'd rather use an "official" method. Will these changes be

  included in the official SDL2 ?

------------------

I think that next official SDL2 will fix this BUG. Of course, I hope to
patch code to official SDL2, especial BLE.

 

 

If you want read pixels from tex(it's type must be
SDL_TEXTUREACCESS_TARGET), you can write below code.

int RenderReadPixels (SDL_Renderer* renderer, const SDL_Rect* rect,

                          Uint32 format, void* pixels, int pitch,
SDL_Texture* tex)

{

   // assume current target is NULL.

   int result ;

   SDL_Rect dst = {0, 0, rect->w, rect->h} ;

   // Since want to read from tex, should set it to target.

   SDL_SetRenderTarget(renderer, tex) ;

   // pitch = dst.w * byte of one pixel. not tex'width * byte of pixel.

   result = SDL_RenderReadPixels(renderer, &dst, format, pixels, pitch);

 

   // recover target to NULL.

   SDL_SetRenderTarget (renderer, NULL) ;

   return result ;

}

_______________________________________________
SDL mailing list
[email protected]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.