I am able to render the below points using the VBO and shaders in OpenGL 4.x.
typedef struct Point
{
double x,y,z,w;
}Point;
std::vector<Point>vPoints;
glBufferData(GL_ARRAY_BUFFER, vPoints.size()* sizeof(Point), &vPoints[0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 4, GL_DOUBLE, GL_FALSE, vPoints.size()*sizeof(GLdouble), (GLvoid*)0)
How do we specify VBO to draw a line string using below variables
typedef struct LineString
{
vector<Point> vPointList;
}LineString;
vector<LineString> vLines;
glBufferData(GL_ARRAY_BUFFER, ????, ????, GL_STATIC_DRAW);
glVertexAttribPointer(0, 4, GL_DOUBLE, GL_FALSE, ????, (GLvoid*)0)
I tried below setting and it does not seem to work
glBufferData(GL_ARRAY_BUFFER, vLines.size()* sizeof(LineString)*sizeof(Point), &vLines[0].vPointList[0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 4, GL_DOUBLE, GL_FALSE, vLines.size()*sizeof(GLdouble), (GLvoid*)0);
I thought I almost got there with below code for VBO creation
for(int i=0;i< vLines.size();i++)
pt_count += vLines[i].vPointList.size();
fprintf( stdout, "Total point Count: %d\n", pt_count);
glBufferData(GL_ARRAY_BUFFER, pt_count * sizeof(Point), nullptr, GL_STATIC_DRAW);
size_t start = 0;
for(int i=0;i< vLines.size();i++)
{
size_t v_size =vLines[i].vPointList.size() * sizeof(Point);
glBufferSubData(GL_ARRAY_BUFFER, start, v_size, &vLines[i].vPointList[0]);
start += v_size;
}
if(start == pt_count * sizeof(Point) )
{
fprintf( stdout, "INFO: %s\n", "Same count");
}
glVertexAttribPointer(0, 4, GL_DOUBLE, GL_FALSE, 4 * sizeof(GLdouble), (GLvoid*)0);
and drawing call.I noticed that the last point of first line is getting connected to first point of the line.
glDrawArrays(GL_LINE_STRIP, 0,pt_count);