OpenGL workflow translation from the Blue Book

Source: Internet
Author: User
Document directory
  • OpenGL Workflow
Through the above introduction, the OpenGL workflow has a general impression on OpenGL. The following describes how to use OpenGL functions in three stages of processing data in OpenGL and in these stages. Figure 1 Figure 1 detailed the diagram of the OpenGL processing pipeline (pipe line. There are three vertical wide arrows on the left of the graph. arrows represent two types of raw data related to geometric vertices: color values and texture coordinates. It can be seen that the three stages of the processing process, the geometric vertices are combined into elements (primitives), and then the elements are merged into fragments ), the final element is converted to the pixel data (pixels) in the frame cache ). This process is described in detail in the following sections. Figure OpenGL workflow (OpenGL Blue Book) 15.5.1 Geometric Vertex This section describes the OpenGL functions related to pre-vertex processing (Per-vertex) in the flowchart. After this processing, the geometric vertex can enter the OpenGL processing process. 1) the input data must provide the following vertices for the OpenGL assembly line: the geometric vertex describes the shape of the geometric object. Specify the geometric vertex to use the glvertex * () function and place it between glbegin () and glend (). You can create a vertex, line, or polygon. You can use glrect * () to describe an entire rectangle. Edge flag-by default, the edges of all polygon are boundaries. You can use gledgeflag * () to specify the boundary. Current raster location-use glrasterpos * () to specify the grid coordinates for pixel and bitmap painting operations. The current normal-the normal vector of the geometric vertex determines the point of a point on a certain surface in the 3D space, thus affecting the light receiving of the point. Use glnormal * () to define a normal vector. Current color-the color of the vertex, coupled with the set lighting conditions, ultimately determines the light color. Glcolor * () is used for RGB colors, and glindex * () is used for Color Indexing *(). Current texture coordinate-defined by gltexcoord * (). The texture coordinate associates a special position of the texture image with the geometric vertex. When glverex * () is called, the calculated geometric vertex inherits the current boundary mark, normal, color, and texture coordinates. Therefore, once these attributes are defined, gledgeflag * (), glnormal * (), glcolor * (), and gltexcoord * () are called before glvertex. 2) Before generating an image in the frame buffer, the geometric vertices and normal vectors must undergo matrix transformation through the modelview matrix and projection matrix. You need to use functions such as glmatrixmode (), glmultmatrix (), glrotate (), gltranslate (), and glscale () to get the desired transformation. You can use glloadmatrix () and glloadidentity () to specify the unit matrix. Use glpushmatrix () and glpopmatrix () to save and retrieve the model matrix and projection matrix from their respective stacks. 3) In addition to defining colors and normal vectors, you can also use gllight * () and gllightmodel * () to set the desired lighting conditions and use glmaterial *() set the expected material attributes. Use glshademodel (), glfrontface (), and glcolormaterial () to control illumination calculation. 4) In addition to precisely setting texture coordinates, you can also use gltexgen * () to automatically generate texture coordinates of geometric vertices. After texture coordinate settings or automatic generation, texture matrix transformation is required. The operation of texture matrix is the same as that of other matrix transformations above. 5) once these calculations are completed, the geometric vertices are combined into elements (points, line segments, or polygon) and contain the related boundary marks, normal, color, and texture coordinates of the geometric vertices. 15.5.2 Elements In the next processing phase, the elements are converted into pixels in several steps: the elements are properly cropped and the color and texture data are adjusted accordingly, the related coordinates are converted to window coordinates. Finally, raster converts the cropped elements into pixel elements. 1) when cropping, the line segment and polygon are slightly different. For a vertex, either the original state is retained (inside the cropping body) or the vertex is cut (outside the cropping body ). For line segments and polygon, if the part is outside the cropping body, a new geometric vertex needs to be generated at the cropping point. For a polygon, you also need to add the complete edge between the newly added vertices. The boundary mark, normal, color, and texture coordinate information must be assigned to the newly added geometric points, regardless of the line segment or polygon. Two steps during the cropping process: application a specifies the cropping (application-specific clipping). Once the elements are combined, if the program uses the glclipplane () function to define any cropping surface, to crop. View volume clipping. Then, the elements are projected by the projection matrix (entering the cropping Coordinate System) and cropped by the corresponding visual bodies. The projection matrix can be defined by glfrustum () or glortho (). The operation of the projection matrix is the same as that of other matrix transformations. 2) Before converting to the window coordinate, crop the coordinates by dividing them by the W value of the normalized device coordinate (normalized device coordinates. Then, the canonicalized data is converted to the viewport to generate the window coordinates. You can use gldepthrange () and glviewport () to control the image size and determine the area of the image displayed on the screen. 3) grating is a process of converting an element into a two-dimensional image. Each point in a two-dimensional image contains color, depth, and texture data. Call this vertex and related information a fragment ). In this phase, the current raster location (defined by glrasterpos * () is required for object element rendering and bitmap operations ). As discussed above, the raster methods for the three elements are different. In addition, pixel blocks and bitmaps also need raster. A) elements use the glpointsize (), gllinewidth (), gllinestipple (), and glpolygonstipple () functions to select the raster dimension and mode of the elements. In addition, you can use glcullface (), glfrontface (), and glpolygonmode () to control the grating effects on the front and back of a polygon. B) There are several functions for Pixel storage and conversion. The glpixelstore * () function is used to store pixels in the memory. GLpixeltransfer * () and glpixelmap * () are used to process pixels before they are written into the frame buffer. Gldrawpixels () defines a pixel rectangle. Use GLpixelzoom () enables pixel scaling. C) bitmap is a rectangle of 0 and 1 with a specific bitmap pattern. Each element has the same related data. It can be defined by glbitmap. D) Texture storage texture maps a specified part of the texture image to each element. The texture coordinate attribute of each fragment. The coordinate corresponds to the coordinate of the texture image, and the color value of the position of the texture image is obtained to modify the rgba color of the fragment, to complete the ing process. Use glteximage2d () or glteximage1d () to define a texture image. Gltexparameter * () and gltexenv * () control how the texture is interpreted and applied to a piece. E) The image elements that have been raked by fog have the color modified by texture textures. The fusion factor can be used to combine the fog color. The size of the fusion factor is determined based on the distance between the viewpoint and fragment. Use glfog * () to specify the atomization color and fusion factor. 15.5.3 Slice OpenGL allows Rasterization to generate a piece of element. As long as the element passes a series of detection, the corresponding pixel in the frame buffer can be modified. If it passes the test, the piece metadata can directly replace the existing value in the frame buffer or merge with the existing value, depending on the set mode. 1) pixel ownership (ownership) detection the first test is to determine whether a pixel corresponding to a pixel in the frame buffer belongs to the current OpenGL context. If yes, the slice element performs the next test. If not, the window system determines whether to ignore the element or whether to perform the next operation. 2) The glscissor () function is used for cropping detection. You can define a rectangle for any screen calibration. The elements outside the rectangle are ignored. 3) Alpha testing can only be performed in rgba mode. If the Alpha value of the element exceeds a fixed reference value, the element will be ignored. This comparison function can use glalphafunc () implement and set reference values. 4) The template checks that when the value of the template buffer exceeds a reference value, the template test ignores the element with conditions. This comparison function and fixed value can be implemented using glstencilfunc. The values in the template buffer are modified based on the glstencilop () function, whether the elements pass or fail the template test. 5) when the depth buffer value fails to be compared with the reference value, the depth test ignores the element. Gldepthfuc () is used to execute this comparison command. If the template is enabled, the results of deep comparison will affect the update of the template buffer value. 6) The fusion combines the R, G, B, And A values of a piece and the values stored in the corresponding position of the frame buffer. Fusion can only be implemented in rgba mode. Its implementation requires the Alpha value of the element and the corresponding storage pixel, and the RGB value. With glbendfun () control, you can modify the source and target of the fusion factor. 7) if the jitter starts, the color or color index of the chip uses the jitter algorithm. This algorithm only requires the color value of the Element and Its X and Y coordinates. 8) at the end of the logical operation, a logical operation is performed between the values of the slice and the frame buffer. The result will replace the value of the current frame buffer. Use gllogicop to define the desired logical operation. This logical operation can only run in color index mode, but not in rgba mode. 15.5.4 Pixel In the last phase of the OpenGL assembly line, the element is converted into pixels in the frame buffer. The frame buffer is actually a set of logical buffers-including the color buffer, the depth buffer, the template buffer, and the accumulation buffer. Color buffers include left, right, left, right, and right, and some auxiliary cache values (Auxiliary buffers ). It can be directly read from or copied. For different OpenGL contexts, These buffers may be incomplete. 1) frame buffer operations use gldrawbuffer to select a color buffer for the drawing. In addition, after the pre-partitioning (Per-fragment) operation, you can use four different functions to keep the operations written to these logical buffers, glindexmask (), glcolormask (), gldepthmask (), and glstencilmask (). Glaccum () is used to operate the cumulative buffer. Finally, glclearcolor (), glclearindex (), glcleardepth (), glclearstenric (), and glclearaccum (). specify the corresponding color value, color index value, depth value, template value, and cumulative value for different buffers. 2) read and copy pixels use glreadpixel () to read pixels from the frame buffer to the memory, perform various operations, and save the processing results. In addition, you can use glcopypixel () to copy a pixel from the frame buffer to another frame mixed storage. Glreadbuffer () can read and copy pixels in the color buffer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.