glutIdleFunc()

glutIdleFunc設定全局的回調函式,當沒有視窗事件到達時,GLUT程式功能可以執行後台處理任務或連續動畫。如果啟用,這個idle function會被不斷調用,直到有視窗事件發生。回調函式沒有參數。當前的視窗和選單在執行idle func之前不會改變。當程式依賴多視窗或選單時最好不要依賴於當前設定。

基本介紹

  • 中文名:glutIdleFunc()
  • 外文名:glutIdleFunc()
  • 用法:glutIdleFunc(*func)
  • 設定:全局的回調函式
  • :參數
用法:,說明:,英文,中文,程式示例:,

用法:

void glutIdleFunc(void (*func)(void));

說明:

英文

glutIdleFunc sets the global idle callback to be func so a GLUT program can perform background processing tasks or continuous animation when window system events are not being received. If enabled, the idle callback is continuously called when events are not being received. The callback routine has no parameters. Thecurrent windowandcurrent menuwill not be changed before the idle callback. Programs with multiple windows and/or menus should explicitly set thecurrent windowand/orcurrent menuand not rely on its current setting.
The amount of computation and rendering done in an idle callback should be minimized to avoid affecting the program's interactive response. In general, not more than a single frame of rendering should be done in an idle callback.
assing NULL to glutIdleFunc disables the generation of the idle callback.

中文

應儘量減少在空閒回調完成的計算和渲染的數額,以避免影響程式的互動回響。在一般情況下,不超過單幀的渲染工作應在一個空閒回調。
glutIdleFunc傳遞NULL(0)就可禁用其函式回調。
在glutIdleFunc(void (*func)(void))回調函式中指定一個函式,如果不存在其他尚未完成的事件(例如,當事件循環處於空閒的時候),就執行這個函式。這個回調函式接受一個函式指針作為它的唯一參數。如果向它傳遞NULL(0),就相當于禁用這個函式。

程式示例:

#include<GL/glut.h>#include<stdio.h>void display(void){    glClear(GL_COLOR_BUFFER_BIT);    glColor4f(0.2f,0.4f,0.6f,0.0f);    glRectf(-0.5f,-0.5f,0.5f,0.5f);    glFlush();}staticintday=0;            //day的變化:從0到365staticintspin=0;            //旋轉角度變化:從0到360void myIdle(void){    ++day;    if(day>=365)        day=0;    printf("%d\n",day);    glRotatef((spin++)%360,0,0,1);    glutPostRedisplay();}int main(intargc,char*argv[]){    glutInit(&argc,argv);    glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);    glutInitWindowPosition(100,100);    glutInitWindowSize(400,400);    glutCreateWindow("helloworld");    glutDisplayFunc(display);    glutIdleFunc(&myIdle);    glutMainLoop();    return0;}

相關詞條

熱門詞條

聯絡我們