The following program, ERESBOX.C, shows the steps you follow to enter and exit a graphics mode. It sets the video mode _ERESCOLOR, draws a box, waits for a keypress, and returns to default mode, which is the video mode in effect when the program began running.
/* ERESBOX.C — Enters _ERESCOLOR mode and draws a box */
#include <graph.h> /* graphics functions */
#include <stdio.h> /* puts */
#include <conio.h> /* _getch */
main()
{
if( _setvideomode( _ERESCOLOR ) ) /* EGA 640x350 mode */
{
_rectangle( _GBORDER, 10, 10, 110, 110 ); /* draw */
_getch(); /* wait for a keypress */
_setvideomode( _DEFAULTMODE ); /* return to default */
} else puts( “Can't enter _ERESCOLOR graphics mode.” )
}
ERESBOX.C illustrates the steps you follow to display graphics:
1.Include the header file GRAPH.H. It contains function prototypes, macros, useful structures, and symbolic constants such as _ERESCOLOR, _GBORDER, and _DEFAULTMODE.
#include <graph.h>
2.Call the _setvideomode function, which sets the desired video mode. The function returns 0 if the hardware does not support the requested mode. (See “Setting a Video Mode” on this page.)
if( _setvideomode( _ERESCOLOR ) )
3.Draw the graphics on the screen. The example program calls the _rectangle function. (See “Drawing Points, Lines, and Shapes”.)
_rectangle( _GBORDER, 10, 10, 110, 110 )
4.Exit the graphics mode and return to whatever video mode was in effect before the program began. Call _setvideomode, passing the constant _DEFAULTMODE. In some cases, you might want to skip this step, exiting the program with the graphics screen still in place.
_setvideomode( _DEFAULTMODE );
In addition, you must link with the GRAPHICS.LIB library, which contains the function code. (If you instructed SETUP to include GRAPHICS.LIB in the combined libraries, you don't need to link with GRAPHICS.LIB explicitly.) If you use window-coordinate functions (which require floating-point calculations) and if you have not created a standard combined library containing a floating-point component, you must explicitly link with a floating-point math library.