• 题目:三维随机分形地形生成(续十二)
  • 作者:佚名
  • 发表日期:十月 02, 2007
  • 浏览:96次
  • 收藏本文
  • 编者导读:6、纹理 bool renderTeximageMap () {  CWaitCursor hourglass;     int size = 1 << teximageIter;  UINT pmapDim, smallDim;  if (teximageFA && teximageFAdirty) {   freeFractArray (teximageFA);   teximageFA = NULL;  }  if (!teximageFA) {   teximageFA = alloc2DFractArray (size);   if (teximageFA==NUL
  • 6、纹理
    bool renderTeximageMap ()
    {
     CWaitCursor hourglass;
        int size = 1 << teximageIter;
     UINT pmapDim, smallDim;

     if (teximageFA && teximageFAdirty) {
      freeFractArray (teximageFA);
      teximageFA = NULL;
     }
     if (!teximageFA) {
      teximageFA = alloc2DFractArray (size);
      if (teximageFA==NULL) return (FALSE);
      fill2DFractArray (teximageFA, size, randomSeed,
       DEF_HEIGHT_SCALE, teximageH);
     }

     // Find the biggest power of two that will fit
     // in the current window. This is where we will 
     // draw the image.
     smallDim = (currentWidth > currentHeight) ?
      currentHeight : currentWidth;
     pmapDim = 1 << (UINT) (log ((float) smallDim) / log (2.));

     glPushAttrib (0xfffffff);

     // Only draw into biggest power of 2 square.
     glViewport (0, 0, pmapDim, pmapDim);
     glMatrixMode (GL_PROJECTION);
        glLoadIdentity ();
     glOrtho (-1.f, 1.f,
      -1.f, 1.f, 1., -1.);
     glMatrixMode (GL_MODELVIEW);
        glLoadIdentity ();
     // The array is rendered into the XZ plane. We need to
     // rotate by 90 degrees so we will be looking at it
     // "top down".
     glRotatef (90.f, 1.f, 0.f, 0.f);
     // Init lights now. Light position must be specified
     // after the rotate, or else it won''''''''''''''''''''''''''''''''t be rotated.
     initLights ();

     glDisable (GL_DEPTH_TEST);
     glDisable (GL_FOG);
     glEnable (GL_LIGHTING);
     glDisable (GL_BLEND);
        
     glClear (GL_COLOR_BUFFER_BIT);

     renderAsTriangles (teximageFA, size, 1, 0);
     glFlush ();

     glPopAttrib ();


     if (teximageFAdirty) {
      GLubyte *pmap;

      pmap = (GLubyte *) malloc (pmapDim*pmapDim*3);
      if (pmap==NULL) return (FALSE);

      glReadPixels (0, 0, pmapDim, pmapDim,
            GL_RGB, GL_UNSIGNED_BYTE, pmap);

      glNewList (TEXIMAGEMAP, GL_COMPILE);
      glTexImage2D (GL_TEXTURE_2D, 0, /* lod */
            3, /* num components */
            pmapDim, pmapDim, /* width, height */
            0, /* border */
            GL_RGB, GL_UNSIGNED_BYTE, /* format, type */
            pmap);

      glEndList ();

      free (pmap);
     }

     teximageFAdirty = FALSE;
     return (TRUE);
    }

  • 前一篇:题目:三维随机分形地形生成(续十...下一篇:题目:三维随机分形地形生成(续十...
  • 【引用地址】http://www.suanshu.net/list/5045.aspx
  • 【关键字】题目:三维随机分形地形生成(续十二)
版权申明:非特殊申明,本站文章均系转载自互联网,如果侵犯了你的合法权益,请告知我们,我们会第一时间处理. 要点评这篇文章,请在下面留言
针对这篇文章的评论
  • 评论载入中
    评论载入中...请稍后...

发表您的评论您的评论

用户名: 验证码: 说明:评论并不需要注册.如果您不是本站会员,你可以注册为本站会员. 注意:文章中的链接、内容等需要修改的错误,请用报告错误,以利文档及时修改。
  • 不良评论请用报告管理员,以利管理员及时删除。
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规。
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任。
  • 本站评论管理人员有权保留或删除其管辖评论中的任意内容。
  • 您在本站发表的作品,本站有权在网站内转载或引用。
  • 参与本评论即表明您已经阅读并接受上述条款。
  • 赞助商链接