使用glutBitmapCharacter()屏幕闪烁?

时间:2019-12-11 13:59:30

标签: c++ opengl glut

我正在尝试使用OpenGL制作游戏。我的游戏运行良好,但我想显示分数。我设法使用glutBitmapCharacter来显示它,但屏幕开始flickering

void drawBitmapText(char *string) 
{  
char *c;
glWindowPos3f(10,1000,0);

for (c=string; *c != '\0'; c++) 
{
    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *c);

}
//glutPostRedisplay();

}

void AffichageScore(int scoreAafficher){ 
    glClear(GL_COLOR_BUFFER_BIT); 

    std::string scoreSTR = std::to_string(scoreAafficher);
    scoreSTR = "Score : "+scoreSTR;
    int len = scoreSTR.length();
    char scoreArray[len+1];
    std::strcpy(scoreArray, scoreSTR.c_str()); 

    drawBitmapText(scoreArray);
    //glutSwapBuffers();

    //glutPostRedisplay();

}


static void end(){

}



static void timer_callback(int)
{
move_trees();
move_floor();
score += 1;
printf("Score : %d \n",score);  




//demande de rappel de cette fonction dans 25ms
glutTimerFunc(25, timer_callback, 0);

//vérifie la présence de collisions toutes les 25ms
bool verif_col=collisions();
if (verif_col==true){
    int scoreFinal = score;
    fin = true;        
    //AffichageScore(scoreFinal);

    }


glutPostRedisplay();


//reactualisation de l'affichage
glutSwapBuffers();
}

1 个答案:

答案 0 :(得分:0)

“我不认为您每次想重画分数时都应该调用glClear。它应该在每个渲染过程中都进行一次”。

这解决了问题。