Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AbrahamR, wdlmaster, 7th_zorro, dr_panther, 1 invisible), 764 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
problem with pixel_for_bmap #403305
06/17/12 23:13
06/17/12 23:13
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
I am trying to copy one panel bmap to another using pixel for bmap and pixel to bmap. I am using the following code:

PANEL* panel_one =
{ pos_x = 10;
pos_y = 10;
layer = 10;
flags = SHOW;
}

PANEL* panel_two =
{ pos_x = 30;
pos_y = 10;
layer = 10;
flags = SHOW;
}


function main()
{ var count;
var count2;
var pixel;
panel_one.bmap = bmap_create("my_bmap.tga");
panel_two.bmap = bmap_createblack(bmap_width(panel_one.bmap),bmap_height(panel_one.bmap),32);
bmap_lock(panel_one.bmap);
bmap_lock(panel_two.bmap);
count = 0;
while(count<bmap_height(panel_one.bmap))
{ count2 = 0;
while(count2<bmap_width(panel_one.bmap))
{ pixel = pixel_for_bmap(panel_one.bmap,count,count2);
pixel_to_bmap(panel_two.bmap,count,count2,pixel);
count2 += 1;
}
count += 1;
}
bmap_unlock(panel_one.bmap);
bmap_unlock(panel_two.bmap);
}

When I run this code i get a crash. upon testing im finding that the pixel read from pixel_for_bmap is zero. Why is this? and would feeding a zero value for the pixel to pixel to bmap cause a crash?

(P.S. please do not tell me to just use panel_two.bmap = panel_one.bmap - this will not work for my purposes.)

Re: problem with pixel_for_bmap [Re: Caermundh] #403313
06/18/12 06:44
06/18/12 06:44
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
hello,
may be those bmap_lock calls need their second parameter.
Does 'my_bmap.tga' have 32bit format? I'm not sure but both bmaps should have same.

Salud!

Re: problem with pixel_for_bmap [Re: txesmi] #403316
06/18/12 07:29
06/18/12 07:29
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
the main error: count should be bmap_width() and count2 should be bmap_height() in the while statement !!!

and some tips:

put a wait(1); after panel_one.bmap = bmap_create("my_bmap.tga");
and
put a wait(1); after panel_two.bmap = bmap_createblack(bmap_width(panel_one.bmap),bmap_height(panel_one.bmap),32);
because I'm not sure they can be locked in the same frame as creation.

and yes, my_bmap.tga must be 32b, or use bmap_to_format();


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: problem with pixel_for_bmap [Re: sivan] #403341
06/18/12 16:16
06/18/12 16:16
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
ok! thanks! that fixed it - part of my problem was that "my_bmap.tga" was 24 bit and the createblack bmap was 32 - changed the create black to 24, flipped count and count2, and put in the wait(1); - all of that fixed that problem.

It never even occured to me to check the bit depth of the maps - when i bmap locked them it returned 8888 for both so i figured they were the same.

(the bmap lock is a typo. i did have bmap_lock(panel_one.bmap,0) - my bad)

heres the code that works:

panel_one.bmap = bmap_create("cb_iconbox_md.tga");
wait(1);
panel_two.bmap = bmap_createblack(bmap_width(panel_one.bmap),bmap_height(panel_one.bmap),24);
wait(1);
bmap_lock(panel_one.bmap,0);
bmap_lock(panel_two.bmap,0);
count = 0;
while(count<bmap_height(panel_one.bmap))
{ count2 = 0;
while(count2<bmap_width(panel_one.bmap))
{ pixel = pixel_for_bmap(panel_one.bmap,count2,count);
pixel_to_bmap(panel_two.bmap,count2,count,pixel);
count2 += 1;
}
count += 1;
}
bmap_unlock(panel_one.bmap);
bmap_unlock(panel_two.bmap);


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1