OpenGL ES 正反面設定指令
太陽火神的美麗人生 (http://blog.csdn.net/opengl_es)
本文遵循“署名-非商業用途-保持一緻”創作公用協定
轉載請保留此句:太陽火神的美麗人生 - 本部落格專注于 靈活開發及移動和物聯裝置研究:iOS、Android、Html5、Arduino、pcDuino,否則,出自本部落格的文章拒絕轉載或再轉載,謝謝合作。
在OpenGL ES 中,僅有一種表面網格表示方式,那就是三角形。
三角形的三個頂點,可以組幾個面?有答 1 的沒有?有!那就是還不懂OpenGL ES 的我。
事實上,一張紙是有正反面的,那麼一個三角形也應該有兩個面,那麼在空間中,如何區分呢?那就是正反面。
那具體哪個是正面,哪個是反面呢,據說是預設逆時針是正面,順時針是反面,不過到現在還沒搞清楚,這個順和逆是個怎麼看法,我們隻知道在兩個軸組成的二維平面坐标系中的順和逆。
有知道的朋友不妨給予指出,謝謝。
不過,從下面的官方資料中,不難看出,應該是空間三角形的頂點向視窗坐标系做投影,得到的投影點,在一個二維坐标系中,就可以按二維坐标系中的順逆來考慮了。
先前,我一直考慮可能有個三維的知識點沒有掌握,現在看來,還是要轉成二維的來考慮。
在研究三維的過程中,很多問題都要結合着二維來考慮,就比較順暢了。
上面說了,系統預設是逆時針是正面,那麼順時針就是反面了,如果想對調一下呢,那就得用下面的指令了 glFrontFace 。
Name
glFrontFace — 定義多邊形的正面和背面 define front- and back-facing polygons
C Specification
| GLenum mode ; |
Parameters
- 指定多邊形正面的方向。可授受
和GL_CW
GL_CCW 兩個參數。初始值是 GL_CCW。
- Specifies the orientation of front-facing polygons.
andGL_CW
are accepted. The initial value isGL_CCW
.GL_CCW
mode
描述 Description
在一個完全由不透明的封閉表面組成的場景中,多邊形的背面永遠也看不到。忽略這些不可見的多邊形對于提升圖檔的渲染速度有明顯的好處。要啟用或禁用多邊形背面消除特性,可調用 glEnable 和 glDisable 并帶參數 GL_CULL_FACE。
如果一個假想的對象沿着它的第一個頂點、第二個頂點......直到最後一個頂點這樣的路徑,最後傳回到第一個頂點,它圍繞多邊形本身按順時針方向移動的,那麼這個多邊形映射到視窗坐标系的投影可以說成具有順時針繞向。如果按同樣的路徑是以反時針方向繞多邊形自身移動的,那麼多邊形的繞向就說成是反時針繞向。glFrontFace指定多邊形在視窗坐标系中是順時針繞向或反時針繞向作為正面;GL_CW 選擇順時針多邊形作為正面。預設,反時針多邊形被當作正面。
In a scene composed entirely of opaque closed surfaces, back-facing polygons are never visible. Eliminating these invisible polygons has the obvious benefit of speeding up the rendering of the image. To enable and disable elimination of back-facing polygons, call glEnable and glDisable with argument
GL_CULL_FACE
.
The projection of a polygon to window coordinates is said to have clockwise winding if an imaginary object following the path from its first vertex, its second vertex, and so on, to its last vertex, and finally back to its first vertex, moves in a clockwise direction about the interior of the polygon. The polygon's winding is said to be counterclockwise if the imaginary object following the same path moves in a counterclockwise direction about the interior of the polygon.
glFrontFace
specifies whether polygons with clockwise winding in window coordinates, or counterclockwise winding in window coordinates, are taken to be front-facing. Passing
GL_CCW
to
mode
selects counterclockwise polygons as front-facing;
GL_CW
selects clockwise polygons as front-facing. By default, counterclockwise polygons are taken to be front-facing.
錯誤資訊 Errors
如果 mode 不是可接受的值,就會産生 GL_INVALID_ENUM 錯誤。
GL_INVALID_ENUM
is generated if
mode
is not an accepted value.
Associated Gets
glGet with argument
GL_FRONT_FACE
See Also
glCullFace
Copyright
Copyright © 1991-2006 Silicon Graphics, Inc. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.