ViewportsViewports provide an alternate integer-based coordinate system for referencing pixels. Fastgraph includes functions to create a viewport, return the viewport limits, and convert viewport coordinates to their screen space values. A viewport definition consists of its extremes in "viewport space" and the corresponding limits in screen space. The fg_setview() function defines a 2D viewport. Its first four parameters represent the minimum x, maximum x, minimum y, and maximum y viewport coordinates, and its last four parameters represent the corresponding screen space pixel values defining the viewport's physical size and location. For example, the call
C/C++ and Delphi:
Visual Basic:
would create a 640x400 viewport in the upper left corner of a 320x200 virtual buffer, as shown here:
The viewport's coordinates would range from 100 to 739 horizontally and 100 to 499 vertically. In other words, the viewport coordinate (100,100) would map to the screen space pixel (0,0). The fg_getview() function returns the current viewport limits and corresponding screen space limits, as defined in the most recent call to fg_setview(). Once you've defined a viewport, the fg_xview() and fg_yview() functions translate viewport coordinates to their screen space equivalents. The translated values can then be passed to any Fastgraph function that expects screen space coordinates. For example, the fg_rect() function draws a filled rectangle in screen space. If you wanted to fill the viewport defined above with color 10 pixels, you could do this as follows:
C/C++ and Delphi:
Visual Basic:
To make a viewport a "true" viewport, it is often desirable to establish clipping limits at the viewport's extremes. This way, the Fastgraph functions that support clipping will only draw within the viewport itself. The following call to fg_setclip() will establish the desired clipping limits:
C/C++ and Delphi:
Visual Basic:
|
 
copyright 2001 Ted Gruber Software, Inc.