Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / The POINT() function seems not to work properly...

Author
Message
Starshyne Emir
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 18th Mar 2020 20:18
How can I use the POINT() function to check properly the color of a point on screen (or on any bitmap?).
Do I need to lock pixels or do something else?
I know how to use RGBR(), RGBG() and RGBB() but always when I compare the colors I retrieve with the colors I stored inside variables when generating the original bitmap, they seem to be different and I can't use them to calculate collisions or terrain features as water or holes.

I'll try to exemplify here, since I deleted my test code. I will not detail how the bitmap is drawn to save time, but I'll try to make clear what I mean:

color1 = rgb(r1,g1,b1)
color2 = rgb(r2,g2,b2)
CREATE BITMAP n,w,h
(draw game level using color1 for ground and color2 for walls)
GET IMAGE n,w,h,1
DELETE BITMAP n
SPRITE n,0,0,n
SET SPRITE n,1,1
SIZE SPRITE n,SCREEN WIDTH(),SCREEN HEIGHT()
HIDE SPRITE

SYNC ON
SYNC RATE 60
DO
CLS
x and y are where I am in screen
PASTE SPRITE n,0,0
r = rgbr(POINT(x,y))
g = rgbg(POINT(x,y))
b = rgbb(POINT(x,y))
coloratposition = rgb(r,g,b)
IF coloratposition = color1 THEN do this
IF coloratposition = color2 THEN do that
SYNC
LOOP

Sometimes it works, sometimes it doesn't. Some colors match, some colors don't match. I get the image without filtering or scaling it to avoid distortions, so, I can't figure out what's going on.

God is real - except if declared as integer.
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 19th Mar 2020 04:19


That works just fine... well as find as DBP does on Windows 10 anyway.
I'd look over your code more closely to see what you're doing weirdly, but my friend is bugging me to play Fortnite.

Still I have a feeling the issue is with what you're trying to do.
Point( ) mind will always Default to the Currently Active Bitmap (if it's On-Screen or Off-Screen)... and do that, you can get the Bitmap Pointer; but the Pitch won't be available to automatically get... so I did add a comment to show how to calculate it (Safely)

Basically each Pixel is a 4 Byte Alignment, but as 32-bit is the Highest Format DBP supports; this should really only ever be 4 Bytes
Starshyne Emir
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 19th Mar 2020 16:57
Thanks for the feedbacki, pal.
I'll work on a code and if I find something working strangely, I'll share it in here.
God is real - except if declared as integer.
Hannibal
17
Years of Service
User Offline
Joined: 5th Mar 2007
Location:
Posted: 9th Apr 2020 22:12
I have had some issues with point too, I wound up having to make bmp's and see what color value the point command was returning (different to expected and those made in photoshop) :-(
Starshyne Emir
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 24th Jun 2020 06:40
Guess I found the issue.
The RGB function is to blame.
RGB(0,0,0) isn't 0. It operates differently and when I paint a pixel with 0 to represent black and call rgb(0,0,0) to test if it is black, obviously it says NO.
Easily solved if instead of using 0 to represent black pixels I use only rgb(0,0,0). Then it works fine.
God is real - except if declared as integer.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 24th Jun 2020 15:23
The RGB function is setting all 8 bits of the alpha channel. This will correct that in your example code.

Hannibal
17
Years of Service
User Offline
Joined: 5th Mar 2007
Location:
Posted: 29th Jun 2020 20:39
That's very good to know, cheers

Login to post a reply

Server time is: 2024-03-28 10:19:07
Your offset time is: 2024-03-28 10:19:07