struct Vertex{ GLfloat position[2]; GLfloat color[3]; }; ... std::vectorpoints; std::vector index;
v.position[0] = 0; v.position[1] = 0; v.color[0] = 0; v.color[0] = 0; v.color[0] = 0; points.push_back(v); theta = 0; for(i=0;i<num;i++) { v.position[0] = 0.9 * cos(theta); v.position[1] = 0.9 * sin(theta); theta += dTheta ; v.color[0] = rand()/float(RAND_MAX); v.color[1] = rand()/float(RAND_MAX); v.color[2] = rand()/float(RAND_MAX); points.push_back(v); index.push_back(0); index.push_back(ushort(points.size()-1)); } }
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferIDs[0]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, index.size()*sizeof(int), index.data(), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, bufferIDs[1]); glBufferData(GL_ARRAY_BUFFER, points.size()*sizeof(Vertex), points.data(), GL_STATIC_DRAW);
void Lines::Display() { if (display) { glEnable(GL_LINE_SMOOTH); glUniform1f(tsLoc, timeStep); glBindVertexArray(VAONumber); glDrawElements(GL_LINES, index.size(), GL_UNSIGNED_SHORT, NULL); glBindVertexArray(0); glDisable(GL_LINE_SMOOTH); } return; }