Welcome, Guest. Please login or register.

Author Topic: How to use BltBitmaprast port or other like it  (Read 3735 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline yssingTopic starter

  • Hero Member
  • *****
  • Join Date: Apr 2002
  • Posts: 1521
    • Show only replies by yssing
    • http://www.yssing.org
How to use BltBitmaprast port or other like it
« 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...

 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: How to use BltBitmaprast port or other like it
« Reply #1 on: March 06, 2003, 09:29:49 AM »
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 :-)
int p; // A
 

Offline yssingTopic starter

  • Hero Member
  • *****
  • Join Date: Apr 2002
  • Posts: 1521
    • Show only replies by yssing
    • http://www.yssing.org
Re: How to use BltBitmaprast port or other like it
« Reply #2 on: March 06, 2003, 09:46:24 AM »
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...
 

Offline Leo42

  • Newbie
  • *
  • Join Date: Dec 2002
  • Posts: 44
    • Show only replies by Leo42
    • http://nogfx.free.fr
Re: How to use BltBitmaprast port or other like it
« Reply #3 on: March 06, 2003, 09:48:06 AM »
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...
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: How to use BltBitmaprast port or other like it
« Reply #4 on: March 06, 2003, 09:48:32 AM »
Ok, another question..

Are you using CyberGraphX?
int p; // A
 

Offline xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show only replies by xeron
    • http://www.petergordon.org.uk
Re: How to use BltBitmaprast port or other like it
« Reply #5 on: March 06, 2003, 09:55:22 AM »
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]
Playstation Network ID: xeron6
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: How to use BltBitmaprast port or other like it
« Reply #6 on: March 06, 2003, 10:02:48 AM »
Quote

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 :-)
int p; // A
 

Offline yssingTopic starter

  • Hero Member
  • *****
  • Join Date: Apr 2002
  • Posts: 1521
    • Show only replies by yssing
    • http://www.yssing.org
Re: How to use BltBitmaprast port or other like it
« Reply #7 on: March 06, 2003, 10:11:30 AM »
Nope I am not using CGFX.
Just plain WB....
I am trying to keep it as HW independant as possible
 

Offline xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show only replies by xeron
    • http://www.petergordon.org.uk
Re: How to use BltBitmaprast port or other like it
« Reply #8 on: March 06, 2003, 10:14:16 AM »
@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]
Playstation Network ID: xeron6
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: How to use BltBitmaprast port or other like it
« Reply #9 on: March 06, 2003, 10:23:28 AM »
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...
int p; // A
 

Offline xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show only replies by xeron
    • http://www.petergordon.org.uk
Re: How to use BltBitmaprast port or other like it
« Reply #10 on: March 06, 2003, 10:26:00 AM »
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]
Playstation Network ID: xeron6
 

Offline xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show only replies by xeron
    • http://www.petergordon.org.uk
Re: How to use BltBitmaprast port or other like it
« Reply #11 on: March 06, 2003, 10:41:29 AM »
Actually, this code assumes you have your own screen and palette, as well, so it wouldn't work on the workbench screen.
Playstation Network ID: xeron6
 

Offline yssingTopic starter

  • Hero Member
  • *****
  • Join Date: Apr 2002
  • Posts: 1521
    • Show only replies by yssing
    • http://www.yssing.org
Re: How to use BltBitmaprast port or other like it
« Reply #12 on: March 06, 2003, 10:49:09 AM »
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.
 

Offline xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show only replies by xeron
    • http://www.petergordon.org.uk
Re: How to use BltBitmaprast port or other like it
« Reply #13 on: March 06, 2003, 10:54:19 AM »
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
Playstation Network ID: xeron6
 

Offline yssingTopic starter

  • Hero Member
  • *****
  • Join Date: Apr 2002
  • Posts: 1521
    • Show only replies by yssing
    • http://www.yssing.org
Re: How to use BltBitmaprast port or other like it
« Reply #14 on: March 06, 2003, 10:56:13 AM »
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 :-)