简体   繁体   中英

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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