miked
New Member
Posts: 3
|
Post by miked on Nov 7, 2023 12:44:23 GMT
I'm trying to figure out why _BLUE32(pt) is returning zero, when I run the code below.
Can anyone please put me out of my misery and explain what I'm missing?
SCREEN _NEWIMAGE(640, 480, 32)
col = _RGB(86, 155, 53)
FOR w = 100 TO 400
FOR h = 100 TO 400
PSET (w, h), col
NEXT h
NEXT w
pt = POINT(200, 200)
tmp$ = "########## ##########"
PRINT USING tmp$; col; pt, _RED32(pt), _GREEN32(pt), _BLUE32(pt)
|
|
miked
New Member
Posts: 3
|
Post by miked on Nov 7, 2023 12:48:30 GMT
Typical. You ask for help and then you go figure it out!
SCREEN _NEWIMAGE(640, 480, 32) col&& = _RGB32(86, 155, 253) FOR w = 100 TO 400 FOR h = 100 TO 400 PSET (w, h), col&& NEXT h NEXT w pt&& = POINT(200, 200) tmp$ = "########## ##########" PRINT USING tmp$; col&&; pt&&, _RED32(pt&&), _GREEN32(pt&&), _BLUE32(pt&&)
|
|
|
Post by bplus on Nov 7, 2023 13:45:36 GMT
It's NOT a BUG when you don't do something correctly and thus it doesn't turn out as expected.
The correct Type to hold ALL 32 bit Colors is _Unsigned Long, use that type for all your color value Variables. Yes _Integer64 that uses && for suffix will work also but default Single which is the assumed Type if none is Dim or suffixed won't work, nor is Long Type big enough without the _Unsigned extension on the Positive Range.
The suffix for _Unsigned Long is ~& which is all positive integers that's what the ~ does. _Unsigned, ~, so one more bit can be used for extending the positive range.
Anyway your first code post is corrected using ~& suffixes and to play it safe use _RGB32() as opposed to _RGB()
Screen _NewImage(640, 480, 32)
col~& = _RGB32(86, 155, 53) ' ~& is best for color container type and use _rgb32
For w = 100 To 400
For h = 100 To 400
PSet (w, h), col~&
Next h
Next w
pt~& = Point(200, 200) ' ~& is best for color container
tmp$ = "########## ##########"
Print Using tmp$; col~&; pt~&, _Red32(pt~&), _Green32(pt~&), _Blue32(pt~&)
|
|
|
Post by Steve on Nov 9, 2023 16:49:22 GMT
bplus LONG works just fine to hold color values for 32-bit colors. The reason why you want to use an _UNSIGNED LONG, however, is so that your values will match the same as those returned by the internal QB64 commands. For example: SCREEN _NEWIMAGE(640, 480, 32) DIM Red AS LONG, Red2 AS _UNSIGNED LONG Red = _RGB32(0, 0, 255) Red2 = _RGB32(0, 0, 255) PSET (0,0), Red IF POINT(0, 0) = Red THEN PRINT "It matches!" ELSE PRINT "No match?!!" IF POINT(0, 0) = Red2 THEN PRINT "It matches an unsigned long!" ELSE PRINT "No match for unsigned longs??!!" LONG will hold your color value but QB64 returns _UNSIGNED LONG values back to you via POINT and other color commands. When compared directly via an IF, they'll give you negative results as -1 is not the same as 123456789 (or whatever the unsigned value is for that same color).
|
|
|
Post by bplus on Nov 9, 2023 20:36:53 GMT
OK I know the right Type to use for wrong reason I remember some problem with White might have been with Point.
|
|