2010-12-21 38 views
1

我有一個需要填充屏幕的640x480紋理。到目前爲止,我可以使它具有方形紋理,但不是矩形紋理。如何使用OpenGL正交模式的矩形填充屏幕?

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(); 

我需要做些什麼修改才能使它適合屏幕上的任何紋理,而不管它的長寬比如何?

回答

0

這可能有一些相關性。

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

您不妨考慮ARB擴展質感矩形作爲一種替代方法(假設glTexImage2D?)http://glprogramming.com/red/chapter09.html

+0

如果我理解正確的一切(和我很可能不這樣做,因爲這是我第一次我只需要紋理矩形擴展,如果我的卡片不支持非冪次冪紋理。我已經能夠創建紋理並將其顯示在屏幕上,但是我的ortho安裝程序正在製作四方形。我認爲我的計算只是需要調整,但我不確定究竟需要做什麼。 – 2010-12-21 20:51:45