![]() |
|
just another getpixel question |
Albin Engström
Member #8,110
December 2006
![]() |
I have a little getpixel problem: the following condition crashes.. if(_getpixel32((BITMAP*)datafiles::sprites_enemies[game::enemies::enemies[enyNR].visual].dat, game::enemies::enemies[enyNR].Xpos - game::projectiles::projectiles[proNR].Xpos, game::enemies::enemies[enyNR].Ypos - game::projectiles::projectiles[proNR].Ypos) != makecol(255, 0, 255))
BUT if i replace != with == it "works"... and it doesn't respond like i want it to do stuff doesn't execute even if the pixel I'm trying to check is (255, 0, 255). getpixel looks up bitmaps with all color depths right? i can't figure out what's wrong! |
Matthew Leverton
Supreme Loser
January 1999
![]() |
_getpixel32 does not do any bounds checking, so it can crash if you use it improperly, but... Quote:
BUT if i replace != with == it "works"... If that's true, then the crash is in your dostuff() call. |
Albin Engström
Member #8,110
December 2006
![]() |
oops, "(_getpixel32((BITMAP*)datafiles::sprites_enemies[game::enemies::enemies[enyNR].visual].dat," strange... it no longer crashes. - -'.. but the more important problem still exists. |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Are you sure the color depth of the bitmap matches the screen's? And of course, are you sure the pixel is 255,0,255? |
Albin Engström
Member #8,110
December 2006
![]() |
Matthew Leverton said: Are you sure the color depth of the bitmap matches the screen's?
i thought bitmaps where converted into the screens color depth? Matthew Leverton said: And of course, are you sure the pixel is 255,0,255? quite sure about that, when drawing them to the buffer the pixels doesn't get drawn and in 32 and 24 color depth isn't that an automatic event trigged by a pixel with maximum red and blue value resp minimum green when using draw_sprite()? |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Quote: i thought bitmaps where converted into the screens color depth? They are, if you load them after you set the graphics mode. |
Albin Engström
Member #8,110
December 2006
![]() |
Matthew Leverton said: They are, if you load them after you set the graphics mode. And that's what i do. :/ |
X-G
Member #856
December 2000
![]() |
Note that in 32-bit mode the fourth byte - the alpha value - is relevant too. (255, 0, 255, 255) and (255, 0, 255, 0) are very different colors according to the system. -- |
Richard Phipps
Member #1,632
November 2001
![]() |
Are the positions you passing within the image correct? |
Albin Engström
Member #8,110
December 2006
![]() |
Z-G said: Note that in 32-bit mode the fourth byte - the alpha value - is relevant too. (255, 0, 255, 255) and (255, 0, 255, 0) are very different colors according to the system. Noted. But am i not checking only for the other values? Richard Phipps said: Are the positions you passing within the image correct? They probably are: i have a condition which checks if the point I'm trying to read is inside the bitmap (in this case it's an enemy's bitmap and the action point of a projectile) if it is inside it should be destroyed which it is (not including the second condition), the second condition is the getpixel dependent one:
and it always executes (if the first condition is true). //sorry for the unreadable stuff.. if(game::projectiles::projectiles[proNR].Xpos > game::enemies::enemies[enyNR].Xpos && game::projectiles::projectiles[proNR].Xpos < game::enemies::enemies[enyNR].Xpos + ((BITMAP*)datafiles::sprites_enemies[game::enemies::enemies[enyNR].visual].dat)->w && game::projectiles::projectiles[proNR].Ypos > game::enemies::enemies[enyNR].Ypos && game::projectiles::projectiles[proNR].Ypos < game::enemies::enemies[enyNR].Ypos + ((BITMAP*)datafiles::sprites_enemies[game::enemies::enemies[enyNR].visual].dat)->h )
Richard Phipps said: Try finding out what the read values are.. Good idea, i will. Thanks for your help! |
X-G
Member #856
December 2000
![]() |
Quote:
Noted. But am i not checking only for the other values? You're comparing a 32-bit integer to another 32-bit integer. Of course the entire thing is being taken into account. -- |
Albin Engström
Member #8,110
December 2006
![]() |
Quote: You're comparing a 32-bit integer to another 32-bit integer. Of course the entire thing is being taken into account. I guess that makes sense in a way.. but how do i check the alpha value? _makecol32 still only accepts 3 values. :/ |
X-G
Member #856
December 2000
![]() |
-- |
Albin Engström
Member #8,110
December 2006
![]() |
X-G said: makeacol32 ... ><. thanks Is alpha 255 solid or is it 0?. I'm going to check what values i get. |
Tobias Dammers
Member #2,604
August 2002
![]() |
I think what you want to compare is the non-alpha part of the pixel value. Since you use magic pink, the alpha channel isn't interesting at all (magic pink pixels are masked out regardless of alpha: in allegro, the alpha channel is only used for the alpha blender). if (getpixel(bmp, x, y) & makeacol32(255, 255, 255, 0) == makeacol32(255, 0, 255, 0)) do_stuff();
--- |
Kris Asick
Member #1,424
July 2001
|
Note that getpixel() is based on the pixel format of the bitmap you are getting the pixel from, while makecol() is based on the current screen format. If you want your routine to be universal, you need to check the bitmap depth before comparing and the use the appropriate makecol#() command. For instance: source_colour = getpixel(my_bitmap); switch (bitmap_color_depth(my_bitmap)) { case 8: test_colour = makecol8(255,0,255); break; case 15: test_colour = makecol15(255,0,255); break; case 16: test_colour = makecol16(255,0,255); break; case 24: test_colour = makecol24(255,0,255); break; case 32: { source_colour = makecol24(getr32(source_colour),getg32(source_colour),getb32(source_colour)); test_colour = makecol24(255,0,255); break; } } if (source_colour == test_colour) // Do Stuff Also, makecol() takes a little CPU time. (Not much, a lot more if it's doing 8-bit conversions.) What you should do if you're using constants in makecol() is to get the values you're going to compare immediately after entering a graphics mode and store them into variables. That way, you can skip calling makecol() every time you want to make the comparison. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
Albin Engström
Member #8,110
December 2006
![]() |
I got it to work after a while, the problem was simple as i didn't check for the right pixels :/. if(getpixel((BITMAP*)datafiles::sprites_enemies[game::enemies::enemies[enyNR].visual].dat, (game::enemies::enemies[enyNR].Xpos + ((BITMAP*)datafiles::sprites_enemies[game::enemies::enemies[enyNR].visual].dat)->w) - game::projectiles::projectiles[proNR].Xpos, (game::enemies::enemies[enyNR].Ypos + ((BITMAP*)datafiles::sprites_enemies[game::enemies::enemies[enyNR].visual].dat)->h) - game::projectiles::projectiles[proNR].Ypos) != makecol(255, 0, 255))
Thanks for all your help!! |
|