Page 1 of 2

scanning for pixel colors in fullscreen window

Posted: Wed Jul 19, 2006 11:00 pm
by ChebbyShabby
basically i want to scan the whole fullscreen window pixel-by-pixel until a certain colour is reached (red, in this case).

i have the following code:

Code: Select all

If OpenScreen(800,600,32,"") 
  Repeat
    FlipBuffers() 
    ClearScreen(0,0,0)
    
    StartDrawing(ScreenOutput())
      Box(400, 300, 100, 100, RGB(255, 0, 0))
    StopDrawing()
    
    For y = 0 To 600
      For x = 0 To 800: xx+1: If xx=800: xx=0: yy+1: EndIf: Next
      If yy=600: yy=0: EndIf    
    Next
    
    C = GetPixel_(GetForegroundWindow_(), xx, yy)
      
    StartDrawing(ScreenOutput())
      DrawText(Str(C))
    StopDrawing()
    
    ExamineKeyboard() 
  Until KeyboardPushed(#PB_KEY_ESCAPE) 
  
EndIf
however, GetPixel_() keeps returning -1, why is this? and how can i fix it?

Posted: Thu Jul 20, 2006 12:16 am
by Dare
Hi ChebbyShabby,

I dont know if GetPixel_(GetForegroundWindow_( works with screens, but someone smarter than I can confirm that. You could try with Point( to see what happens.

It looks like you do the loops for no reason other than to increment xx,yy until you reset them to 0 and then check the pixel (at 0,0) outside of the loop. That may not be what you want.

Also would going from 0 to 800 and 0 to 600 not do 801 and 601 hits respectively?



PS: Didn't run it, too lazy to load 3.94, so if I am talking out the wrong oriface just ignore this. :)

Posted: Thu Jul 20, 2006 2:45 am
by netmaestro
GetPixel_() works with the hardware device context of the given window. The handle gets you halfway there, but you need the hDC to provide the function with all it needs:

Code: Select all

color=GetPixel_(GetDC_(GetForegroundWindow_()), 100,100)
For a fullscreen app, you get the dc another way:

Code: Select all

color=GetPixel_(GetDC_(ScreenID()),100,100)
and for both environments you can also do the tried and true:

Code: Select all

hDC = StartDrawing(..... StopDrawing()

Posted: Thu Jul 20, 2006 1:18 pm
by ChebbyShabby
thanks both of you... it helpted
but now i'm having trouble scanning for pixels on the screen

how would i go about a fast way of scanning every pixel on screen? any ideas?

Posted: Thu Jul 20, 2006 3:20 pm
by Kale
ChebbyShabby wrote:thanks both of you... it helpted
but now i'm having trouble scanning for pixels on the screen

how would i go about a fast way of scanning every pixel on screen? any ideas?
Use the direct video memory access commands. I cant give example yet im at work. :P

Posted: Thu Jul 20, 2006 8:16 pm
by ChebbyShabby
thanks kale... but i'm still confused :(

Posted: Thu Sep 14, 2006 5:41 pm
by K.puts
Hi, is it a Color-Bot you try to prog ?

Posted: Sat Sep 30, 2006 5:24 pm
by ChebbyShabby
yeah i'm making a bot. sorry about the late reply

Posted: Wed Oct 04, 2006 4:28 am
by White Eagle
Hi, is it a Color-Bot you try to prog ?
Could one of you youngsters please explain to the old man what a "Color-Bot" is?

Posted: Wed Mar 28, 2007 5:33 pm
by K.puts
Oh sorry, wasn't here for a long, long time. too long.

A color bot is a program for games, p.e. 3d shooters, that detects the color of textures(pixels) and aims on it automaticly, so u can hit ur targets.

u can use the color of of an enemy face or something like that, some detail on an enemy uniform...

i have tested a prog with "enemy territory" and "warrock", the problem is the lightning in 3d games, so pixels don't have the same color all the time, it's a matter of ur position and range.

so the color bot is absolutely ineffective.
but, was a nice try ;-)

for anyone else who wants to code such a bot, don't use _getpixel(),
its not fast enough, you can only scan ~50-100² pixels per second with a 1,8 ghz processor.
you have to use direct_x or opengl functions for that, but its realy hard stuff to extraxt the r,g,b information, i gave up on this :-(.

Posted: Wed Mar 28, 2007 6:10 pm
by Fred
There is a DrawingBuffer() command to have raw access to the pixel buffer. Here is an old source about direct screen access (courtesy of Va!n) : http://www.purebasic.com/Plasma_DSA.pb

Posted: Thu Mar 29, 2007 11:07 am
by Heathen
K.puts wrote:Oh sorry, wasn't here for a long, long time. too long.

A color bot is a program for games, p.e. 3d shooters, that detects the color of textures(pixels) and aims on it automaticly, so u can hit ur targets.

u can use the color of of an enemy face or something like that, some detail on an enemy uniform...

i have tested a prog with "enemy territory" and "warrock", the problem is the lightning in 3d games, so pixels don't have the same color all the time, it's a matter of ur position and range.

so the color bot is absolutely ineffective.
but, was a nice try ;-)

for anyone else who wants to code such a bot, don't use _getpixel(),
its not fast enough, you can only scan ~50-100² pixels per second with a 1,8 ghz processor.
you have to use direct_x or opengl functions for that, but its realy hard stuff to extraxt the r,g,b information, i gave up on this :-(.
I hope you get banned from both games :evil: People like you make me sick, you can't just enjoy a game without ruining it for others can you? I hope you will be one of the people crying on the warrock forum about getting a HW ban :)

Posted: Thu Mar 29, 2007 11:44 am
by Derek
Heathen wrote:I hope you get banned from both games :evil: People like you make me sick, you can't just enjoy a game without ruining it for others can you? I hope you will be one of the people crying on the warrock forum about getting a HW ban :)
A bit harsh. :wink:
But, yeah, what is the point of playing if you don't actually play, why ruin it for others.

Posted: Thu Mar 29, 2007 12:22 pm
by Heathen
Derek wrote:
Heathen wrote:I hope you get banned from both games :evil: People like you make me sick, you can't just enjoy a game without ruining it for others can you? I hope you will be one of the people crying on the warrock forum about getting a HW ban :)
A bit harsh. :wink:
But, yeah, what is the point of playing if you don't actually play, why ruin it for others.
It may sound harsh but it's true. There's nothing worse than someone who get's joy out of taking other's fun away. :? I personally play warrock, and not long ago the game was flooded with kids like this guy who go game to game just destorying it for everyone. Thank god they reactivated punkbuster and the amount of hackers was reduced. I just hope this guy get's caught.

Posted: Thu Mar 29, 2007 12:27 pm
by Kaeru Gaman
yeah. cheating in games is a form of impotence...