_SETALPHA Question - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: _SETALPHA Question (/showthread.php?tid=2049) Pages:
1
2
|
_SETALPHA Question - TerryRitchie - 09-29-2023 I seem to be having issues with _SETALPHA. When I initially set a color to a transparency level with _SETALPHA I can't change it to another transparency level later on. I'm certain I've done this in the past. I've found a work-around using a temporary image but I'm sure this is not needed ... or is it? See my code below and please explain to me why the first block of code is not working. A bug? Brain-fart on my part? Code: (Select All) '| RE: _SETALPHA Question - DSMan195276 - 09-29-2023 The alpha value of the color provided to `_SetAlpha` has to match what is already there. IE. After your first call to `_SetAlpha`, all the red pixels no longer have 255 alpha, and as a consequence they are not equal to `_RGB32(255, 0, 0)` which does (That's the same as `_RGBA32(255, 0, 0, 255)`). You can get around this issue with the `TO color` option on `_SetAlpha`. Ex. I haven't tested it, but this should work: `_SetAlpha c, _RGBA32(255, 0, 0, 0) TO _RGBA32(255, 0, 0, 255), RedBox`. I'm not 100% sure but I think the `_CopyImage` version works because it blends the images together and the resulting pixels still have 255 alpha, meaning the next `_SetAlpha` works as intended. RE: _SETALPHA Question - TerryRitchie - 09-29-2023 Well son of a pup that worked. Thank you. The Wiki entry for _SETALPHA needs to be rewritten to make this more clear. I'm also going to need to revise Lesson 14 of the tutorial to reflect this information. Code: (Select All) '| RE: _SETALPHA Question - TerryRitchie - 09-29-2023 You know, I've been thinking about this. Having to work with _RGBA seems like overkill for something as simple as wanting to fade an individual color. Why couldn't a statement such as _SETALPHA Level%, _RGB32(255, 0, 0), Image& automatically include all of the alpha levels from 0 to 255? As it stands now you either need to enter a range with _RGBA as you have shown or manually keep track of every level change at each step in the software. RE: _SETALPHA Question - SMcNeill - 09-29-2023 SETALPHA Level%, _RGBA32(255, 0, 0, 0) TO _RGBA32(255,0,0,255), Image& More flexibility than just assuming "do them all". What if you only wanted to change a single value's alpha? RE: _SETALPHA Question - TerryRitchie - 09-29-2023 (09-29-2023, 05:15 AM)SMcNeill Wrote: SETALPHA Level%, _RGBA32(255, 0, 0, 0) TO _RGBA32(255,0,0,255), Image&Then that is where _RGBA32 would come into play. I definitely see the benefit of controlling individual alpha levels. What I envision is when _SETALPHA sees _RGB32 it assumes all alpha levels for the given color instead of the default 255 that is assumed with _RGB32. _SETALPHA 0, _RGB32(255, 0, 0), Image& ' all alpha levels of red set to 0 _SETALPHA 0, _RGBA32(255, 0, 0, 255), Image& ' only alpha level 255 of red set to 0 I don't know, perhaps I'm overthinking this. RE: _SETALPHA Question - SMcNeill - 09-29-2023 One thing to remember, _RGB32 and RGBA32 just return a simple number for us to use. Code: (Select All) PRINT _RGBA32(255, 0, 0, 255) All the above prints the same value for us -- 4,294,901,760 -- which represents the numeric value of "ALL Red and FULL Alpha". Now, how is _SETALPHA going to recognize that that number in question came from _RGB, _RGBA, or some other formula? Is it simply expected to assume that any time someone uses the value &HFFFF0000, that they intend to change the whole RGB spectrum for that color value, rather than just for &H00FF0000 TO &H11FF0000? How the heck would they ever just change the alpha for &HFFFF0000 all by itself, if that's the *only* value they wanted to change?? RE: _SETALPHA Question - SMcNeill - 09-29-2023 You can always do something like this, if you really just need to change alpha for a whole range at once for a _RGB color: Code: (Select All)
RE: _SETALPHA Question - DSMan195276 - 09-29-2023 (09-29-2023, 05:01 AM)TerryRitchie Wrote: You know, I've been thinking about this. Having to work with _RGBA seems like overkill for something as simple as wanting to fade an individual color.Personally I kinda agree, I think the marginal amount of flexibility gained is offset by it being extremely unintuitive that `_SetAlpha` still checks the original alpha value. I don't think I've ever seen someone use the ability to target specific alphas and this isn't the first time someone has run into this confusion and asked on this forum. That said, we can't change it now. I think personally it's a bit of a silly command since it's just a big loop (so it's expensive), it's not something you want to be using often anyway. RE: _SETALPHA Question - TerryRitchie - 09-29-2023 (09-29-2023, 05:11 PM)DSMan195276 Wrote:No, it's not very intuitive but I do see the need to allow the setting of individual alpha channel values. Instead of changing or adding to the _SETALPHA statement I think a better explanation in the Wiki would be a good alternative for now.(09-29-2023, 05:01 AM)TerryRitchie Wrote: You know, I've been thinking about this. Having to work with _RGBA seems like overkill for something as simple as wanting to fade an individual color.Personally I kinda agree, I think the marginal amount of flexibility gained is offset by it being extremely unintuitive that `_SetAlpha` still checks the original alpha value. I don't think I've ever seen someone use the ability to target specific alphas and this isn't the first time someone has run into this confusion and asked on this forum. I'm currently reworking the _SETALPHA section in Lesson 14 of the tutorial. I completely had the explanation and example FUBARed because of the confusion I had. Yours and Steve's points and examples have set me straight. |