OpenGL中的多视口

就是在OpenGL中实现多个视口,每个视口对应不同的用途。

我的代码:

//视口一 左下角 glEnable(GL_SCISSOR_TEST); glScissor(0,0,m_width/2-1,m_height/2-1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_SCISSOR_TEST); glViewport(0,0,m_width/2-1,m_height/2-1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)m_width/(GLfloat)m_height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //绘制部分 //视口二 左上角 glEnable(GL_SCISSOR_TEST); glScissor(0, m_height/2+1, m_width/2-1, m_height/2-1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_SCISSOR_TEST); glViewport(0, m_height/2+1, m_width/2-1, m_height/2-1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)m_width/(GLfloat)m_height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //绘制部分 //视口三 右下角 glEnable(GL_SCISSOR_TEST); glScissor(m_width/2+1, 0, m_width/2-1, m_height/2-1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_SCISSOR_TEST); glViewport(m_width/2+1, 0, m_width/2-1, m_height/2-1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)m_width/(GLfloat)m_height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //绘制部分 //视口四 右上角 glEnable(GL_SCISSOR_TEST); glScissor(m_width/2+1, m_height/2+1, m_width/2-1, m_height/2-1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_SCISSOR_TEST); glViewport(m_width/2+1, m_height/2+1, m_width/2-1, m_height/2-1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)m_width/(GLfloat)m_height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //绘制部分

 

 

效果:

 

 

OpenGL中的多视口_第1张图片

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(buffer)