When trying to draw the following quads in OpenGL using a vertex array (instead of using immediate mode rendering), I get the graphical glitch (line segment) shown in the picture, which can be found in the second link below. The line seems to extend upwards to infinity.
GLdouble vertices[] = {
// back
0.0, 0.0, 0.0,
si, 0.0, 0.0,
si, -si, 0.0,
0.0, -si, 0.0,
// front
0.0, 0.0, si,
0.0, -si, si,
si, -si, si,
si, 0.0, si,
// left
0.0, 0.0, 0.0,
0.0, -si, 0.0,
0.0, -si, si,
0.0, 0.0, si,
// right
si, 0.0, 0.0,
si, 0.0, si,
si, -si, si,
si, -si, 0.0,
// top
0.0, 0.0, 0.0,
0.0, 0.0, si,
si, 0.0, si,
si, 0.0, 0.0,
// bottom
0.0, -si, 0.0,
si, -si, 0.0,
si, -si, si,
0.0, -si, si,
};
Immediate drawing:
glBegin(GL_QUADS);
for (int i = 0; i < sizeof(vertices)/sizeof(*vertices)/3; i++)
glVertex3d(vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2]);
glEnd();
Drawing with vertex array:
glVertexPointer(3, GL_DOUBLE, 0, vertices);
glDrawArrays(GL_QUADS, 0, sizeof(vertices)/sizeof(*vertices));
Images:
Correct cube drawn in immediate mode
Glitchy cube drawn with vertex array
What am I doing wrong?