所以,我试图在每张图纸之间延迟这个程序。我尝试使用 Sleep(),但如果在 draw() 函数上使用它会给我一个错误,如果在其他地方使用,它不会产生任何效果。
Xcode 编译该文件,但在运行时指出此错误:
libsystem_kernel.dylib`__semwait_signal:
0x7fff8fd7937c: movl $33554766, %eax
0x7fff8fd79381: movq %rcx, %r10
0x7fff8fd79384: syscall
0x7fff8fd79386: jae 0x7fff8fd7938d ; __semwait_signal + 17
0x7fff8fd79388: jmpq 0x7fff8fd7a4c8 ; cerror
0x7fff8fd7938d: ret
0x7fff8fd7938e: nop
0x7fff8fd7938f: nop
代码:
void draw()
{
GLint width;
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(10);
int x=0; int y=0;
glBegin(GL_POINTS);
for(x=0; x<500; x++)
{
for(y=0;y<500; y++)
{
glColor3f(rand()%255,rand()%255, rand()%255);
glVertex2i(rand()%500,rand()%500);
}
}
sleep(500);
glEnd();
glFlush();
}
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Trabalho de Modelagem e Simulação de Processos");
glutDisplayFunc(draw);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
gluOrtho2D (0.0f, 500.0f, 0.0f, 500.0f);
glutIdleFunc(draw);
glutMainLoop();
return 1;
}