2015-09-06 57 views
0

我對使用Opengl很有新意,並且難以用幾秒鐘的時間眨眼幾秒鐘。我已經設法弄清楚如何使用「箭頭鍵」輸入,但我沒有任何運氣可以搞清楚這一點。如何使點使用opengl閃爍?

我試過睡眠()函數,但是這個函數沒有用作動畫的替代品。我無法找到我應該如何修復我的glutidle()以使其工作。

在我window.cpp,

void Appwindow::buildObject(){ }, i have several   
_ptcoords.push_back(GsVec(-0.53 + xxx, 0.1 + yyy, 0.0)); 
_ptcolors.push_back(GsColor::yellow); 
//and 15 of this points or mores. 

我已經在網上閱讀,但並發現,我必須調整我的框架,這將被設置爲60 fps的大多數標準計算機。

+0

要回答你的問題 - 只是不要渲染他們在特定的幀,你會得到'閃爍'的效果。我不能更具體,因爲你提供了一些我不知道的自定義代碼,並沒有提到任何可以幫助我提供正確答案的庫。 – RippeR

回答

1

您應該使用glutTimerFunc()定期調用子例程。在這個子程序中你維護你的動畫參數,可以調用glutPostRedisplay()來調用你的主繪圖函數。

然後,在您的主要繪圖功能中,只需在您希望它們出現的時候繪製點。

int time; 
float speed = 0.1f; // 10 frames per second 

void animate(int value) { 
    glutTimerFunc(speed, animate, 0); 
    time++; 
    if (time >= 10) 
     time = 0;  // time is in tenths of a second 
    glutPostRedisplay(); 
} 

void display() { 
    if (time > 5) { 
     // draw your flashing points here 
    } 
    // draw anything that doesn't flash here 
} 

int main(void) {int argc, char *argv[]) { 

    // your glut init goes here 

    glutTimerFunc(1.0, animate, 0); 
    glutDisplayFunc(display); 
    glutTimerFunc(TIMERSECS, animate, 0); 
    glutPostRedisplay(); 

    glutMainLoop(); 
}