Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting Line _RGB colours
#10
(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.
Reply


Messages In This Thread
Setting Line _RGB colours - by PhilOfPerth - 11-03-2024, 12:46 AM
RE: Setting Line _RGB colours - by bplus - 11-03-2024, 12:53 AM
RE: Setting Line _RGB colours - by PhilOfPerth - 11-03-2024, 12:56 AM
RE: Setting Line _RGB colours - by ahenry3068 - 11-03-2024, 12:54 AM
RE: Setting Line _RGB colours - by PhilOfPerth - 11-03-2024, 01:06 AM
RE: Setting Line _RGB colours - by bplus - 11-03-2024, 01:02 AM
RE: Setting Line _RGB colours - by SMcNeill - 11-03-2024, 02:33 AM
RE: Setting Line _RGB colours - by PhilOfPerth - 11-03-2024, 05:37 AM
RE: Setting Line _RGB colours - by bplus - 11-03-2024, 01:08 AM
RE: Setting Line _RGB colours - by PhilOfPerth - 11-03-2024, 01:32 AM
RE: Setting Line _RGB colours - by bplus - 11-03-2024, 01:29 AM



Users browsing this thread: 2 Guest(s)