@Roxas
Thanks for testing it. I'm glad it works in DBPro. From your results, there is not as big an improvement as it is in DBC, but still an improvement none the less!
Wow, DBPro must natively be so much faster than DBC. I redid the test using just a 20x20 area and GDI did it in 6ms and POINT took 7090! Like I said, I couldn't wait for POINT to finish 200x200. Just extrapolating forward, that would be over an hour with this test using POINT in DBC.
[EDIT]
I just realized that I have the sync rate set to 60 in the example. Setting it to 0 improves the perforamnce of the POINT command, but not by much. The GDI function is still faster.
And I almost forgot to show that the GDI command returns the same value as POINT. Just point the mouse at different colored objects on the screen to show the color values.
(NOTE: I think part of the reason POINT in DBC is so slow is because it automatically calls SYNC when it is used. So if you have it in a loop, it calls SYNC everytime it is encountered. Try commenting out cpoint=point(mousex(),mousey()) in the example. )
sync on
sync rate 0
set window on
autocam off
randomize timer()
for obj=1 to 100
make object cube obj,25
position object obj,rnd(500)-100,rnd(100)-50,rnd(1000)
color object obj,rgb(rnd(255),rnd(255),rnd(255))
next obj
gosub _load_dlls
mem=1
ink rgb(255,255,255),0
do
cpixel=gdi_point(user32,gdi32,hwnd,mousex(),mousey(),mem)
cpoint=point(mousex(),mousey())
text 0,0,"POINT command result = "+str$(cpoint)
text 0,20,"GDI_POINT function result = "+str$(cpixel)
loop
end
rem procedures and functions to for the winapi calls
_load_dlls:
user32=1
gdi32=2
load dll "user32.dll",user32
load dll "gdi32.dll",gdi32
hwnd=call dll(user32,"GetActiveWindow")
return
function gdi_point(user32,gdi32,hwnd,xpos,ypos,mem)
if memblock exist(mem)=0
make memblock mem,4
endif
rem get hwnd to retrieve the DC and the pixel of the window
hdc=call dll(user32,"GetDC",hwnd)
cpixel=call dll(gdi32,"GetPixel",hdc,xpos,ypos)
call dll user32,"ReleaseDC",hwnd,hdc
rem since the pixel color is returned by getpixel in R G B order,
rem I swap bytes 0 and 2 for reading back the DWORD (B G R) for dbc
rem right now this limits the screen depth to 32 bits.
write memblock dword mem,0,cpixel
temp=memblock byte(mem,0)
write memblock byte mem,0,memblock byte(mem,2)
write memblock byte mem,2,temp
cpixel=memblock dword(mem,0)
endfunction cpixel
Enjoy your day.