我尝试使用GL_TRIANGLE_STRIP原语常量绘制一个多边形(使用OpenGL库和C ++)作为一组连接的三角形。我写的代码就像
#include <GL/glut.h>
void init()
{
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,300.0,0.0,250.0);
}
void polygonDrawing()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
int point1[] = {30,80};
int point2[] = {80,40};
int point3[] = {120,40};
int point4[] = {165,80};
int point5[] = {120,120};
int point6[] = {80,120};
glBegin(GL_TRIANGLE_STRIP);
glVertex2iv(point1);
glVertex2iv(point2);
glVertex2iv(point6);
glVertex2iv(point3);
glVertex2iv(point5);
glVertex2iv(point4);
glEnd();
glFlush();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitWindowSize(300,300);
glutInitWindowPosition(150,100);
glutCreateWindow("An OpenGl window for a polygon");
init();
glutDisplayFunc(polygonDrawing);
glutMainLoop();
return 0;
}
我的问题是:代码正确显示多边形,但不显示其中的连接三角形。任何人都可以告诉我为什么会这样,以及如何克服它?