在OpenGL中如何将原语渲染为线框?


当前回答

你可以这样使用供过于求的库:

对于球面: glutWireSphere(半径20 20); 圆柱体: GLUquadric *quadratic = gluNewQuadric(); GLU_LINE gluQuadricDrawStyle(二次); gluCylinder(二次,1,1,1,12日1); 对于立方体: glutWireCube (1.5);

其他回答

从http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/ogladv/tut5

// Turn on wireframe mode
glPolygonMode(GL_FRONT, GL_LINE);
glPolygonMode(GL_BACK, GL_LINE);

// Draw the box
DrawBox();

// Turn off wireframe mode
glPolygonMode(GL_FRONT, GL_FILL);
glPolygonMode(GL_BACK, GL_FILL);
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );

要打开电源,

glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

回归正常。

注意,如果启用了纹理映射和照明,它们仍然会应用到线框线上,这看起来可能很奇怪。

你可以这样使用供过于求的库:

对于球面: glutWireSphere(半径20 20); 圆柱体: GLUquadric *quadratic = gluNewQuadric(); GLU_LINE gluQuadricDrawStyle(二次); gluCylinder(二次,1,1,1,12日1); 对于立方体: glutWireCube (1.5);

如果您正在使用固定的管道(OpenGL < 3.3)或兼容性配置文件,您可以使用

//Turn on wireframe mode
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

//Draw the scene with polygons as lines (wireframe)
renderScene();

//Turn off wireframe mode
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

在这种情况下,你可以通过调用glLineWidth来改变行宽

否则,你需要在你的绘制方法(glDrawElements, glDrawArrays等)中改变多边形模式,你可能会得到一些粗略的结果,因为你的顶点数据是三角形的,你是输出线。为了获得最好的效果,可以考虑使用几何着色器或为线框创建新数据。

最简单的方法是将原语绘制为GL_LINE_STRIP。

glBegin(GL_LINE_STRIP);
/* Draw vertices here */
glEnd();