在OpenGL中如何将原语渲染为线框?
当前回答
最简单的方法是将原语绘制为GL_LINE_STRIP。
glBegin(GL_LINE_STRIP);
/* Draw vertices here */
glEnd();
其他回答
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(OpenGL 3.2及更高版本)中,你可以使用几何着色器:
#version 330
layout (triangles) in;
layout (line_strip /*for lines, use "points" for points*/, max_vertices=3) out;
in vec2 texcoords_pass[]; //Texcoords from Vertex Shader
in vec3 normals_pass[]; //Normals from Vertex Shader
out vec3 normals; //Normals for Fragment Shader
out vec2 texcoords; //Texcoords for Fragment Shader
void main(void)
{
int i;
for (i = 0; i < gl_in.length(); i++)
{
texcoords=texcoords_pass[i]; //Pass through
normals=normals_pass[i]; //Pass through
gl_Position = gl_in[i].gl_Position; //Pass through
EmitVertex();
}
EndPrimitive();
}
通知:
对于点,改变布局(line_strip, max_vertices=3);到布局(points, max_vertices=3); 阅读更多关于几何着色器
从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);
在非抗锯齿渲染目标上绘制抗锯齿线的一个好而简单的方法是绘制宽度为4像素的矩形,纹理为1x4, alpha通道值为{0,1,1,0。},并使用mip-mapping关闭的线性过滤。这将使线条2像素厚,但你可以改变不同厚度的纹理。 这比重力计算更快更简单。