In OpenGL, how can I adjust for the window being resized?

You definitely don't want to make the size of your objects explicitly dependent on the window size.

As already suggested by genpfault, adjust your projection matrix whenever the window size changes.

Things to do on window resize:

  1. Adjust viewport

    glViewport(0, 0, width, height)
    
  2. Adjust scissor rectangle (only if you have GL_SCISSOR_TEST enabled)

    glScissor(0, 0, width, height)
    
  3. Adjust projection matrix

    In case of legacy (fixed function pipeline) OpenGL, you can do it the following ways:

    glFrustum(left * ratio, right * ratio, bottom, top, nearClip,farClip)
    

    or

    glOrtho(left * ratio, right * ratio, bottom, top, nearClip,farClip)
    

    or

    gluOrtho2D(left * ratio, right * ratio, bottom, top)
    

    (assuming that left, right, bottom and top are all equal and ratio=width/height)


You should setup some sort of window handler function that is called whenever your OpenGL window is resized. You need to take care of the case when aspectRatio > 1, and when aspectRatio <= 1 separately. Not doing so may result in geometry falling offscreen after a screen resize.

void windowResizeHandler(int windowWidth, int windowHeight){
    const float aspectRatio = ((float)windowWidth) / windowHeight;
    float xSpan = 1; // Feel free to change this to any xSpan you need.
    float ySpan = 1; // Feel free to change this to any ySpan you need.

    if (aspectRatio > 1){
        // Width > Height, so scale xSpan accordinly.
        xSpan *= aspectRatio;
    }
    else{
        // Height >= Width, so scale ySpan accordingly.
        ySpan = xSpan / aspectRatio;
    }

    glOrhto2D(-1*xSpan, xSpan, -1*ySpan, ySpan, -1, 1);

    // Use the entire window for rendering.
    glViewport(0, 0, windowWidth, windowHeight);
}

If you're using something like gluPerspective() just use the window width/height ratio:

gluPerspective(60, (double)width/(double)height, 1, 256);