Amiga.org
Amiga computer related discussion => Amiga Software Issues and Discussion => Topic started by: yssing on March 06, 2003, 09:25:37 AM
-
Hi
I seem to have a problem with this.
If I use AllocBitMap() to alloc the bitmap I use to store image data.
And then use BltBitMap() my puter crashes. I am sure I am doing some thing wrong.
My question is this : Does any one have an example on how to use AllocBitMap() with BltBitMap()
Hope you guys can help...
-
Are you blitting from one bitmap to another or a section of the bitmap to somewhere else in the same bitmap?
When you create your bitmap, do you specify the BMF_DISPLAYABLE flag? Do yo make it a friend of an existing bitmap (the one you intend to blit to, for example)?
Post your suspect code section, that's always handy for seeing whats wrong :-)
-
Here is my code....
struct RastPort *rastport1 = NULL;
struct BitMap *bitmap = NULL;
struct BitMap *mitbitmap = NULL;
BPTR m;
rastport1 = Mywindow->RPort;
mitbitmap = AllocBitMap(640,480,8,BMF_MINPLANES|BMF_DISPLAYABLE,rastport1->BitMap);
m = Open("GFX/game_menu", MODE_OLDFILE);
Read(m, menuraw, 307200);
Close(m);
menu.ImageData = menuraw;
BltBitMap(mitbitmap,0,0,rastport1->BitMap,0,0,640,480,0xC0,0xff,NULL);
Should be it...
-
Check out the sources of FlashNG: both AllocBitmap() and BltBitmap() are used...
http://nogfx.free.fr/flash
flash.c/AllocFlash() => AllocBitmap()
flash.c/MoveRect()=> BltBitmap()
Maybe the sources I released a year or so ago will finally become usefull for someone ;)
Regards,
Leo.
PS: It will work on both RTG (P96/CGX) and AGA...
-
Ok, another question..
Are you using CyberGraphX?
-
OK, this is from memory, while at work, but this should do the trick:
[color=006600]if( mybitmap = AllocBitMap( bwidth, bheight, bdepth, BMF_CLEAR, 0 ) )
{
rp myrast;
InitRastPort( &myrast );
/* Attach our rastport to our bitmap */
myrast.bitmap = mybitmap;
/* Put something in the bitmap */
SetFont( &myrast, myfont );
SetAPen( &myrast, 1 );
Move( &myrast, 0, myfont->baseline );
Text( &myrast, "Hello", 5 );
/* Blit to our window */
BltBitMapRastPort( mybitmap, 0, 0, win->rport, win->borderleft, win->bordertop, bwidth, bheight, 0x0C0 );
/* Free the bitmap */
FreeBitMap( mybitmap );
}
[/color]
-
Karlos wrote:
Ok, another question..
Are you using CyberGraphX?
I ask because I found that the depth parameter you give to AllocBitMap() under cgx sometimes caused memory trashing when given as 8 and used with the BMF_SPECIALFMT option (when creating high/trucolour bitmaps).
Also, I never tried manually setting image data before - I always lock the bitmap, write the data and then unlock.
Still if your'e not using cgx, ignore me :-)
-
Nope I am not using CGFX.
Just plain WB....
I am trying to keep it as HW independant as possible
-
@yssing:
Whoa! There are quite a few things wrong with that! You've specified rastport1->Bitmap as a friend bitmap. if rastport1 isn't the same pixel format as your game menu, you'll get graphics corruption. If you are going to load a raw file directly into a bitmap, you'll have to put zero there to make sure you get a planar bitmap. Also, there is no need to specify displayable for it.
Once you know you have a planar bitmap of the right size for your menu file, you can do this:
Read( m, mybitmap->planes[0], planesize );
Read( m, mybitmap->planes[1], planesize );
...
Then, when you use BltBitMapRastPort, if a graphics card is being used, CGX or P96 will perform planar to chunky/high/truecolour on the data if necessary.
Finally, it is better to use BltBitMapRastPort, since the windows rastport contains the information required to correctly blit to a window bitmap.
Something like this should do (note: i don't have an Amiga here, so i cant test this):
[color=006600]
if( menubm = AllocBitMap( 640, 480, 8, 0, 0 ) )
{
if( m = Open( "GFX/game_menu", MODE_OLDFILE ) )
{
Read( m, menubm->planes[0], 80*480 );
Read( m, menubm->planes[1], 80*480 );
Read( m, menubm->planes[2], 80*480 );
Read( m, menubm->planes[3], 80*480 );
Read( m, menubm->planes[4], 80*480 );
Read( m, menubm->planes[5], 80*480 );
Read( m, menubm->planes[6], 80*480 );
Read( m, menubm->planes[7], 80*480 );
BltBitMapRastPort( menubm, 0, 0, win->rport, win->borderleft, win->bordertop, 640, 480, 0x0C0 );
Close( m );
}
FreeBitMap( menubm );
}
[/color]
-
Have to admit, I did think the way the image data was loaded looked suspect. What guarentee was there that it was the same format as the bitmap?
I only got into gfx coding post BVision :-) so I tend to concentrate on gfx-card only stuff...
-
Also, with my code above, you could allocate a second bitmap as a friend of the window (still no need for BMF_DISPLAYABLE, and especially not BMF_MINPLANES), then blit from the planar one to the second one, then free up the planar one.
Now you have the menu converted to the correct format by CGX/P96, and when you blit it into the window it will be faster.
Example:
[color=006600]
struct BitMap *menubm = NULL;
bool load_menu( void )
{
struct BitMap *tempbm = NULL;
struct RastPort temprp;
BPTR m;
bool loadok = false;
if(( menubm = AllocBitMap( 640, 480, 8, BMF_DISPLAYABLE, win->RPort->BitMap ) ) == NULL) return false;
InitRastPort( &temprp );
temprp.bitmap = menubm;
if( tempbm = AllocBitMap( 640, 480, 8, 0, 0 ) )
{
if( m = Open( "GFX/game_menu", MODE_OLDFILE ) )
{
Read( m, tempbm->planes[0], 80*480 );
Read( m, tempbm->planes[1], 80*480 );
Read( m, tempbm->planes[2], 80*480 );
Read( m, tempbm->planes[3], 80*480 );
Read( m, tempbm->planes[4], 80*480 );
Read( m, tempbm->planes[5], 80*480 );
Read( m, tempbm->planes[6], 80*480 );
Read( m, tempbm->planes[7], 80*480 );
BltBitMapRastPort( tempbm, 0, 0, &temprp, 0, 0, 640, 480, 0x0C0 );
loadok = true;
Close( m );
}
FreeBitMap( tempbm );
}
return loadok;
}
void show_menu( void )
{
BltBitMapRastPort( menubm, 0, 0, win->RPort, win->BorderLeft, win->BorderTop, 640, 480, 0x0C0 );
}
void free_menu( void )
{
if( menubm != NULL ) FreeBitMap( menubm );
}
[/color]
-
Actually, this code assumes you have your own screen and palette, as well, so it wouldn't work on the workbench screen.
-
Well It does not crash anymore :-)
But It does only display a grey screen :-(
But thank you very much.. I never did think about that friend bitmap and the way I loaded data.
-
Well, although i don't have an amiga here at work to test it, i'm 95% sure the latest code i posted should get your menu on the screen.
Edit: Well, it should *now*, I just fixed a bug where it allocated menubm. :-D
-
Well I do have my own screen and palette.
I am, in my program, using DrawImage, which works, and does a good job. but, it is rather slow.
And cannot blit with transparent color.
But I think I can continue now :-)
-
Right, well, TBH using DrawImage is not the best way to go about it. I think my code above is probably the fastest way to show your raw menu data in a way that will work on AGA, P96 and CGX.