10.3 Writing a Presentation Graphics Program

To write a C or C++ program that uses presentation graphics, follow these steps:

1.Include the required header files, GRAPH.H and PGCHART.H, as well as any other header files your program may need.

2.Set the video mode to a graphics mode. See Chapter 9, “Communicating with Graphics,” for a description of video modes.

3.Initialize the presentation graphics chart environment. Presentation graphics places charting parameters in data structures. The amount of initialization that must be done by your program depends on how extensively it relies on the defaults.

4.Assemble the plot data. Data can be collected in a variety of ways: by calculating it elsewhere in the program, reading it from files, or entering it from the keyboard. All plot data must be assembled in arrays because the presentation graphics functions locate them through pointers.

5.Call presentation graphics functions to display the chart. Pause while the chart is on the screen.

6.Reset the video mode. When your program detects the signal to continue, it should reset the video to its original (default) mode.

After compiling the program, link it to the library modules PGCHART.LIB and GRAPHICS.LIB.

Note:

If your program uses the alternate math package (i.e., if it is compiled with /FPa), it cannot use the PGCHART.LIB module.

The sample programs on topic topic use 5 of the 22 presentation graphics functions: _pg_initchart, _pg_defaultchart, _pg_chartpie, _pg_chart, and _pg_chartscatter. Each program is commented so that you can recognize the steps given in this section.