荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: Peter (小飞侠), 信区: Program
标  题: VC 4.0中使用OpenGL(1)
发信站: BBS 荔园晨风站 (Tue Jan 26 22:54:22 1999), 转信


   * 41 ?The OpenGL Graphics Library
             + OpenGL Overview
                  + Basic OpenGL Concepts
                  + Initialization
                  + Drawing with OpenGL
                  + Additional Libraries
             + Writing OpenGL Windows Applications in C
                  + OpenGL Initialization
                  + The Window Procedure
                  + Compiling and Running the Application
             + OpenGL in MFC Applications
                  + OpenGL initialization
                  + Drawing the Cube
                  + Running the Application
             + Summary

                     41 ?The OpenGL Graphics Library

OpenGL is a device- and operating system-independent library for
three-dimensional graphics and graphics rendering. OpenGL was originally
developed by Silicon Graphics Inc. (SGI) for use on their high-end graphics

workstations. Since then, OpenGL has become a widely accepted standard with

implementations on many operating system and hardware platforms, including
the Windows NT and Windows 95 operating systems.

---------------------------------------------------------------------------

[Image]Note: OpenGL support under Windows 95 has just become available
recently. The Windows 95 version of the OpenGL development system and
redistributable run-time files are available as part of the October, 1995
or later release of the Microsoft Developer Library, level 2. There is no
support for OpenGL under Win32s.
---------------------------------------------------------------------------


In addition to the standard OpenGL Library implementation, Windows also
provides a series of functions that integrate OpenGL with the operating
system. In particular, functions are provided that associate OpenGL
rendering contexts with GDI device contexts. These Windows extensions to
the OpenGL Library are identified by names that begin with wgl. In addition

to these OpenGL extensions, a series of new Win32 API functions has also
been defined to facilitate certain aspects of OpenGL programming.

The OpenGL Library is large and complex. If you wish to have access to a
comprehensive set of manuals, you should consider purchasing The OpenGL
Reference Manual from the OpenGL Architecture Review Board, or The OpenGL
Programming Guide by Jackie Neider, Tom Davis, and Mason Woo. Both books
are published by Addison-Wesley.

In this chapter, in addition to presenting a brief (and far from
comprehensive!) overview of the OpenGL Library, I place the focus on using
OpenGL from Windows and MFC applications.

                              OpenGL Overview

The purpose of the OpenGL Library is to render two- and three-dimensional
objects into a frame buffer, such as the pixel memory of your computer's
graphics hardware.

The OpenGL Library is fundamentally procedural. What this means is that in
your application, you don't describe what an object looks like; instead,
you specify how an object is to be drawn. Complex geometric objects are
described in terms of simple elements that your application defines.

The OpenGL Library implementation follows the client-server model. OpenGL
clients and servers need not even reside on the same machine.

                           Basic OpenGL Concepts

At the basic level, the OpenGL Library deals with vertices. A vertex is a
point, for example the end point of a line, or a corner of a polygon.
Vertices can be two- or three-dimensional.

At the next level are primitives. Primitives consist of a group of one or
more vertices. For example, a rectangle described as a set of four vertices

is a primitive.

How vertices are assembled into primitives and how primitives are drawn
into a frame buffer are controlled by a variety of settings. For example,
applications can specify a three-dimensional transformation matrix that
defines how the coordinates of an object are translated into coordinates on

the drawing surface.

In addition to its ability to draw points and lines, OpenGL can also draw
surfaces, apply lighting specifications, and use texture bitmaps.

Another set of features enables applications to selectively use or discard
pixels. For example, drawing a pixel can be made conditional upon
properties such as the pixel's depth or its opacity.

A greatly simplified view of how OpenGL works is presented in Figure 41.1.

Figure 41.1. Simplified overview of OpenGL operations.

                              Initialization

Before the OpenGL Library can be used, a number of initialization steps
must be executed.

Every Windows OpenGL application must associate a rendering context with a
device context. The device context must be a display device context or a
memory device context that is compatible with the display device context.
To set up a rendering context, applications must first use the
SetPixelFormat Win32 function to set up a pixel format for the device;
next, they must call wglCreateContext with the device context handle as its

parameter. If successful, wglCreateContext returns a rendering context
handle of type HGLRC.

---------------------------------------------------------------------------

[Image]Note: Windows does not support drawing into a printer device context

using the OpenGL Library. If you wish to print an image created with
OpenGL, one possible workaround is to draw into a memory device context
that is compatible with the display device and then transfer the resulting
bitmap to the printer device.
---------------------------------------------------------------------------


OpenGL under Windows recognizes two types of pixel data modes: RGBA formats

and color index-based modes. When the RGBA mode is selected, pixel colors
are specified in the form of RGB color values. When color index mode is
selected, pixel colors are selected from the system palette using an index
value. These two modes become relevant on palette-based 256-color devices
(many VGA-compatible display cards). When your application uses the RGBA
mode on such a device, it must manage its own palette, and respond to
Windows palette notification messages.

There are specific requirements that must be met by a window that is to be
used for OpenGL operations. Specifically, such windows cannot be created
using a window class that has the CS_PARENTDC style set. The window itself
must have the WS_CLIPCHILDREN and the WS_CLIPSIBLINGS styles in order to be

compatible with OpenGL.

Note that to increase your application's performance, you may wish to use a

window class that has a null background brush; the window background will
be erased through the OpenGL Library anyway.

Before a rendering context can be used, it must be set up as the current
context using the wglMakeCurrent function. This function takes two
parameters, one of which is a device-context handle. Interestingly, this
handle does not need to be identical to the handle used in
wglCreateContext梑ut it must refer to the same device). Thus it is
possible, for example, to set up an OpenGL rendering context using a
device-context handle returned by GetDC, but use wglMakeCurrent with a
device-context handle returned by BeginPaint.

Once a rendering context is ready to accept commands, you may wish to send
additional initialization commands; for example, you may wish to erase the
frame buffer before drawing, set up coordinate transformations, configure
light sources, or enable and disable other options.

One initialization step that cannot be omitted is the call to the
glViewport function. Through this function, you can set up or modify the
size of the rendering viewport. Typically, you should call this function
once when the rendering context is initialized, and subsequently every time

your application receives a WM_SIZE message indicating that its window size

has changed.

--
※ 来源:.BBS 荔园晨风站 bbs.szu.edu.cn.[FROM: 192.168.1.3]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店