开发者

How do I fill the screen with a rectangle in OpenGL ortho mode?

I ha开发者_如何学编程ve 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?


This may have some relevance.

Tiling texture bmp file as texture onto a rectangle in OpenGL?

You may wish to consider ARB extension texture rectangle as an alternative approach to (assuming glTexImage2D?) http://glprogramming.com/red/chapter09.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜