Closed sigzegv closed 3 years ago
Hi @sigzegv, you can pass the address of the first item of an array such as unsafe.Pointer(&pixels[0])
. So pixels
can be declared like var pixels = make([]byte, width*height*channels)
.
Ty, this works well I am not familiar with unsafe.pointer type, so question now is, am I forced then to use the texture's Update method to reaffect the pixels, or is there a way then to redirect values to the texture directly ?
@sigzegv You have an example here https://play.golang.org/p/14JFZvpukGK, ReadPixels is a slow operation.
Do you think it's better (and quicker) to maintain a Surface (that will be updated some times) at same time and then push it to a new texture when needed to ?
Depends on what you want to do, check migration guide https://wiki.libsdl.org/MigrationGuide, and If your game wants to blit surfaces to the screen/If your game wants to do both
, but yes, that is the recommended method for what you want.
thank you very much it's clear now.
How am I supposed to use renderer.ReadPIxels pixel parameter ?
I am doing this
but I just get (unsafe.Pointer)(nil) as response. So this mean my pixels array wasn't filled.
I would like to be able to load pixels data and then convert it to either []byte or *uint32.