|
pixel_for_bmap???
#226808
09/11/08 11:55
09/11/08 11:55
|
Joined: Aug 2008
Posts: 55 United Kingdom
CdeathJD
OP
Junior Member
|
OP
Junior Member
Joined: Aug 2008
Posts: 55
United Kingdom
|
Hi there, its seems Lite-C doesn't like this bit of code, but im not sure why:
=============================================================== #include <acknex.h> #include <default.c>
ENTITY* FLOOR; VECTOR pixel2; var pixel; var num_box; var posx; var posy; BMAP* texture;
bmap_load(texture, "hello.bmp", 0);
function new_box() { posx=0; posy=0; while (posx<75) { posx += 2; while (posy<32) { posy += 2;
pixel = pixel_for_bmap(texture,posx,posy); // SHOULd get the bitmaps pixels color
pixel_to_vec(pixel2, NULL,8888,pixel); // SHOULD change the color to a *vector*
if (pixel2.x + pixel2.y +pixel2.z > 100) // IF the result is brighter than a certain amount DO SOMETHING num_box=num_box+1; { /*more commands*/ } num_box=num_box+1; wait(1); } } num_box=num_box+1;
} =============================================================== It's the bold line causing problems, the engine gives the unhelpfull message:
ERROR E1513 "Crash in main"
Can anyone help?
I am a noob to this... Blitz3D is where i am best at!
|
|
|
Re: pixel_for_bmap???
[Re: CdeathJD]
#226948
09/12/08 03:37
09/12/08 03:37
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Best guesses, 1> "texture" may be a reserved word. 2> posx/posy are going higher than actual bmap size. 3> You may be accessing an 8-bit(256 color) bitmap file. From the manual. Only normal 16, 24, or 32 bit bmaps can be read from. Compressed DDS bmaps, or bmaps used as render target can not be accessed.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: pixel_for_bmap???
[Re: EvilSOB]
#226999
09/12/08 10:46
09/12/08 10:46
|
Joined: Jul 2007
Posts: 959 nl
flits
User
|
User
Joined: Jul 2007
Posts: 959
nl
|
dont forget to set bmap_lock first
"empty"
|
|
|
Re: pixel_for_bmap???
[Re: flits]
#227009
09/12/08 11:15
09/12/08 11:15
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Filis, do you need bmap_lock for just reading a bitmap? I thought it was just for changing it. (I have never used it though)
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: pixel_for_bmap???
[Re: EvilSOB]
#227018
09/12/08 11:41
09/12/08 11:41
|
Joined: Aug 2008
Posts: 55 United Kingdom
CdeathJD
OP
Junior Member
|
OP
Junior Member
Joined: Aug 2008
Posts: 55
United Kingdom
|
Tsk, sorry Evil SOB but its none of those things:
1) i changed "texture" handle to MYBMP
2) the posx/posy variables are stopped before the dimensions of the bitmap are reached. (Image size 78x33)
3) the image is in 16 million colours!
I also tried the bmp_lock function to, but it seemed to do nothing, and i still get the error! ==================================================================================
#include <acknex.h> #include <default.c>
VECTOR pixel2; var pixel; var num_box; var posx; var posy; BMAP* MYBMP;
var crackman; // debug variable to watch
bmap_load(MYBMP, "hello.bmp", 0); bmap_lock( MYBMP, 0);
typedef struct { ENTITY* model; } box;
function new_box() { crackman += 1; posx=0; while (posx<74) { posx += 2; posy=0; while (posy<30) { posy += 2; pixel = pixel_for_bmap(MYBMP,posx,posy); // SHOULd get the bitmaps pixels color pixel_to_vec(pixel2, NULL,8888,pixel); // SHOULD change the color to a *vector* if (pixel2.x + pixel2.y +pixel2.z > 100) // IF the result is brighter than a certain amount DO SOMETHING num_box=num_box+1; { box my_box; /* box loading stuff */ wait(1); /* more box setup stuff */ } num_box=num_box+1; wait(1); } } num_box=num_box+1;
}
I am a noob to this... Blitz3D is where i am best at!
|
|
|
Re: pixel_for_bmap???
[Re: CdeathJD]
#227038
09/12/08 13:08
09/12/08 13:08
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Hmmm, that looks odd. Are the commands bmap_load(MYBMP, "hello.bmp", 0);
bmap_lock( MYBMP, 0); inside a function or not, cause they dont look like it, and they need to be. If they're not, it means MYBMP is still empty, causing the error. Try puttin them into the start of function new_box(). If they are inside a function already, is it getting to that point before new_box() is executed? Let us know and I'll turn my brain back on. Another thing to try (whether I was right or wrong), try declaring the BMAP directly. BMAP* MyBmp = "hello.bmp"; leave it where it is though, and drop the bmap_load line. Still move the map_lock into new_box() too.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: pixel_for_bmap???
[Re: EvilSOB]
#227057
09/12/08 13:44
09/12/08 13:44
|
Joined: Aug 2008
Posts: 55 United Kingdom
CdeathJD
OP
Junior Member
|
OP
Junior Member
Joined: Aug 2008
Posts: 55
United Kingdom
|
right now theres more problems! * i made the defenition line into "BMAP* MYBMP = "hello.bmp";" as suggested. * i also put the bmap_lock command inside my "function main()" as instructed. Now the code works, but just generates an array of objects, disregarding the color of the pixel its supposed to be reading and then using to judge if the color is bright enough it will make a cube! :S Here is the image its reading: [img]http://slcrinkle.googlepages.com/hello.bmp[/img] The probably offending code:
function new_box()
{
//bmap_load(MYBMP, "hello.bmp", 0);
bmap_lock( MYBMP, 0);
posx=0;
while (posx<74)
{
posx += 2;
posy=0;
while (posy<20)
{
posy += 2;
// VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
pixel = pixel_for_bmap(MYBMP,posx,posy); // SHOULd get the bitmaps pixels color
pixel_to_vec(pixel2, NULL,8888,pixel); // SHOULD change the color to a *vector*
if (pixel2.x + pixel2.y +pixel2.z > 300) // IF the result is brighter than a certain amount DO SOMETHING
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
{
box my_box;
EDIT: Never mind i got it working! instead of "8888" i should have used "888"!! My bad! Now if only i could figure them damn structs out!
Last edited by CdeathJD; 09/12/08 13:51.
I am a noob to this... Blitz3D is where i am best at!
|
|
|
Re: pixel_for_bmap???
[Re: CdeathJD]
#227088
09/12/08 15:19
09/12/08 15:19
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Cool.
As for structs, do you really need it? Did you try using the skills like I suggested? With 100 'var's built into each entity, is it really necessary to muck about with structs?
I only use them VERY rarely, and even then I store a pointer to it in one of my entitys skills anyway.
What do you have in mind for the struct anyway? If you tell me that, I can probably show you a way to do it in entity skills anyway.
Unless you just want to understand structs, in which case ask away.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|