2016-06-10 55 views
0

我想绘制一个图像背景的动画模型。 要正确绘制我的模型,我需要使用glMatrixMode,glLoadIdentity,gluPerspective等。但是,要在背景上绘制矩形,我需要更改所设置的所有模式和矩阵以正确地查看我的模型。绘制动画模型与背景 - 设置opengl矩阵模式和透视

我在下面发布我的代码。任何人都可以告诉我该怎么做才能同时正确地看到我的模型和背景?

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 
glLoadIdentity();    // Reset MV Matrix 

glBindTexture(GL_TEXTURE_2D, m_texture1); 
glBegin(GL_QUADS); 
glColor4f(1.0f, 1.0f, 1.0f, 1); 
glTexCoord2f(0, 1); 
glVertex3f(-1.0, -1.0, 0); 
glTexCoord2f(0, 0); 
glVertex3f(-1.0, 1.0, 0); 
glTexCoord2f(1, 0); 
glVertex3f(1.0, 1.0, 0); 
glTexCoord2f(1, 1); 
glVertex3f(1.0, -1.0, 0); 
glEnd(); 

const double aspectRatio = (float) getOpenGLViewWidth() 
     /getOpenGLViewHeight(), fieldOfView = 45.0; 

glMatrixMode (GL_PROJECTION); 
glLoadIdentity(); 
gluPerspective(fieldOfView, 
     aspectRatio, 
     1.0, 
     1000.0); 
glMatrixMode (GL_MODELVIEW);     // Select The Modelview Matrix 
glLoadIdentity(); 
glTranslatef(0.0f, -25.0f, -70.0f); // Move 40 Units And Into The Screen 

glViewport(0, 0, getOpenGLViewWidth(), getOpenGLViewHeight()); 

// glRotatef(90.0f, 1.0f, 0.0f, 0.0f); 
recursive_render(_scenes[0], _scenes[0]->mRootNode, 25); 

回答

0

如果图像的背景是一个静态的背景下,应填写整个视口,而不是与您的场景旋转,你应该使其分开使用正交矩阵。

我的遗产GL是有点生疏,但它应该是这样的:

  1. 设置正交投影矩阵(例如用glOrtho)
  2. 设置模型视图矩阵身份
  3. 渲染你的填充整个视口的静态背景
  4. 设置透视投影矩阵
  5. 为您的动画模型翻译并旋转您的模型(视图)矩阵
  6. 渲染你的模型

请注意,如果你想保存一些填充率,你可能想要翻转顺序并渲染背景。