Resizing window in OpenGL: Garbage Output
<p>I am using GLUT with the OpenGL on Mac OS X. When I resize my window by dragging the window edges, the window gets filled with garbage values. The code is attached below. The only way to remove garbage I've found is by calling glClear(), which of course, I do not want to do.</p>

<p>The question is that <strong>I do not want the garbage values</strong>. I cannot figure out why I get such values as well.</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

#ifdef __APPLE__
#include &lt;GLUT/glut.h&gt;
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#else
#include &lt;GL/glut.h&gt;
#endif

void myInit();
void display();
void reshape(int x, int y);
void keyboard(unsigned char c, int x, int y);
void mouse(int b, int s, int x, int y);


int width;
int height;

int main(int argc, char* argv[]) {

    glutInit(&amp;argc, argv);
    myInit();
    glutMainLoop();
    return 0;
}


void myInit(){
    glutInitDisplayMode(GLUT_MULTISAMPLE);
    glutInitWindowSize(500,500);
    glutInitWindowPosition(100,100);
    glutCreateWindow("Hello World!");

    glClearColor(0.2,0.2,0.2,1);
    glutDisplayFunc(display);

    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);

    glutReshapeFunc(reshape);
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();
    gluLookAt(0.0, 0.0, 0.5,\
        0.0,0.0,0.0,\
        0.0,1.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT);
}

void display(){
    printf ("))display\n");
    glFlush();
}

void keyboard(unsigned char c, int x, int y){
    if (c == 27 || c == 81 || c == 113) exit(0);
    else if (c == 67 || c == 99){
        printf("CLEAR!\n");
        glClear(GL_COLOR_BUFFER_BIT);
        glutPostRedisplay();
    }
}

void putDot(int x, int y){
    glBegin(GL_POINTS);
        glVertex3f(x,height-y,0);
    glEnd();
    glutPostRedisplay();
}

void mouse(int b, int s, int x, int y){
    if (b == GLUT_LEFT_BUTTON &amp;&amp; s == GLUT_DOWN){
        printf("MouseD\n");
        putDot(x,y);
    }
}

void reshape(int x, int y){
    printf ("))reshape\n");
    width = x;
    height = y;
    glViewport(0,0,width,height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0,width, 0,height, -10,10);
    glMatrixMode(GL_MODELVIEW);
    glutPostRedisplay();
}
</code></pre>

<p><strong>EDIT</strong>: I have a similar problem on Ubuntu 14.04. So the trouble must be my coding (of course!).</p>