当我创建 2 个或更多 TestLine 类实例并将其添加到渲染类中时,仅渲染最后一个。先前的对象不会渲染或消失
测试线类:
void update(){
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_VERTEX_ARRAY, xbo);
glVertexPointer(2, GL_FLOAT, 0, 0);
glDrawArrays(GL_LINES, 0, verts.size());
glDisableClientState(GL_VERTEX_ARRAY);
}
void set(float x, float y, float x2, float y2){
verts.push_back(x);
verts.push_back(y);
verts.push_back(x2);
verts.push_back(y2);
glGenBuffers(1, &xbo);
glBindBuffer(GL_ARRAY_BUFFER, xbo);
glBufferData(GL_ARRAY_BUFFER, verts.size() * sizeof(GLfloat), &verts[0], GL_STATIC_DRAW);
}
渲染类中的函数
void draw(){
int size = lines.size();
for(int i = 0; i < size; i++)
lines[i]->update();
}
void add(TestLine* d){
lines.push_back(d);
}