幾個OpenGL函式(glRectf() 畫素重疊的處理方案)
glRectf(glfloat x1,glfloat y1,glfloat x2,glfloat y2):x1,y1指定矩形的一個頂點x2,y2指定矩形反方向的頂點。四個點嚴格等於下面的序列(x1,y1)(x2,y1)(x2,y2)(x1,y2)。如果第二個頂點在第一個頂點的上方和右側,那麼這個矩形將以逆時針旋轉方向構造
glRectf(const glfloat *v1,const glfloat *v2):v1一個指向矩形的一個頂點的指標,v2一個指向矩形的一個頂點的指標
畫素重疊的解決方案;
在渲染環境設定中加入以下兩條語句:
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 0.0f);
glPolygonOffset(factor, bias);offset的計算公式是factor * DZ + bias
http://www.opengl.org/sdk/docs/man/html/glPolygonOffset.xhtml
Name
glPolygonOffset — set the scale and units used to calculate depth values
C Specification
void glPolygonOffset( |
GLfloat factor, |
GLfloat units) ; |
Parameters
-
factor
-
Specifies a scale factor that is used to create a variable depth offset for each polygon. The initial value is 0.
-
units
-
Is multiplied by an implementation-specific value to create a constant depth offset. The initial value is 0.
Description
When GL_POLYGON_OFFSET_FILL
, GL_POLYGON_OFFSET_LINE
, or GL_POLYGON_OFFSET_POINT
is enabled, each fragment's depth value will be offset after it is interpolated from the depth values of the appropriate vertices. The value of the offset is factor×DZ+r×units, where DZ is a measurement of the change in depth relative to the screen area of the polygon, and r is the smallest value that is guaranteed to produce a resolvable offset for a given implementation. The offset is added before the depth test is performed and before the value is written into the depth buffer.
glPolygonOffset
is useful for rendering hidden-line images, for applying decals to surfaces, and for rendering solids with highlighted edges.
Associated Gets
glIsEnabled with argument GL_POLYGON_OFFSET_FILL
, GL_POLYGON_OFFSET_LINE
, or GL_POLYGON_OFFSET_POINT
.
glGet with argument GL_POLYGON_OFFSET_FACTOR
or GL_POLYGON_OFFSET_UNITS
.
See Also
glDepthFunc, glEnable, glGet, glIsEnabled
Copyright
Copyright © 1991-2006 Silicon Graphics, Inc. Copyright © 2010-2013 Khronos Group. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.