在OpenGL中如何将原语渲染为线框?
当前回答
你可以这样使用供过于求的库:
对于球面: glutWireSphere(半径20 20); 圆柱体: GLUquadric *quadratic = gluNewQuadric(); GLU_LINE gluQuadricDrawStyle(二次); gluCylinder(二次,1,1,1,12日1); 对于立方体: glutWireCube (1.5);
其他回答
你可以这样使用供过于求的库:
对于球面: 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等)中改变多边形模式,你可能会得到一些粗略的结果,因为你的顶点数据是三角形的,你是输出线。为了获得最好的效果,可以考虑使用几何着色器或为线框创建新数据。
如果你处理的是OpenGL ES 2.0,你可以从中选择一个绘制模式常量
GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES,来画线,
GL_POINTS(如果您只需要绘制顶点),或者
GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN和gl_triangle来绘制填充三角形
作为你的第一个论点
glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices)
or
glDrawArrays(GLenum模式,GLint优先,GLsizei计数)调用。
最简单的方法是将原语绘制为GL_LINE_STRIP。
glBegin(GL_LINE_STRIP);
/* Draw vertices here */
glEnd();
从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);