2D Graphics Overview

The 2D Graphics Framework is a self-contained collection of C++ classes within IBM Open Class which provide classes for creating, manipulating, and rendering 2-dimensional graphics. You can use 2D Graphics classes to build applications that create and manipulate 2-dimensional graphics and images. These classes are easy to use. You instantiate the classes you need and call their member functions. You do not need to know linear algebra or any other advanced mathematics to effectively use these classes. All advanced mathematics is implemented for you.

You can extend most of these classes to add your own functionality by deriving from the abstract base classes, implementing the pure virtual functions, and adding whatever behavior you need.

The 2D Graphics Framework classes can be used to perform the following:

The 2D Graphics Framework is grouped into the following main categories:

The graphics and geometry classes provide functionality for different areas of graphics programming:

You can use graphics and geometry classes together, or use the geometry classes by themselves. You can also extend the graphics classes by creating your own graphic class. You can design your own class to use as many geometry classes as you want.

The geometry classes provide many ways to construct a shape because you construct the geometry first and then use it to construct the graphic. The graphics classes constructors give you the option of including an attribute bundle to define characteristics of the graphic.

Transformation functions let you rotate, translate, scale, or apply a general transformation to the geometry without using matrix multiplication.

The graphic classes provide mechanisms to determine the bounds of a graphic as a rectangle enclosing the shape. This bounding box can be used, for example, to determine whether a user has selected a graphic (hit detection). The supported functions return a bounding box that does not have a tight fit.

When you use a graphic class to create a shape, you get the following:

Geometry

The geometry classes serve as the foundation for creating graphics. Use these classes to describe pure geometric shapes.

The geometry classes are grouped into the following categories:

NOTE: For immediate mode rendering, a user can create geometry and graphics attributes and render directly to the graphics rendering/display system, the rendering pipeline, without using the modeling classes. However, IMGraphic modeling classes are more convenient for retained mode rendering where a user needs to attach attributes and transformation functions to a geometry.

Attributes and Bundles

Graphics attributes classes describe primitive attributes such as paint, pen, and image transfer mode. These classes collect combinations of such primitive attributes to use when rendering the geometry.

Transformations

Transformation classes, specifically IGrafMatrix, define transformation matrices for manipulating graphics geometry and modeling.

Modeling

Modeling classes associate geometries with graphic attributes, and transformations for simple graphics and hierarchical collections of graphics. IMGraphic is the abstract class of IGraphicGroup and its related classes. Use these classes to create complex graphics models (scenes), and extend these classes to enable graphics metadata storage. The virtual draw function lets you render the geometry of a drawable graphic with attributes and transforms applied.

Rendering

The rendering pipeline, controlled through IGrafPort, performs imaging operations. You associate a graphic and its state information, including its attribute state, transformation matrix, and clipping state, with a grafport. The grafport renders the graphic from this state information.

IGrafPort is associated with IGrafDevice. For performance reasons, IGrafDevice is at the level of abstraction of platform/device-specific code. The concrete subclass of IGrafDevice is platform/device specific. IGrafDevice encapsulates the nonportable code: the device-dependent layer is completely hidden from the client.

Prerequisite Information

For background information on graphics programming, refer to a dictionary of graphics terms or to the following books on graphics programming:

Useful Information



Attributes and Bundles Overview
2D Graphics Geometry Overview
Modeling Overview
2D Graphics Rendering Pipeline Overview
2D Graphic Transformations Overview


Transitioning 2D Graphics to IBM Open Class