我正在渲染一个pointcloud,但是当我移动相机时,点开始闪烁(youtu.be/wMTVID7NATo)。
奇怪的是,当我改变清晰的颜色或点的颜色时,闪烁消失或减少。例如glClearColor(0,0,0,1)和glColor3f(0.5f,0.5f,0.5f)会导致闪烁,但是当我使用glClearColor(1,1,1,1)或glColor3f(1时,这种闪烁消失了) 1,1)。
造成这种闪烁的原因是什么?如何在不改变透明或点颜色的情况下摆脱它?
这是我的代码:
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(640, 480);
mainWindow = glutCreateWindow("MyWindow");
glutTimerFunc(1, timerRoutine, 0);
glutDisplayFunc(displayFunc);
glutMotionFunc(motionFunc);
glutMouseFunc(mouseFunc);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearDepth(10.0f);
}
void timerRoutine(int t) {
glutPostRedisplay();
glutTimerFunc(t, timerRoutine, 0);
}
void displayFunc() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_POINTS);
for (int i = 0; i < pointCount; ++i) {
glColor3f(points[i].getIntensity(), points[i].getIntensity(), points[i].getIntensity());
glVertex3f(points[i].getX(), points[i].getY(), points[i].getZ());
}
glEnd();
glutSwapBuffers();
}
void mouseFunc(int x, int y, int z, int w) {
if (x == 0) {
if (y == 0) { //LMB Down
leftMouseButton = true;
}
else if (y == 1) { //LMB Up
leftMouseButton = false;
}
}
}
void motionFunc(int x, int y) {
if (leftMouseButton ) {
camera.rotate(y, 0, x)); //Apply rotation to GL_MODELVIEW
}
}