/* %kw # %v %n %d %t # */ /* Version # 1 BMAPBITS.C 7-Aug-98 13:26:54 # */ /* *************************************************** */ /* METAGRAPHICS SOFTWARE CORPORATION (c) 1998 */ /* */ /* BMAPBITS.C illustrates how to directly access */ /* the pixel data in an offscreen bitmap created */ /* in local conventional memory. */ /* */ /* Demonstrates usage of CreateBitmap(), */ /* DestroyBitmap() and CopyBlit() */ /* *************************************************** */ #include #include #include #include #include #include #include #include "metawndo.h" /* master MetaWINDOW include file */ /* special stack size declaration if using Turbo or Borland C++ */ #ifdef TurboC extern unsigned _stklen = 14336U; /* stack size 14K */ #endif int GrafixCard, GrafixInput; void main( int argc, char *argv[] ) { int i,j; int scrnHeight; // screen height int scrnWidth; // screen width rect sR, fR; // temp working rects grafPort *thePort; // pointer to the screen port(/bitmap) grafPort *offscrPort; // pointer to the offscreen port(/bitmap) grafMap *offscrBitmap; // pointer to the offscreen bitmap Byte **offscrRowTable; // ptr to table of ptrs to each raster line Byte *pixelPtr; // pointer to pixel data MetQuery( argc,argv ); // autodetect the graphics card i = InitGraphics( GrafixCard ); // init MetaWINDOW if ( i != 0 ) GrInitErr( i ); // display reason for error GetPort( &thePort ); // get pointer to the screen port scrnWidth = thePort->portMap->pixWidth; scrnHeight = thePort->portMap->pixHeight; printf("\nLaunching offscreen local memory bitmap"); // *** create a memory bitmap and port matching the screen *** // (we could create any size bitmap if we wanted) offscrPort = CreateBitmap( cMEMORY, scrnWidth, scrnHeight ); if ( offscrPort == NULL ) { printf("ERROR: Unable to allocate offscreen bitmap\n"); exit(1); // abort if CreateBitmap() fails } printf("\nNow drawing to offscreen bitmap..."); printf(" Fill..."); sR = offscrPort->portRect; PenColor( Red ); BackColor( LtGray ); FillRect( &sR, 30 ); printf(" Frame..."); fR = sR; fR.Xmax--; fR.Ymax--; PenColor( Green ); FrameRect( &fR ); printf(" Some lines..."); PenColor( Blue ); MoveTo( fR.Xmin, fR.Ymin ); LineTo( fR.Xmax, fR.Ymax ); MoveTo( fR.Xmax, fR.Ymin ); LineTo( fR.Xmin, fR.Ymax ); printf(" Some text..."); PenColor( Black ); MoveTo( 20,40 ); DrawString("Offscreen bitmaps are easy with CreateBitmap()!"); printf("\nNow manually setting first byte of each raster line to 0xFF..."); offscrBitmap = offscrPort->portMap; // for 4-plane, 16-color modes loop through each plane for ( j=0; jpixPlanes; j++ ) { offscrRowTable = offscrBitmap->mapTable[j]; // now loop through each raster line for ( i=0; ipixHeight; i++ ) { pixelPtr = offscrRowTable[i]; // get the address of the 1st pixel byte *pixelPtr = 0xFF; // set the first pixel byte to 0xFF } } printf("\n\nReady to copy offscreen bitmap to the screen"); printf("\n(press Return to continue)\n"); getch(); // wait for a keypress SetPort( thePort ); // switch back to the screen SetDisplay( GrafPg0 ); // switch display to graphics mode PaintRect( &sR ); // fill screen with a different color // copy the memory bitmap to the screen bitmap CopyBlit( offscrPort, thePort, &offscrPort->portRect, &thePort->portRect ); getch(); // wait for a keypress // free the offscreen bitmap DestroyBitmap( offscrPort ); SetDisplay( TextPg0 ); // Switch to text mode i = QueryError(); // Show any MetaWINDOW detected errors printf("QueryError=%d/%d",i >> 7,i & 127); StopGraphics(); exit(i); } #include "metquery.c" /* End of File - BMAPBITS.C */