Results 1 to 3 of 3

Thread: glutSwapBuffers seems not working

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2013

    Unhappy glutSwapBuffers seems not working

    Hello everyone, I met with a strangle problem in a demo program to lean double buffering of OpenGL. I specified GLUT_DOUBLE in glutInitDisplayMode and called glutSwapBuffers at the end of display callback. But the result is exactly the same without GLUT_DOUBLE and glutSwapBuffers, so what is wrong with my codes, could anyone help me out of this?

    Here is the code, spinning a square continuously on the screen:

    Code :
    #include <stdio.h>
    #include <GLUT/GLUT.h>
    #include <math.h>
    float theta = 0;
    void display ();
    void idle ();
    void mouse (int button, int state, int x, int y);
    int main (int argc, char** argv)
        glutInit (&argc, argv);
        glutInitDisplayMode (GLUT_DOUBLE |GLUT_RGB);
        glutInitWindowPosition (100, 100);
        glutInitWindowSize (500, 500);
        glutCreateWindow ("Double Buffer Testing");
        glutDisplayFunc (display);
        glClearColor (1, 1, 1,1);
        glMatrixMode (GL_PROJECTION);
        glLoadIdentity ();
        gluOrtho2D (-1, 1, -1, 1);
        glMatrixMode (GL_MODELVIEW);
        return 0;
    void display ()
        glClear (GL_COLOR_BUFFER_BIT);
        glColor3f (1, 0, 0);
        glBegin (GL_POLYGON);
        float thetar = theta * (3.14159 / 180.0);
        glVertex2f (cosf (thetar), sinf (thetar));
        glVertex2f (-sinf (thetar), cosf(thetar));
        glVertex2f (-cosf (thetar), -sinf (thetar));
        glVertex2f (sinf (thetar), -cosf (thetar));
        glEnd ();
    void idle ()
        theta += 2;
        if (theta > 360) theta -= 360;
        glutPostRedisplay ();

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    The rendered result looks great to me. Nice, stable, and framelocked with double-buffering (GLUT_DOUBLE).

    Note however that with single-buffering (GLUT_SINGLE), sync-to-vblank doesn't happen by default (i.e. glXSwapBuffers called under-the-hood is a no-op in this case, as there are no buffers to swap). So to generate a somewhat comparable rendered result with single-buffering, put this after your glutSwapBuffers() call:

    Code cpp:

    Now change back and forth between GLUT_DOUBLE and GLUT_SINGLE and the results should be fairly comparable. Notice that with single-buffering you see tearing artifacts, but not so with double-buffering (assuming you've got sync-to-vblank enabled).

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2013
    thanks for reply, I found the reason leading GL_DOUBLE didn't work, the v-sync is disabled.

Similar Threads

  1. Not using glutSwapBuffers
    By programmer17 in forum OpenGL: User Software
    Replies: 8
    Last Post: 01-17-2012, 07:25 PM
  2. glutSwapBuffers can't be debugged
    By jacques in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-28-2009, 08:42 AM
  3. glutSwapBuffers
    By rixed in forum OpenGL: General
    Replies: 1
    Last Post: 01-15-2003, 09:58 PM
  4. glutSwapBuffers
    By rixed in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 01-15-2003, 12:22 PM
  5. Vsync and glutSwapBuffers() and glSwapBuffers
    By hades in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 10-21-2000, 06:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean