Chapter 3. Transformation and Viewing


Perhaps the most common problem encountered by programmers who are new to OpenGL is the blank screen; executing an OpenGL program produces an empty window rather than a rendered image. Although several application problems can cause this result, the most common cause is misconfiguring the OpenGL transformation pipeline. To avoid blank screens, you need to be adept at controlling the OpenGL transformation state.

OpenGL provides a powerful, flexible set of routines for controlling transformation and viewing. This programming interface isn't always straight-forward, however, especially if it's been a few years since you opened a linear-algebra textbook. OpenGL doesn't provide a "place the camera here" command, for example. To specify a view location and orientation, OpenGL requires the application to compute the inverse of the camera transformation matrix. (Fortunately, GLU somewhat addresses this with gluLookAt(), discussed in this chapter.)

Another common source of confusion is the difference between the view transformation, which positions and orients the camera, and the projection transformation, which determines the field of view, the shape of the view volume, and the projection type (parallel or perspective). Confusing these transformations can cause problems not only with viewing, but also with other OpenGL features, such as lighting and clipping.

This chapter covers the essentials of OpenGL transformation and viewing, and points out areas that are confusing to some programmers.

What You'll Learn

This chapter covers the following topics:

  • Characteristics of OpenGL matrices, matrix state, and coordinate systems

  • How to control the fixed-function transformation pipeline

  • How to create parallel and perspective projection transformations

  • How to specify model and view transformations

  • Specifying the window area for displaying the final image

  • Transforming vertices to and from window coordinates without rendering them

  • How to add picking support to your application

What You Won't Learn

The following aspects of the OpenGL transformation system are not covered in this chapter:

  • This chapter isn't an introduction to linear algebra.

  • OpenGL version 2.0 features a programmable transformation interface. This chapter discusses only the fixed-function method. For more information, see OpenGL® Shading Language.

  • The chapter doesn't discuss the transpose matrix feature, which allows applications to specify row-order matrices. For more information, see The OpenGL Graphics System.

  • The chapter doesn't cover the depth-range feature, part of the viewport transformation, which allows applications to control the range of the depth buffer.

  • The chapter doesn't cover transforming colors with the color matrix.

  • This chapter briefly mentions the glFrustum() interface for creating perspective projections but doesn't cover it in detail.

If you need to review linear algebra as applied to the field of computer graphics, see Chapter 5, "Geometrical Transformations," and the appendix, "Mathematics for Computer Graphics," in Computer Graphics: Principles and Practice.




OpenGL Distilled
OpenGL Distilled
ISBN: 0321336798
EAN: 2147483647
Year: 2007
Pages: 123
Authors: Paul Martz

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net