Skip to main content
gamedev.net
🔒 Locked

GUI Pixel Alpha Selection

Started by WOsborn Feb 16, 2007 at 9:49 PM 4 replies 950+ views
Original Post
WOsborn
WOsborn
Im creating a GUI system in DX9. Write now I do a Rectangular selection test to see if im over a button or not. What is the DirectX way of after I know im over an object I would then check the alpha of the texture applied to it to see if I clicked the button. Say the texture on the button is a donut.. I wouldnt want to select it if I would click in the middle hole. Thanks.. WOsborn
dave
dave
Well, this could be a costly operation and i have thought about this for my GUI. The reason it could be costly is because you would end up having to iterate through the pixels of the texture, checking the alpha for each one. My recommended solution is to maybe have each control interact the mouse with itself, but only report whether the mouse was inside it or not. This ofcourse assumes that the main gui object does the rest of the complicated interactions.

I have been thinking about how to interact with more complicated boundaries of controls. Rectangles, rounded rectangles, circles and elipses are all straight forward and since those account for most controls bounds, it might be worth simple having 4 static methods that take the input and the control and do the testing.

Dave
Elias
Elias
I have no direct3d experience at all, so can anyone tell me why it will be necessary to iterate through the whole texture?

I mean, if it's possible to do a rectangular selection test, doesn't that mean that it's possible to know the pixels that must be checked (from the coordinates of the mouse)?
dave
dave
Actually you are correct, you dont need to. I'm tired, heh.

It does however mean that he has to do some fiddly memory stuff to get the 4 bytes for the colour and find the alpha, etc. It also restricts you a bit as to what buttons can look like. Supposing you want a sharp edge button with some shadow around it, all premade in photoshop, you would have a hard time not interacting with the shadow.
Cigguh
Cigguh
Just 'lock' your texture to gain access to the alpha component. I'll suggest you to have a small sized texture for that method (32x32 pixels or even smaller).
Getting pixel could be hard with all these 'pitch' and 'stride' coz of different texture formats so i'd use D3DFMT_A8 or something like that (so only one byte would be pixel's alpha, plus it will work faster ).

For more info about 'lock' function check this:
http://www.toymaker.info/Games/html/blitting.html

Hope it'll help.


EDIT:

I forgot.. Ofcourse 32x32 texture is not your button texture, use it just for you 'click' test only.
i make the game so i be ballin
Endurion
Endurion
The DirectX way is to not use DirectX for this.

You could lock the texture and check the pixel alpha below the mouse. But this breaks the async workflow so should be avoided if possible.

You can store the alpha image in a system buffer and check the pixel in memory. This will turn out way faster.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.