Graphics Reference
In-Depth Information
/* Global variables */
int graphDriver, graphMode,
/* After call to InitGraph these variables specify the
current hardware */
numColors,
/* maximum number of colors */
scrnXmax, scrnYmax
/* screen resolution */
txtHeight, txtWidth;
/* the height and width in pixels of a character in the
current font */
void MyExitProc ( void )
{ closegraph ();
/* Shut down the graphics system */
}
void InitializeGraphics ( void )
{ int errorCode;
graphDriver = DETECT; /* DETECT is a BGI constant */
initgraph (&graphDriver,&graphMode,"");
errorCode = graphresult ();
if ( errorCode != grOk ) /* grOk is a BGI constant */
{ /* Error occurred during initialization */
printf (" Graphics system error: %s\n",grapherrormsg (errorCode));
exit (1);
}
atexit (MyExitProc);
/* so that we do closegraph when exiting */
numColors = getmaxcolor () + 1;
scrnXmax = getmaxx ();
scrnYmax = getmaxy ();
txtHeight = textheight ("A");
txtWidth = textwidth ("A");
}
Program 1.6.1.
Code for initializing DOS graphics mode.
doing a similar initialization for Microsoft Windows is much more complicated. The
reason is that the user's program is now initializing one of potentially many windows
on the screen. Under DOS basically only one window was initialized, namely, the
whole screen. If a program wanted to deal with multiple windows, it would have to
do that completely by itself. In other words, with Microsoft Windows we have a more
complicated initialization procedure but we gain functionality. If one is using OpenGL
or DirectX, then actually two initializations are required. After initializing the native
Windows GDI, so that one can run the program in a standard window on the screen
Search WWH ::




Custom Search