Hi!
I am attempting to write an sub-routine that will read a pixel from a bitmap based on the position of the mouse and give me a return value based on the color of that pixel. here is what I have so far:
function get_pixel_color()
{var x_coord = integer(mouse_pos.x*(bmap_width(my_bmap)/screen_size.x));
var y_coord = integer(mouse_pos.y*(bmap_height(my_bmap)/screen_size.y));
var pixel;
COLOR* pixel_color;
if(x_coord>bmap_width(my_bmap)||x_coord<0) { return(-1); }
if(y_coord>bmap_height(my_bmap)||y_coord<0) { return(-1); }
bmap_lock(my_bmap,0);
pixel = pixel_for_bmap(my_bmap,x_coord,y_coord);
bmap_unlock(my_bmap);
pixel_to_vec(pixel_color,NULL,8888,pixel);
if(pixel_color.red)
{ if(pixel_color.red>245&&pixel_color.red<255)
{ return(0);
}
}
return(-1)
}
The routine works fine - x_coord and y_coord are always co-ordinates within the bmap and pixel_for_bmap() is returning the pixel it is supposed to. However, when I execute the pixel_to_vec() command, the game crashes.
I tested the return value from bmap_lock and it is 8888, indicating that it is locking a 32-bit tga file with an alpha channel - which is curious becuse the bmap im reading from was created in photshop and saved as a 24-bit tga file with no alpha channel.
Am I feeding pixel_to_vec a bad pixel value? or maybe im feeding some bad value for one of the other parameters? Is bmap_lock misreading the bmap and thats whats causing problems? why would pixel_to_vec() crash the engine like this?
Last edited by Caermundh; 11/30/10 05:39.