sdl2
sdl2 copied to clipboard
Get Pixel information from a Surface
I would like to get the pixel information of a surface (i.e. I have a surface and coordinates (x,y), I want to get the color of that pixel.
I don't think it is possible with sdl2 bindings as now. Or am I wrong?
@Piepoli The type of a Surface is:
data Surface = Surface (Ptr Raw.Surface) (Maybe (MSV.IOVector Word8))
I think the IOVector of Word8 might be the pixels data. I might be wrong tho.
There's also surfacePixels :: MonadIO m => Surface -> m (Ptr ()), but now I'm wondering what the IOVector @Rydgel mentioned is for. As far as I know when you call createRGBSurfaceFrom you need to pass the IOVector with pixel data.
Apparently there are two 'types' of surfaces, managed and unmanaged. When you use createRGBSurfaceFrom you get managed surface, and the IOVector is there, and if you use createRGBSurface it's Nothing.
So yeah, it's better to use surfacePixels as @BartAdv mentioned.