1

I have a single 640x480 texture that needs to fill the screen. So far, I can make it work with a square texture, but not a rectangular one.

glViewport(0, 0, display->w, display->h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

double aspectRatio = (double)display->w / (double)display->h;

if (display->w <= display->h)
    glOrtho(-1, 1, -1 / aspectRatio, 1 / aspectRatio, -1, 1);
else
    glOrtho(-1 * aspectRatio, 1 * aspectRatio, -1, 1, -1, 1);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

What modifications do I need to make so that it will fit any texture to the screen, regardless of its aspect ratio?

4

1 回答 1

0

这可能有一些相关性。

在OpenGL中将纹理bmp文件作为纹理平铺到矩形上?

您可能希望将 ARB 扩展纹理矩形视为(假设 glTexImage2D?)http://glprogramming.com/red/chapter09.html的替代方法

于 2010-12-21T15:48:28.783 回答