[SDL2] Texture with alpha and mouse cursor over it |
Naith
|
It is possible to retrieve the pixels of a SDL_Texture, but it's a costly process and you shouldn't do it. What you should do instead is checking the pixel color of the surface that is created before the texture is created. This means that you'll have to save the SDL_Surface in some way and destroy it when the SDL_Texture is destroyed. One way you can achieve this is by having both the SDL_Surface and the SDL_Texture inside a struct and destroy everything when the program ends.
Example code below:
Then, when the program is executed, check if the mouse pointer is inside the texture quad (see struct above) and if it is, retrieve the pixel color from the surface and then do whatever you want with the pixel information you retrieve. Example code for retrieving the pixel color of a SDL_Surface:
And example code on how to use it:
Hope it helps |
|||||||||||||||||
|
Rang
|
In this moment i use same method as you describe, but memory we use x2 (RAM + GPU).
I thought use SDL_Rect (or other structure) for saving borders\points of borders for visible part, but this is more complicated code. I already have images, and need dynamicly creating this zones. |
|||||||||||
|
[SDL2] Texture with alpha and mouse cursor over it |
Jonny D
|
If the use is rare, like on user input, then the performance penalty of reading the pixels directly from the texture might be acceptable.
It also depends on what you want to use this info for. In some cases, you can do everything you need to do in a shader. Jonny D On Thu, Aug 25, 2016 at 12:43 PM, Rang wrote:
|
|||||||||||||
|
Re: [SDL2] Texture with alpha and mouse cursor over it |
Rang
|
I need highlight the object and handle click events. Images like buttons. But they not have rectangle forms.
|
|||||||||||||||
|