Wednesday, May 4, 2011

OpenGL SwapBuffers() example Windows.

SwapBuffers(hdc) function is used to switch front and back buffer of OpenGL surface.
So, it effectively requires double-buffering. In OpenGL, your drawing is not updated to screen until you call SwapBuffers(hdc) function.

void    DrawIt()
{
    // Drawing OpenGL Geometry.
    //
    glClear(GL_COLOR_BUFFER_BIT);

    //glPushMatrix();

    glScalef(0.5f, 0.5f, 0.5f);
    glBegin(GL_TRIANGLES);
        glColor3f(1.0f, 0.0f, 0.0f);
        glVertex3f(-1.0f, -1.0f, -1.0f);
        glColor3f(0.0f, 1.0f, 0.0f);
        glVertex3f(1.0f, -1.0f, -1.0f);
        glColor3f(0.0f, 0.0f, 1.0f);
        glVertex3f(0.0f, 1.0f, -1.0f);
    glEnd();

    //glPopMatrix();

    SwapBuffers(g_hDC);

    return;
}