Welcome, Guest. Please login or register.

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

Description:

0 Members and 1 Guest are viewing this topic.

Offline xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show all replies
    • http://www.petergordon.org.uk
Re: How to use BltBitmaprast port or other like it
« 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 xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show all replies
    • http://www.petergordon.org.uk
Re: How to use BltBitmaprast port or other like it
« Reply #1 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 xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show all replies
    • http://www.petergordon.org.uk
Re: How to use BltBitmaprast port or other like it
« Reply #2 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 all replies
    • http://www.petergordon.org.uk
Re: How to use BltBitmaprast port or other like it
« Reply #3 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 xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show all replies
    • http://www.petergordon.org.uk
Re: How to use BltBitmaprast port or other like it
« Reply #4 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 xeron

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