render is wrong after 23 renders

I render using the following code, and for the first 23 times the buffer is all green. After 23 renders, only the bottom left 1/4 of the buffer is green and the rest is red. After 126 renders, the buffer is all red. Any ideas as to what may be causing this?

How do I put this into a code block?

wglMakeCurrent(this->deviceContext, this->renderContext);

glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

glColor3d(0.0, 1.0, 0.0);

glBegin(GL_QUADS);

//glColor3d(1.0, 0.0, 0.0);
glVertex2d(0.0, 0.0);

//glColor3d(0.0, 1.0, 0.0);
glVertex2d(1.0, 0.0);

//glColor3d(0.0, 0.0, 1.0);
glVertex2d(1.0, 1.0);

//glColor3d(1.0, 1.0, 0.0);
glVertex2d(0.0, 1.0);

glEnd();

glFlush();

SwapBuffers(this->deviceContext);

wglMakeCurrent(NULL, NULL);

PAINTSTRUCT paintStruct;
BeginPaint(this->hwnd, &paintStruct);
EndPaint(this->hwnd, &paintStruct);

Sorry I missed this,

    wglMakeCurrent(this->deviceContext, this->renderContext);
    
    glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
    
    glColor3d(0.0, 1.0, 0.0);
    
    glBegin(GL_QUADS);
    
    //glColor3d(1.0, 0.0, 0.0);
    glVertex2d(0.0, 0.0);
    
    //glColor3d(0.0, 1.0, 0.0);
    glVertex2d(1.0, 0.0);
    
    //glColor3d(0.0, 0.0, 1.0);
    glVertex2d(1.0, 1.0);
    
    //glColor3d(1.0, 1.0, 0.0);
    glVertex2d(0.0, 1.0);
    
    glEnd();
    
    glFlush();
    
    SwapBuffers(this->deviceContext);
    
    wglMakeCurrent(NULL, NULL);

    PAINTSTRUCT paintStruct;
    BeginPaint(this->hwnd, &paintStruct);
    EndPaint(this->hwnd, &paintStruct);

Hi,

You may need to call “glMatrixMode(GL_PROJECTION)” before “glOrtho” and revert to the modelview matrix (glMatrixMode(GL_MODELVIEW)) before drawing the quad.

Cheers