next up previous contents
Next: 15.6.1 Line Joins Up: 15. Illustration and Artistic Previous: 15.5 Cross Hatching and

15.6 2D Drawing Techniques

While most applications use OpenGL for rendering 3D data it is inevitable that 3D geometry must be combined with some 2D screen space geometry. OpenGL is designed to coexist with other renderers in the window system, that is, OpenGL and other renderers can operate on the same window. For example, X Window System 2D drawing primitives and OpenGL commands can be combined together in a window. Similarly, Win32 GDI drawing and OpenGL commands can be combined together in the same window.

One advantage of using the native window system 2D renderer is that the 2D renderers typically provide more control over 2D operations. For example, control over the joins in lines (mitre, round, bevel), the end caps on lines (round, butt) and have rasterization rules that are somewhat easier to predict. For example, both the X Window System and Win32 GDI have very precise specifications of the algorithms for rasterizing 2D lines, whereas OpenGL has provided some latitude for implementors which occasionally causes problems with application portability.

Some disadvantages in not using OpenGL commands for 2D rendering, are that the native window system 2D renderers are not tightly integrated with the OpenGL renderers. For example, the 2D renderer typically does not update or test against the depth or other ancillary buffers, the coordinate system typically has the origin at the top left corner of the window, some desirable OpenGL functionality may not be available in the 2D renderer (e.g., framebuffer blending, antialiased lines), and the 2D code is less portable.

To specify object coordinates in screen space, an orthographic projection is used. For a window of width w and height h, the transformation maps object coordinate (0,0) to window coordinate (0,0) and object coordinate (w,h) to window coordinate (w,h). Since OpenGL has pixel centers on half integer boundaries, this mapping results in pixel centers at 0.5, 1.5, 2.5, ..., w-.5 along the x-axis and 0.5, 1.5, 2.5, ..., h-.5 along the y-axis.

One difficulty is that the line rasterization rules for OpenGL are designed to avoid multiple pixel hits when drawing connected line primitives. The reason for this is that multiple hits cause difficulties in using blending or stenciling algorithms to merge multiple primitives reliably. This means that if a rectangle is drawn with a GL_LINE_LOOP, the rectangle will be properly closed with no missing pixels, whereas if the same rectangle is drawn with a GL_LINE_STRIP, or independent GL_LINES there will likely be pixels missing and or multiple hits on the rectangle boundary at or near the vertices of the rectangle. A second issue is that OpenGL does use half integer pixel centers, whereas the native window system specifies pixel centers at integer boundaries. Application developers often incorrectly use integer pixel centers with OpenGL without compensating in the projection transform.



 
next up previous contents
Next: 15.6.1 Line Joins Up: 15. Illustration and Artistic Previous: 15.5 Cross Hatching and
David Blythe
1999-08-06