开发者

Polygon in OpenGL

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(in开发者_如何学运维t 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:

Polygon in OpenGL


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜