我有一个方法,我需要这个方法来显示病毒的行为在使用网络GLUT(这是一个使用图形库我的第一次)。更新窗口显示的OpenGL/GLUT C++
我显示的点数和连接它们的线。该程序运行良好,它完美地显示了网络的初始状态,但我无法设法在我调用方法模拟后找到更新显示的方法。
的点改变颜色取决于计算机的状态,所以我需要一种方法来更新显示(网络图)每3秒或类似的东西。有任何想法吗?
我已阅读有关使用glutPostRedisplay()
或以某种方式使用glutIdleFunc()
,但我不明白如何实现它。谢谢您的帮助。
这里是我的代码:(但是这只能说明初始状态)
void Visualizador::visualizar(int cItr, int ios, double vsc, int vcf, double rc, double grc) {
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1280,720);
glutCreateWindow("Network initial state");
glutDisplayFunc(display); //display creates a number of points (computers) and lines (connections)
glutIdleFunc(display);
glutMainLoop();
for (int i = 0; i < cItr; i++) { //cItr: Number of times the state of the network will be updated
ostringstream oss;
oss << "State #" << i+1 << " of the network";
string windowName = oss.str();
const char* cstr = windowName.c_str();
simulator.simulate(1, vsc, vcf, rc, grc); //this method can change which point is infected
glutDisplayFunc(display);
glutIdleFunc(display);
glutSetWindowTitle(cstr);
glutMainLoop();
}
}