scanning for pixel colors in fullscreen window

Advanced game related topics
ChebbyShabby
Enthusiast
Enthusiast
Posts: 121
Joined: Mon Jun 26, 2006 10:47 am

scanning for pixel colors in fullscreen window

Post 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?
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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. :)
Dare2 cut down to size
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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()
Last edited by netmaestro on Fri Jul 21, 2006 4:19 pm, edited 1 time in total.
BERESHEIT
ChebbyShabby
Enthusiast
Enthusiast
Posts: 121
Joined: Mon Jun 26, 2006 10:47 am

Post 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?
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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
--Kale

Image
ChebbyShabby
Enthusiast
Enthusiast
Posts: 121
Joined: Mon Jun 26, 2006 10:47 am

Post by ChebbyShabby »

thanks kale... but i'm still confused :(
K.puts
New User
New User
Posts: 6
Joined: Tue Sep 12, 2006 9:23 pm

Post by K.puts »

Hi, is it a Color-Bot you try to prog ?
ChebbyShabby
Enthusiast
Enthusiast
Posts: 121
Joined: Mon Jun 26, 2006 10:47 am

Post by ChebbyShabby »

yeah i'm making a bot. sorry about the late reply
White Eagle
Enthusiast
Enthusiast
Posts: 215
Joined: Sun Jan 04, 2004 3:38 am
Location: Maryland

Post 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?
K.puts
New User
New User
Posts: 6
Joined: Tue Sep 12, 2006 9:23 pm

Post 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 :-(.
Fred
Administrator
Administrator
Posts: 18384
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post 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 :)
I love Purebasic.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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.
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post 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.
I love Purebasic.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

yeah. cheating in games is a form of impotence...
oh... and have a nice day.
Post Reply