opengl中有一个重启图元的函数:
glEnable(GL_PRIMITIVE_RESTART)
glPrimitiveRestartIndex(GLuint index)
//实例中定义为0xffff
当绘制大量相同类型的图元时,例如GL_TRIANGLE_STRIP,GL_LINE_STRIP等等,使用glDrawElement函数时,有些点是链接不上的,需要重新开始一个新的点然后继续绘图,因此就需要这个重启
图源,就是在索引或者顶点数组中没一部分绘图结束后再数组中加入特定值0xffff,然后继续画就会把下一个点当作起始点
#include "glut.h"
#include <QDebug>
#define BUFFER_OFFSET(offset) ((GLvoid*)nullptr+offset)
#define XStart -0.8
#define XEnd 0.8
#define YStart -0.8
#define YEnd 0.8
#define NumXPoints 11
#define NumYPoints 11
#define NumPoints (NumXPoints*NumYPoints)
#define NumPointsPerStrip (2*NumXPoints)
#define NumStrips (NumYPoints-1)
#define RestartIndex 0xffff
GLfloat *vertices;
GLushort *indices;
void Init()
{
GLuint vbo,ebo;