Archived

This topic is now archived and is closed to further replies.

Pixel Color Detection, pleeeease help!

This topic is 6360 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
screen 13

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=-..

Share this post


Link to post
Share on other sites
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=-..

Share this post


Link to post
Share on other sites