Please help me for the Display Lists

I am the beginner for OpenGL. I want to using the display list to switch two images on the screen with 60Hz with Vsync on.
I first generate two lists for each image.


glNewList(index, GL_COMPILE);
    glDrawPixels(GLwidth, GLheight, GL_BGR_EXT, GL_UNSIGNED_BYTE, image2.data);
glEndList();

glNewList(index + 1, GL_COMPILE);
    glDrawPixels(GLwidth, GLheight, GL_BGR_EXT, GL_UNSIGNED_BYTE, image.data);
glEndList();

lists[0] = 0; lists[1] = 2;
glListBase(index);       

Then in the display function, I use following code


if (flag == 0)
{
        glCallList(index);
        flag = 1;
}
    else
{
        glCallList(index + 1);
        flag = 0;
}
glutSwapBuffers();
glutPostRedisplay();

But after I run it, the screen dose not update. But sometimes, if I move the frame, it start to update. But it stops after several seconds. Dose anyone know what’s wrong with my code?

Have you checked for GL errors (link)?

If you find one, identify which GL call is triggering it. That will give you clues.

Does your code work properly if you inline the code DrawPixels calls instead of calling the display list?

Also, what do you hope that using display lists here will do for you?