Assuming you have already created a texture, bound it and enabled GL_TEXTURE...
glBegin(GL_QUADS);
{
glTexCoord2f(0.0f, 0.0f);
glVertex2f(-aspectRatio * 0.5f, 0.5f);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(-aspectRatio * 0.5f, -0.5f);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(aspectRatio * 0.5f, -0.5f);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(aspectRatio * 0.5f, 0.5f);
}
glEnd();
Notice that our x-coordinates are all half of the aspect ratio and the y-coordinates are half of one. Every time you resize your window you need to then snap your texture to the top and bottom with some space on the sides or to the left and right with some space on the sides. This is assuming that your window aspect ratio is not the same as your texture aspect ratio. If they are the same, then all is well and there will be no space on either side. So, what magic will get you the right aspect ratio on every resize without the texture spilling out of bounds? Here it is:
// get the window aspect ratio
float windowAspectRatio = this->width() / (float) this->height();
float halfWindowAspectRatio = windowAspectRatio * 0.5f;
// aspectRatio is the aspect ratio of your frame or texture
float halfAspectRatio = aspectRatio * 0.5f;
float left, right, top, bottom;
if (aspectRatio < windowAspectRatio) {
// top and bottom should be flush with window
top = 0.5f; // remember this is the top of the texture
left = -halfWindowAspectRatio;
} else {
// left and right should be flush with window
left = -halfAspectRatio;
// we are keeping top relative to the windowAspectRatio (normalizing here)
top = halfAspectRatio / windowAspectRatio;
}
right = -left;
bottom = -top;
There it is. Notice that the two cases rely on the fact that the aspect ratio of the texture is either less than or greater than the aspect ratio of the window. There it is though, in all its glory. Once you have that you just need to set those values into your glFrustum call and you're done.