OpenGL中使用glutDisplayFunc(myDisplay),myDisplay里面的代码不显示
使用了OpenGL自带的glut库来做窗口,使用了
glutMouseFunc(myMouse);
glutDisplayFunc(myDisplay);
glutReshapeFunc(myReshape);
myMouse函数
myMouse
1 void myMouse(int button,int state,int x,int y)
2 {
3 if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
4 {
5 if(count<3)
6 {
7 drawDot(x,screenHeight-y);
8 pt[count].x = x;
9 pt[count].y = screenHeight - y;
10 count++;
11 glFlush();
12 }
13 else
14 {
15 count = 0;
16 drawDot(x,screenHeight-y);
17 pt[count].x = x;
18 pt[count].y = screenHeight - y;
19 count++;
20 glFlush();
21 }
22 }
23 else if (button ==GLUT_LEFT_BUTTON && state == GLUT_UP)
24 {
25 if (count==3)
26 {
27
28 glFlush();
29 }
30
31 }
32 }
其中的drawdot是画点函数。此时glut窗口上会绘制出点,但如果把这里的drawdot去掉,加在myDisplay函数中,却不绘制点,奇怪!必须刷新下,才绘制点。
pt[3], count都是全局静态变量。
myDisplay函数
myDisplay
1 void myDisplay(void)
2 {
3 glClear(GL_COLOR_BUFFER_BIT);
4
5 if (count!=0)
6 {
7 for (int i=0;i<count;i++)
8 {
9 drawDot(pt[i].x,pt[i].y);
10 }
11 }
12
13 glFlush();
14 }
myMouse
浙公网安备 33010602011771号