0
A
回答
1
使用固定管道(< OpenGL的3.x的)周圍的網狀創建輪廓或剪影的一個直接的方法在下面給出:
- 禁用照明:glDisable(GL_LIGHTING)
- 選擇顏色爲輪廓:glColor(R,G,B)
- 打開正面剔除:glCullFace(GL_FRONT)
- 量表的目(球體)由一些小百分比:glScale(SX,SY,SZ)
- 像以前一樣渲染球體:glutSolidSphere
使用核心配置文件OpenGL 3.x或更高版本,您將執行完全相同的操作,但在頂點着色器中可以完成。
實現這一使用固定管道所需要的代碼很簡單,只要:
# Render silhouette around object
glPushMatrix()
glCullFace(GL_FRONT) # Front face culling makes us render only the inside of the sphere, which gives the illusion of a silhouette
glScale(1.04, 1.04, 1.04) # This makes the silhouette show up around the object
glDisable(GL_LIGHTING) # We only want a plain single colour silhouette
glColor(0., 1., 0.) # Silhouette colour
glutSolidSphere(2,20,20) # This can be any object, not limited to spheres (even non-convex objects)
glPopMatrix()
下面是一個簡單的例子PyOpenGL程序渲染球體的輪廓,在GLUT例如鹼發現在http://code.activestate.com/recipes/325391-open-a-glut-window-and-draw-a-sphere-using-pythono/:
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
import sys
name = 'ball_glut'
def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(400,400)
glutCreateWindow(name)
glClearColor(0.,0.,1.,1.)
glShadeModel(GL_SMOOTH)
glEnable(GL_CULL_FACE)
glEnable(GL_DEPTH_TEST)
glEnable(GL_LIGHTING)
lightZeroPosition = [10.,4.,10.,1.]
lightZeroColor = [1.0,1.0,1.0,1.0]
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition)
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor)
glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1)
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05)
glEnable(GL_LIGHT0)
glutDisplayFunc(display)
glMatrixMode(GL_PROJECTION)
gluPerspective(40.,1.,1.,40.)
glMatrixMode(GL_MODELVIEW)
gluLookAt(0,0,10,
0,0,0,
0,1,0)
glPushMatrix()
glutMainLoop()
return
def display():
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
# Render sphere normally
glPushMatrix()
color = [1.0,0.,0.,1.]
glMaterialfv(GL_FRONT,GL_DIFFUSE,color)
glCullFace(GL_BACK)
glEnable(GL_LIGHTING)
glutSolidSphere(2,20,20)
# Render silhouette around object
glPushMatrix()
glCullFace(GL_FRONT) # Front face culling makes us render only the inside of the sphere, which gives the illusion of a silhouette
glScale(1.04, 1.04, 1.04) # This makes the silhouette show up around the object
glDisable(GL_LIGHTING) # We only want a plain fixed colour silhouette
glColor(0., 1., 0.) # Silhouette colour
glutSolidSphere(2,20,20) # This can be any object, not limited to spheres (even non-convex objects)
glPopMatrix()
glPopMatrix()
glutSwapBuffers() # Display results.
return
if __name__ == '__main__': main()
相關問題
- 1. 輪廓形狀
- 2. 如何用預定義的七巧板形狀填充輪廓?
- 3. Java:製作多個形狀的輪廓
- 4. OpenCV-如何統一不同的輪廓,一個封閉輪廓
- 5. 使線跟隨形狀的輪廓
- 6. openCV檢測輪廓內的形狀
- 7. 使用NumPy填充形狀/輪廓
- 8. 連接形狀並追蹤其輪廓
- 9. Java - 繪製動態形狀輪廓
- 10. 如何從.NET中的點雲創建輪廓形狀
- 11. Java:如何獲取字符的形狀(不是輪廓)
- 12. 我該如何刪除box2d的身體形狀輪廓?
- 13. 如何創建一個註冊表格的圓形輪廓儀
- 14. 如何創建一個帶有輪廓邊框的矩形?
- 15. OpenCV的 - 找到或訪問形狀輪廓不是由BG包圍,只有一個輪廓分離
- 16. 繪製在drawRect中的兩個形狀的公共輪廓:ObjectiveC
- 17. opencv/javacv:如何迭代輪廓以進行形狀識別?
- 18. 如何使用JavaCV識別另一輪廓內的輪廓?
- 19. css中的梯形輪廓
- 20. 獲取一組矩形的輪廓
- 21. 如何用java畫一個錐形輪廓awt.Graphics2D
- 22. 如何建立一個分佈輪廓
- 23. 構造一個多邊形的輪廓(特別是三角形)
- 24. 輪廓與cartopy:ValueError:無效的變換:不支持球形輪廓
- 25. 右梯形輪廓形狀(具有透明度)
- 26. 用輪廓填充圓形
- 27. OpenGL繪製矩形輪廓
- 28. 空心菱形輪廓
- 29. 如何在Flex餅圖的特定楔形上繪製輪廓?
- 30. 如何動畫多邊形? (閱讀:動畫輪廓改變形狀)