Pixel Color Detection, pleeeease help!
Ok. The thing is I have been porgramming with QB and VB for a long time. But Basic is in many ways soo much simpler then C.
Now I need the command point(x,y) from Basic to C
Point(x,y) does this thing:
i.e. if the color of the pixel at 200,123 in screen 13 is white(15) then if you do like this(in Qbasic):
screen 13
k = point(200,123)
Print k
then the result is this:
15
I need it for my pixel collision detection engine.
Please help me. I''m greatful for any help.
MindWipe
"To some its a six-pack, to me it's a support group."
You''re going to need to give us more info. What API''s are you using? What OS/CPU (I suppose you''re using Windows)?
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Well if you're using a 16-bit surface, you can get the value by...
WORD p = *(destination + (pitch*y) + (2*x));
Then just mask out the R,G,B values based on your pixel type.
Edited by - Buster on July 14, 2000 4:14:59 PM
WORD p = *(destination + (pitch*y) + (2*x));
Then just mask out the R,G,B values based on your pixel type.
Edited by - Buster on July 14, 2000 4:14:59 PM
I''m using DJGPP With Allegro =)
"To some its a six-pack, to me it's a support group."
screen 13
gets into mode 13h which is for DOS..
here''s how it works...
this code is for TC++...
if you want to test whether the pixel at that specific location is 15 (meaning WHITE if you dont tamper with the palette) or not then you''d do something like this:
if (GetPixel(200, 123) == 15)
{
// pixel at location (x=200; y=123) IS white
}
else
{
// pixel at location (x=200; y=123) is NOT white
}
Hope this helps!
..-=gLaDiAtOr=-..
gets into mode 13h which is for DOS..
here''s how it works...
this code is for TC++...
#include <stdio.h>#include <conio.h>unsigned char far* vga = (unsigned char far *) 0xA0000000L;void SetMode(unsigned short mode){ asm { mov ax, [mode] int 10h }}unsigned char GetPixel(int x, int y){ return vga[(y<<8)+(y<<6)+x];}int main(){ unsigned char k; // declare k as a byte SetMode(0x0013); // screen 13 k = GetPixel(200, 123); // k = point(200,123) SetMode(0x0003); // go back to text mode printf("%u", (unsigned int) k); //Print k getch(); return 0;}
if you want to test whether the pixel at that specific location is 15 (meaning WHITE if you dont tamper with the palette) or not then you''d do something like this:
if (GetPixel(200, 123) == 15)
{
// pixel at location (x=200; y=123) IS white
}
else
{
// pixel at location (x=200; y=123) is NOT white
}
Hope this helps!
..-=gLaDiAtOr=-..
whyt didnt you say you were using DJGPP earlier too lazy to write the DJGPP equivalent code right now... here is a link that will help you with graphics/game programming with DJGPP. Click Here
..-=gLaDiAtOr=-..
..-=gLaDiAtOr=-..
THANKS!!! Love this forum, you allways get help with anything.
Thanks again
MindWipe
Thanks again
MindWipe
"To some its a six-pack, to me it's a support group."
also, there is documentation that comes with Allegro. it spells all of these type of things. usually you can expect Allegro to have functions like these.
JoeMont001@aol.com www.polarisoft.n3.net
JoeMont001@aol.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement