2
我必須有一個使用兩個視口的OpenGL程序。在其中之一,我必須有一架直升機的模型,帶有一臺工作相機,可以在每個方向旋轉。在我決定讓視口分割之前,我讓相機在模型上工作,因爲它具有更高的優先級。另一個視口應該顯示FPS計數器,但由於某種原因,我只能從特定角度看到文本。OpenGL中的多個視口和文本...也許它是相機?
我的代碼如下:
//sets up the viewports
void setView(int option)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
switch (option)
{
case 1:
glViewport(0,height-150,width,150);
break;
case 2:
glViewport(0,0,width,height-150);
break;
}
if(persp)
gluPerspective(fovy, (GLfloat) width /(GLfloat) height , near, far);
else
glOrtho(left,right,bottom,top,-10,10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
myCam.updateLook();
}
void writeBitmapString(void *font, char *string)
{
char *c;
for (c = string; *c != '\0'; c++) glutBitmapCharacter(font, *c);
}
//main draw function
void display(void)
{
//Text portion of the window
setView(1);
glColor3f(1.0, 0.0, 0.0);
glRasterPos3f(0, 0, 0.0);
writeBitmapString((void*)font, "Test text");
glutSwapBuffers();
//Viewport for heli
setView(2);
glEnable(GL_DEPTH_TEST);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
//....The rest is just the modelling stuff
glPopMatrix(); // final pop clause
glFlush();
glutSwapBuffers();
任何幫助將不勝感激。
myCam.updateLook()是做什麼的? – Aeluned 2013-03-10 02:12:18
它調用gluLookAt函數並設置指向斬波器中心的點。它還處理所有相機的新定位。相機的位置由IJKL鍵修改。 – Galipan 2013-03-10 14:48:03
@加利潘:你爲一個教程而倒下SNAFU的人傾向於一次又一次:在渲染功能之外設置投影和視口。將該代碼移動到繪圖代碼中,事情變得明顯起來。 – datenwolf 2013-03-10 18:40:41