SwapBuffers, when to use

I still don’t understand how SwapBuffer works with GLUT, should I use SwapBuffers every time I change the screen or every render and new thing? Is there a way more “automatic” or just using a renderer or game engine?

I take it you’re referring to glutSwapBuffers?

You should call it at the end of the display function (which is the only place rendering operations should be performed). With a double-buffered context, all rendering operations are performed on an off-screen buffer (the back buffer). The only way to make the rendering result appear on the screen is to use glutSwapBuffers to copy the back buffer to the front buffer. The contents of the back buffer will be undefined after this call.

1 Like

I’m undertanding better now, but what about this code that i finded o github searching for study? It’s call 2 times:

( https://github.com/VandanaBaidya/2D-Car-Racing-Game )

So, its not really needed?

(i erased some parts of the code to don’t make the reply too big)

void display()
    movd = movd - 16;
    if(movd < - 60)
        movd = 0;

    score = score + 1;
    drawText("Score:", 360,455);
    //itoa (score, buffer, 10);
    drawTextNum(buffer, 6, 420,455);
    for(q = 0; q<= 10000000; q++){;}
    if(collide == true)
        drawText("Game Over", 200,250);

You know when you see code like this that the person really is pretty much a n00b. I wouldn’t pay too much attention to it. It contains other errors as well.

1 Like

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.