[haiku-appserver] Re: drawing thread

  • From: André Braga <meianoite@xxxxxxxxx>
  • To: haiku-appserver@xxxxxxxxxxxxx
  • Date: Mon, 8 Nov 2004 15:33:02 -0200

OK, kill me now, but this code is so simple I just felt like showing
you (and it's C at least ^_^)


// Allegro API
BITMAP *pages[2];
int curPage =3D 0;

pages[0] =3D create_video_bitmap(SCREEN_W,SCREEN_H);
pages[1] =3D create_video_bitmap(SCREEN_W,SCREEN_H);

while(main_loop)
 {
  blit(buffer, page[curPage], 0,0,0,0,SCREEN_W,SCREEN_H);
  show_video_bitmap(page[curPage]); // this does vsync() for us, but proper=
ly.

  curPage ^=3D 0x01; // flips the buffers
 }


Bottom line is:
1) you always draw to the same place (backbuffer), and blit it to the
current frontbuffer
2) you draw the "ready" frontbuffer, and flip it afterwards; now
you're ready to draw the one which was current in step 1.
3) repeat

So there's no need to sync both buffer's contents. Which is very nice :DD

Cheers,
A.


--
"A year spent in artificial intelligence is enough to make one believe in G=
od"
Alan J. Perlis


On Mon, 8 Nov 2004 15:16:55 -0200, Andr=E9 Braga <meianoite@xxxxxxxxx> wrot=
e:
> And now some code (sorry, non-linear email composition usually leads to t=
his =3DP)
>=20
> http://www.bsdg.org/SWAG/GRAPHICS/0174.PAS.html
>=20
> I hope it's useful, despite being written in Pascal.
>=20
>=20
>=20
> Cheers,
> A.
>

Other related posts: