当前位置:主页   - 电脑 - 程序设计 - C/C++
《基于MFC的OpenGL编程》Part 12 Creating and Using Display Lists
来源:网络   作者:   更新时间:2011-01-21
收藏此页】    【字号    】    【打印】    【关闭

  本文对第11篇文章进行修改,使用显示列表来存储渲染命令。

  显示列表

  OpenGL provides a facility to create a preprocessed set of OpenGL commands called a display list. Creating a display list is a straight forward process. We just have to delimit the display list code with glNewList and glEndList. The display list is named by an integer and this name is used to call the list to be executed later on. Display lists are very useful for scenes which have lot of geometry that don't change in from frame to frame. If we have to rerender something that doesn't change it is not worth going through all the calculations required once again - it is better to store them somewhere in memory and reuse it. This is exactly what the display list lets us achieve. Thus if we are going to repeatedly execute the same sequence of OpenGL commands we can create and store a display list and then have this cached sequence of calls repeated with minimal overhead, since all the vertices, lighting calculations, textures and matrix operations are calculated only when the list is created and not when it is replayed. Only the results of the calculations end up being stored in display lists. This means we cannot modify the list once we create it.

  1,CY457OpenGLView类中加入一个变量来保存显示列表名称

  GLuint m_sceneList;

  2,创建显示列表

void CCY457OpenGLView::CreateSceneList()
{//创建显示列表
  m_sceneList = glGenLists(1);
  glNewList(m_sceneList, GL_COMPILE);
    SetupLighting();
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,m_Texture[0]);
    //Front Face
    glBegin(GL_POLYGON);
      glTexCoord2f(0,0);
      glVertex3f(-1.0f,-1.0f,0.0f);
      glTexCoord2f(1,0);
      glVertex3f( 1.0f,-1.0f,0.0f);
      glTexCoord2f(1,1);
      glVertex3f( 1.0f, 1.0f,0.0f);
      glTexCoord2f(0,1);
      glVertex3f(-1.0f, 1.0f,0.0f);
    glEnd();
    //Back Face
    glBegin(GL_POLYGON);
      glTexCoord2f(1,0);
      glVertex3f(-1.0f,-1.0f,-1.0f);
      glTexCoord2f(1,1);
      glVertex3f(-1.0f, 1.0f,-1.0f);
      glTexCoord2f(0,1);
      glVertex3f( 1.0f, 1.0f,-1.0f);
      glTexCoord2f(0,0);
      glVertex3f( 1.0f,-1.0f,-1.0f);
    glEnd();
    glBindTexture(GL_TEXTURE_2D,m_Texture[1]);
    
    //Left Face
    glBegin(GL_POLYGON);
      glTexCoord2f(1,0);
      glVertex3f(-1.0f,-1.0f, 0.0f);
      glTexCoord2f(1,1);
      glVertex3f(-1.0f, 1.0f, 0.0f);
      glTexCoord2f(0,1);
      glVertex3f(-1.0f, 1.0f,-1.0f);
      glTexCoord2f(0,0);
      glVertex3f(-1.0f,-1.0f,-1.0f);
    glEnd();
    //Right Face
    glBegin(GL_POLYGON);
      glTexCoord2f(0,0);
      glVertex3f(1.0f,-1.0f, 0.0f);
      glTexCoord2f(1,0);
      glVertex3f(1.0f,-1.0f,-1.0f);
      glTexCoord2f(1,1);
      glVertex3f(1.0f, 1.0f,-1.0f);
      glTexCoord2f(0,1);
      glVertex3f(1.0f, 1.0f, 0.0f);
    glEnd();
    glBindTexture(GL_TEXTURE_2D,m_Texture[2]);
    //Top Face
    glBegin(GL_POLYGON);
      glTexCoord2f(0,0);
      glVertex3f(-1.0f, 1.0f, 0.0f);
      glTexCoord2f(0,1);
      glVertex3f( 1.0f, 1.0f, 0.0f);
      glTexCoord2f(1,1);
      glVertex3f( 1.0f, 1.0f, -1.0f);
      glTexCoord2f(1,0);
      glVertex3f(-1.0f, 1.0f, -1.0f);
    glEnd();
    //Botton Face
    glBegin(GL_POLYGON);
      glTexCoord2f(0,1);
      glVertex3f(-1.0f, -1.0f, 0.0f);
      glTexCoord2f(0,0);
      glVertex3f(-1.0f, -1.0f, -1.0f);
      glTexCoord2f(1,0);
      glVertex3f( 1.0f, -1.0f, -1.0f);
      glTexCoord2f(1,1);
      glVertex3f( 1.0f, -1.0f, 0.0f);
    glEnd();
    glDisable(GL_TEXTURE_2D);
  glEndList();
}

其它资源
来源声明

版权与免责声明
1、本站所发布的文章仅供技术交流参考,本站不主张将其做为决策的依据,浏览者可自愿选择采信与否,本站不对因采信这些信息所产生的任何问题负责。
2、本站部分文章来源于网络,其版权为原权利人所有。由于来源之故,有的文章未能获得作者姓名,署“未知”或“佚名”。对于这些文章,有知悉作者姓名的请告知本站,以便及时署名。如果作者要求删除,我们将予以删除。除此之外本站不再承担其它责任。
3、本站部分文章来源于本站原创,本站拥有所有权利。
4、如对本站发布的信息有异议,请联系我们,经本站确认后,将在三个工作日内做出修改或删除处理。
请参阅权责声明