OpenGL 中的多边形
有人可以向我解释一下为什么下面的代码没有绘制任何东西,但是如果我使用 GL_LINE_LOOP 它确实会形成一个闭环?
glBegin(GL_POLYGON);
for(int i = 0; i <= Ncircle; i++) {
tempAngle = angle + i*(2*M_PI - 2*angle)/Ncircle;
glVertex3f(r*cos(tempAngle), r*sin(tempAngle), 0.0);
}
glVertex3f(l, 0, 0.0);
//glVertex3f(r*cos(angle), r*sin(angle), 0.0);
glEnd();
(这基本上是一个半径为 r 和 θ 为 [-angle,angle] 的圆,上面有一个高度为 l 的三角形,这样离开圆的角度就是三角形的角度:
Can someone please explain to me why the following code doesn't draw anything, but If I use GL_LINE_LOOP it does make a closed loop?
glBegin(GL_POLYGON);
for(int i = 0; i <= Ncircle; i++) {
tempAngle = angle + i*(2*M_PI - 2*angle)/Ncircle;
glVertex3f(r*cos(tempAngle), r*sin(tempAngle), 0.0);
}
glVertex3f(l, 0, 0.0);
//glVertex3f(r*cos(angle), r*sin(angle), 0.0);
glEnd();
(This is basically a circle of radius r and Θ in [-angle,angle] with a triangle of height l on it such that the angle of leaving the circle is the triangle's angle:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
多边形不可见,因为多边形背面可见,并且默认情况下不渲染背面(它被剔除)。
多边形面由投影顶点的屏幕位置确定:如果顶点是逆时针方向,则正面可见,否则背面可见。
要控制多边形面剔除,请参阅 glCullFace。
我建议保留默认的面剔除预设,并以逆时针顺序发出多边形顶点。当相同的几何体显示两个面(正面和背面,即罐子)时,应禁用背面剔除
The polygon is not visible because the polygon back face is visible, and the back face is not rendered by default (it is culled).
The polygon face is determined by the screen position of the projected vertices: if the vertices are counter-clockwise the front face is visible, otherwise the back face is visible.
To control polygon face culling, see glCullFace.
I suggest to leave the default face culling preset, and issue polygon vertices in a counter-clockwise order. Back face culling shall be disabled when the same geometry show both faces (front and back, i.e. A jar)