I'm calculating a lot of vertices and then display them with quad strips for a 3D surface plot.
I had a strange behavior for some vertices, changing colors in unpredictable manner. I tried fixing it and by coincidence, I found that the problem is solved, when I put glPushMatrix() and glPopMatrix before and after. Does anyone know what the underlying problem could be? Should I generally use push/pop around by glBegin/glEnd?
Here my working code:
for (int i = 1; i < vec.size(); i++) {
glPushMatrix();
glBegin(GL_QUAD_STRIP);
for (int j = 0; j < vec[i].size(); j++) {
glNormal3dv(vertex_normal[i][j]);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, reflectance[i][j]);
glVertex3d(vec[i][j].x(), vec[i][j].y(),vec[i][j].z());
glNormal3dv(vertex_normal[i-1][j]);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, reflectance[i-1][j]);
glVertex3d(vec[i-1][j].x(), vec[i-1][j].y(), vec[i-1][j].z());
}
glEnd();
glPopMatrix();
}