Recent

Author Topic: How do I read the RGBA values of a pixel from a surface or texture with SDL2?  (Read 2581 times)

semichaud1

  • New Member
  • *
  • Posts: 38
Hi,

How do I read the RGBA values of a specific pixel, at given coordinates x and y, from a surface or texture with SDL2 in Free Pascal?

Thanks.

piXelicidio

  • Newbie
  • Posts: 3
Hi, you can't or shouldn't read pixels from a texture because its on GPU memory.
Only from surfaces:
When you create the surface with (https://wiki.libsdl.org/SDL_CreateRGBSurface) maybe with 32 bits in the deph parameter.
Then it returns an structure (record): https://wiki.libsdl.org/SDL_Surface
There you can get and access anytime the "pixels" pointer.
From that record you need also pitch to make your custom getpixel and setpixel.



metis

  • Sr. Member
  • ****
  • Posts: 300
@semichaud1

and then try it with
SDL_GetDisplayDPI(...);  // Get diagonal, horizontal, vertical DPI
and
SDL_GetRGBA(...); // Get the Pixel's RGBA-Values
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

metis

  • Sr. Member
  • ****
  • Posts: 300
@semichaud1

with 'SDL_RenderReadPixels()' you may get the Pixels from a Texture w/o creating a Surface in Your Code, see:
https://discourse.libsdl.org/t/most-efficient-way-of-getting-render-pixels/27581.
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

 

TinyPortal © 2005-2018