OpenGL的glViewPort窗口设置函数实现分屏

之前实现过全景图片查看(OpenGL的几何变换3之内观察全景图),那么我们需要进行分屏该如何实现呢?如下图:

OpenGL的glViewPort窗口设置函数实现分屏

没错就是以前提过的glViewPort函数,废话不多说了,我直接上代码:

 //从这里开始进行所有的绘制
void drawCube(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //清除屏幕和深度缓存
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //重置当前的模型观察矩阵 glPushMatrix();
{
gluLookAt(, , -, , , , , , );
glTranslatef(0.0f, 0.0f, -5.0f); //移入屏幕 5 个单位
glRotatef(xangle_Textures, 1.0f, 0.0f, 0.0f); //绕X轴旋转
glRotatef(yangle_Textures, 0.0f, 1.0f, 0.0f); //绕Y轴旋转
glRotatef(zangle_Textures, 0.0f, 0.0f, 1.0f); //绕Z轴旋转
for (int i = ; i < ; i++) {
glViewport(i * w_Textures, , w_Textures, h_Textures);
glBindTexture(GL_TEXTURE_2D, texturesArr[]); //选择纹理
glBegin(GL_QUADS); {
//前面:纹理顺时针,立方体逆时针
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); //纹理和四边形的左下
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); //纹理和四边形的左上
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); //纹理和四边形的右上
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); //纹理和四边形的右下
}glEnd(); glBindTexture(GL_TEXTURE_2D, texturesArr[]); //选择纹理
glBegin(GL_QUADS); {
//后面:纹理顺时针,立方体逆时针
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); //纹理和四边形的左下
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); //纹理和四边形的左上
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); //纹理和四边形的右上
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); //纹理和四边形的右下
}glEnd(); glBindTexture(GL_TEXTURE_2D, texturesArr[]); //选择纹理
glBegin(GL_QUADS); {
//顶面:纹理顺时针,立方体逆时针
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); //纹理和四边形的左下
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); //纹理和四边形的左上
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); //纹理和四边形的右上
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); //纹理和四边形的右下
}glEnd(); glBindTexture(GL_TEXTURE_2D, texturesArr[]); //选择纹理
glBegin(GL_QUADS); {
//底面:纹理顺时针,立方体逆时针
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); //纹理和四边形的左下
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, 1.0f); //纹理和四边形的左上
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); //纹理和四边形的右上
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); //纹理和四边形的右下
}glEnd(); glBindTexture(GL_TEXTURE_2D, texturesArr[]); //选择纹理
glBegin(GL_QUADS); {
//右面:纹理顺时针,立方体逆时针
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); //纹理和四边形的左下
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); //纹理和四边形的左上
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); //纹理和四边形的右上
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); //纹理和四边形的右下
}glEnd(); glBindTexture(GL_TEXTURE_2D, texturesArr[]); //选择纹理
glBegin(GL_QUADS); {
//左面:纹理顺时针,立方体逆时针 glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); //纹理和四边形的左下
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); //纹理和四边形的左上
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); //纹理和四边形的右上
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); //纹理和四边形的右下
}glEnd();
}
}glPopMatrix();
glFlush();
}
上一篇:ubuntu新建用户并允许SSH登录


下一篇:[转载]HTML5浏览器测试网站汇总