EDIT
I am editing the answer to respond to your comment. The algorithm would look like this:
Color *buffer = Color char [w * h];
// create a texture that you can map onto the quad stretched over the area
// of the window. You will need to create a quad rendered in the space of the
// window, aka you in 2D not 3D.
...
// now render your image using you ray-tracer
for (j = 0; j < h; ++h) {
for (i =0; i < w; ++i) {
buffer[j * w + i] = trace(orig, dir, ...);
}
// it is not very efficient to update your window each time you have
// a new pixel so do this every row or every 10 rows ... you get the idea
// copy content of your buffer into the GL texture
// I am not using the right calls here, too lazy to find the right ones
glCopyTexture(myGLTextureId, buffer, (sizeof(char) * 3 * w * h);
// do the texture binding, etc... all GL or DX stuff
...
// this will update your window with the content of the buffer
glSwapBuffer();
}
// now save content of buffer to image file
saveToDisk(buffer);
Windows? Arg(. You will have to use DirectX calls indeed but they 2 APIs are very close.