當我調整窗口大小時,我不想縮放內容,但只是爲了增加視圖端口大小。我發現這一點,而在我的問題幾乎相同的stackoverflow(http://stackoverflow.com/questions/5894866/resize-viewport-crop-scene)上搜索。不過,我很困惑,什麼樣的縮放設置到何地,我嘗試了與1.0F但當時什麼也沒有顯示在所有:■如何在不縮放其內容的情況下調整opengl視口大小
這是目前調整功能代碼不結垢:
void GLRenderer::resize() {
RECT rect;
int width, height;
GLfloat aspect;
GetClientRect(hWnd, &rect);
width = rect.right;
height = rect.bottom;
if (height == 0) {
height = 1;
}
aspect = (GLfloat) width/height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, aspect, 0.1, 100.0);
glMatrixMode(GL_MODELVIEW);
}
而我的功能來呈現一個簡單的三角形:
void GLRenderer::render() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslated(0, 0, -20);
glBegin(GL_TRIANGLES);
glColor3d(1, 0, 0);
glVertex3d(0, 1, 0);
glVertex3d(1, -1, 0);
glVertex3d(-1, -1, 0);
glEnd();
SwapBuffers(hDC);
}
啊哈,我得到它的工作使用: 雙fovy =身高/ 45.0; gluPerspective(fovy,aspect,0.1,100.0); 謝謝你的幫助! :) – nevernew