简体   繁体   English

如何将顶点添加到OpenGL C ++ triangle_fan

[英]How to add vertices to OpenGL C++ triangle_fan

I need to add correct lighting to an OpenGL irregular polygon that I filled using TRIANGLE_FAN. 我需要为使用TRIANGLE_FAN填充的OpenGL不规则多边形添加正确的照明。

glBegin(GL_TRIANGLE_FAN);

glNormal3f(0.0, 0.0, 1.0);
glVertex3f(0.0f, 0.0f,0.0f);
glVertex3f(b[0][0],b[0][1], 0);
glVertex3f(b[11][0], b[11][1], 0);
glVertex3f(b[7][0], b[7][1], 0);
glVertex3f(b[10][0], b[10][1], 0);
glVertex3f(b[6][0],b[6][1], 0);
glVertex3f(b[5][0],b[5][1], 0);
glVertex3f(b[4][0],b[4][1], 0);
glVertex3f(b[8][0],b[8][1], 0);
glVertex3f(b[3][0],b[3][1], 0);
glVertex3f(b[9][0],b[9][1], 0);
glVertex3f(b[2][0],b[2][1], 0);
glVertex3f(b[1][0],b[1][1], 0);
glVertex3f(b[0][0],b[0][1], 0);

glEnd();

The problem with my current polygon is that it does not reflect light correctly. 我当前的多边形存在的问题是它不能正确反射光。 It only does so from its vertices, which gives the light that hits it an X shape. 它仅从其顶点执行此操作,从而使撞击它的光成为X形。 I am guessing that I need to add vertices to my polygon. 我猜想我需要向多边形添加顶点。 Is there a simple way to keep my triangle fan but add vertices to it? 有一种简单的方法可以保持三角形扇形但向其添加顶点吗?

To get "correct" results when lighting your object, you need to define appropriate normals. 为了在照明对象时获得“正确”的结果,您需要定义适当的法线。 Since you only have one normal for every vertex, it obviously didn't shade correctly. 由于每个顶点只有一个法线,因此显然着色不正确。

However, there's no correct way to calculate normals for any model; 但是,没有正确的方法可以为任何模型计算法线。 you have to define how the object should be shaded, and then add more glNormal calls to inform OpenGL how you want it to be shaded. 你必须定义对象应如何着色,然后添加更多glNormal来电告知OpenGL的你怎么想它被遮蔽。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM