Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting Line _RGB colours
#11
(11-03-2024, 02:33 AM)SMcNeill Wrote:
(11-03-2024, 01:02 AM)bplus Wrote: Henry is right for _RGB() you may only need long because you don't have transparent colors.

_Unsigned Long covers all color bases _RGB() and _RGB32(). I recommend _RGB32() because it is very versatile.

LONG and _UNSIGNED LONG both cover all your color valules.

That said, you should *ALWAYS* use _UNSIGNED LONG, as several of the QB64 Functions return _UNSIGNED LONG values and your LONG colors won't match them.  Let me give the simplest of demos here:

Code: (Select All)
Screen _NewImage(640, 480, 32)
Dim l As Long, ul As _Unsigned Long

l = _RGB(200, 200, 200)
ul = l

Print "As you can see, the hex values of these numbers are the same,"
Print "but their decimal values are quite different."
Print l, Hex$(l)
Print ul, Hex$(ul)

Line (200, 200)-(300, 300), l, BF
Line (400, 200)-(500, 300), ul, BF
Print
Print "As you can tell from our boxes, the colors are EXACTLY the same."
Print Point(250, 250), Point(450, 250)
Print "But the problem is, POINT returns FLOAT values (to match UNSIGNED LONG)."
Print "So when you try TRUE/FALSE comparisons, you get:"
Print "IF POINT(250,250) = "; l; "THEN.... ";
If Point(250, 250) = l Then Print "TRUE" Else Print "FALSE"
Print "IF POINT(450,250) = "; ul; "THEN.... ";
If Point(450, 250) = ul Then Print "TRUE" Else Print "FALSE"


Now, in your SUB here, it doesn't matter as you're not making use of POINT or other color functions that return an unsigned long value to you.  Still, I wouldn't recommend to use a LONG value for colors.  *ALWAYS* use an _UNSIGNED LONG.  Get in the habit of  *always* using an unsigned long.  *ALWAYS*, when using 32-bit colors.

Otherwise, it will eventually come to bite you in the butt, and I will end up laughing at you and pointing to the 5217 posts like this one that I've repeated over and over and over, over the years.  Big Grin

There's no reason to use LONG values.  They save no memory.  Don't process any faster.  They have no bonus to efficiency or anything else.  AND, they can break your code as QB64PE functions return UNSIGNED LONG values back to you, and not LONGs.

Thanks Steve. Good to know!
But I tend to be a pretty sloppy coder (heck, it's only me that ends up using it anyway). If a GoTo works, or an unidentified variable-type works, I generally use them, then maybe "tidy up" later. Having said that, I enjoy trying out more sophisticated things when I'm "practising".
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply




Users browsing this thread: 1 Guest(s)