【问题标题】:Screen flickering using glutBitmapCharacter()?使用 glutBitmapCharacter() 屏幕闪烁?
【发布时间】:2019-12-11 13:59:30
【问题描述】:

我正在尝试使用 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();
}

【问题讨论】:

  • 我认为您不应该在每次想要重绘分数时调用 glClear。它应该在每个渲染过程中完成一次。
  • 非常感谢,问题解决了!

标签: c++ opengl glut


【解决方案1】:

“我认为你不应该在每次想要重绘分数时调用 glClear。它应该在每个渲染过程中完成一次”来自三。

这解决了问题。

【讨论】:

    猜你喜欢
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-06
    • 2015-11-05
    • 2014-11-29
    • 1970-01-01
    相关资源
    最近更新 更多