// Filename : Dbuff2.c // Coded by : Scott Evans // Created/Modified : 16/9/97 // Description : Demonstrates double buffering using high and low level // graphics functions #include // Header file for yaroze.c, my versions of functions not included // in Yaroze libraries #include #define NPKTS 1 #define PBSIZE NPKTS*sizeof(GsBOXF) #define OT_LENGTH 1 #define SCRNW 320 #define SCRNH 240 // 2 ordering tables and 2 packet buffers GsOT mainOT[2],*ot=mainOT; GsOT_TAG OTTags[2][1<length=(ot+1)->length=OT_LENGTH; ot->org=OTTags[0]; (ot+1)->org=OTTags[1]; // Set drawing area for buffer 0 and 1 SetDefDrawEnv(&dbp->drawenv,0,0,SCRNW,SCRNH); SetDefDrawEnv(&(dbp+1)->drawenv,0,SCRNH,SCRNW,SCRNH); // Set display area for buffer 0 and 1 SetDefDispEnv(&dbp->dispenv,0,SCRNH,SCRNW,SCRNH); SetDefDispEnv(&(dbp+1)->dispenv,0,0,SCRNW,SCRNH); // Set ordering table for buffer 0 and 1 dbp->ot=ot; (dbp+1)->ot=ot+1; // Set packet buffer for buffer 0 and 1 dbp->pb=pb; (dbp+1)->pb=pb+PBSIZE; // Dither off dbp->drawenv.dtd=(dbp+1)->drawenv.dtd=0; // Clear background on dbp->drawenv.isbg=(dbp+1)->drawenv.isbg=1; // Background colour=red setRGB0(&dbp->drawenv,0x80,0x0,0x0); setRGB0(&(dbp+1)->drawenv,0x80,0x0,0x0); // Set up a white box box.attribute=0; box.w=box.h=50; box.x=(SCRNW-box.w)>>1; box.y=(SCRNH-box.h)>>1; box.r=box.g=box.b=0xff; // Initialise graphics ResetGraph(0); // Turn on display SetDispMask(1); while(1) { // Swap buffers dbp=(dbp==db ? db+1 : db); // Set packet buffer for current buffer GsSetWorkBase(dbp->pb); // Initialise ordering table GsClearOt(0,0,dbp->ot); // Put primitive in ordering table GsSortBoxFill(&box,dbp->ot,0); // Wait for it all to finish VSync(0); // Halt drawing after vertical blank has returned // Similar to DrawSync() but does not wait for drawing to // finish, it just stops the drawing ResetGraph(1); // Set new drawing and display areas PutDrawEnv(&dbp->drawenv); PutDispEnv(&dbp->dispenv); // Execute the primitives in the ordering table GsDrawOt(dbp->ot); } exit(0); }