• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            逛奔的蝸牛

            我不聰明,但我會很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::

            The solution is to enable depth-buffering but make the depth buffer read-only while drawing the 

            translucent objects. First you draw all the opaque objects, with the depth buffer in normal operation. 

            Then, you preserve these depth values by making the depth buffer read-only. When the translucent 

            objects are drawn, their depth values are still compared to the values established by the opaque objects, 

            so they aren't drawn if they're behind the opaque ones. If they're closer to the viewpoint, however, they 

            don't eliminate the opaque objects, since the depth-buffer values can't change. Instead, they're blended 

            with the opaque objects. To control whether the depth buffer is writable, use glDepthMask(); if you 

            pass GL_FALSE as the argument, the buffer becomes read-only, whereas GL_TRUE restores the 

            normal, writable operation. 

            void GLWidget::paintGL() {

            glLoadIdentity();

            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            gluLookAt(0, 0, 8, 0, 0, 0, 0, 1, 0);

            glPushMatrix();

            {

            glColor3f(1.0, 0.0f, 0.0f);

            glTranslatef(0.0f, 0.0f, -1.0f);

            this->drawCube(1.0f, 1.0f, 1.0f, 0.1f);

            }

            glPopMatrix();

            glPushMatrix();

            {

            glColor3f(0.0, 0.0f, 1.0f);

            glTranslatef(0.60f, 0.0f, -0.5f);

            this->drawCube(1.0f, 1.0f, 1.0f, 0.1f);

            }

            glPopMatrix();

            glPushMatrix();

            {

            glEnable(GL_BLEND);

            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

            glDepthMask(GL_FALSE);

            glColor4f(0.0, 1.0f, 0.0f, 0.5f);

            glTranslatef(0.20f, 0.0f, 0.0f);

            this->drawCube(0.60f, 1.0f, 1.0f, 0.1f);

            glDepthMask(GL_TRUE);

            glDisable(GL_BLEND);

            }

            glPopMatrix();

            }

            void GLWidget::drawCube(GLfloat len, GLfloat xFactor, GLfloat yFactor,

            GLfloat zFactor) {

            GLfloat x = len * xFactor / 2;

            GLfloat y = len * yFactor / 2;

            GLfloat z = len * zFactor / 2;


            // GLfloat p0[3] = { -x, -y, -z };

            // GLfloat p1[3] = { x, -y, -z };

            // GLfloat p2[3] = { x, y, -z };

            // GLfloat p3[3] = { -x, y, -z };

            // GLfloat p4[3] = { -x, -y, z };

            // GLfloat p5[3] = { x, -y, z };

            // GLfloat p6[3] = { x, y, z };

            // GLfloat p7[3] = { -x, y, z };


            glBegin(GL_QUADS);

            {

            // Draw left surface.

            glNormal3f(-1.0f, 0.0f, 0.0f);

            glVertex3f(-x, y, -z);

            glVertex3f(-x, -y, -z);

            glVertex3f(-x, -y, z);

            glVertex3f(-x, y, z);


            // Draw front surface.

            glNormal3f(0.0f, 0.0f, 1.0f);

            glVertex3f(-x, -y, z);

            glVertex3f(x, -y, z);

            glVertex3f(x, y, z);

            glVertex3f(-x, y, z);


            // Draw right surface.

            glNormal3f(1.0f, 0.0f, 0.0f);

            glVertex3f(x, -y, z);

            glVertex3f(x, -y, -z);

            glVertex3f(x, y, -z);

            glVertex3f(x, y, z);


            // Draw back surface.

            glNormal3f(0.0f, 0.0f, -1.0f);

            glVertex3f(x, y, -z);

            glVertex3f(x, -y, -z);

            glVertex3f(-x, -y, -z);

            glVertex3f(-x, y, -z);


            // Draw top surface.

            glNormal3f(0.0f, 1.0f, 0.0f);

            glVertex3f(x, y, z);

            glVertex3f(x, y, -z);

            glVertex3f(-x, y, -z);

            glVertex3f(-x, y, z);


            // Draw bottom surface.

            glNormal3f(0.0f, -1.0f, 0.0f);

            glVertex3f(-x, -y, -z);

            glVertex3f(x, -y, -z);

            glVertex3f(x, -y, z);

            glVertex3f(-x, -y, z);

            }

            glEnd();


            // glBegin(GL_QUADS);

            // {

            // // Draw left surface.

            // glNormal3f(-1.0f, 0.0f, 0.0f);

            // glVertex3fv(p3);

            // glVertex3fv(p0);

            // glVertex3fv(p4);

            // glVertex3fv(p7);

            //

            // // Draw front surface.

            // glNormal3f(0.0f, 0.0f, 1.0f);

            // glVertex3fv(p4);

            // glVertex3fv(p5);

            // glVertex3fv(p6);

            // glVertex3fv(p7);

            //

            // // Draw right surface.

            // glNormal3f(1.0f, 0.0f, 0.0f);

            // glVertex3fv(p5);

            // glVertex3fv(p1);

            // glVertex3fv(p2);

            // glVertex3fv(p6);

            //

            // // Draw back surface.

            // glNormal3f(0.0f, 0.0f, -1.0f);

            // glVertex3fv(p2);

            // glVertex3fv(p1);

            // glVertex3fv(p0);

            // glVertex3fv(p3);

            //

            // // Draw top surface.

            // glNormal3f(0.0f, 1.0f, 0.0f);

            // glVertex3fv(p6);

            // glVertex3fv(p2);

            // glVertex3fv(p3);

            // glVertex3fv(p7);

            //

            // // Draw bottom surface.

            // glNormal3f(0.0f, -1.0f, 0.0f);

            // glVertex3fv(p0);

            // glVertex3fv(p1);

            // glVertex3fv(p5);

            // glVertex3fv(p4);

            // }

            // glEnd();

            }

             

             

            posted on 2008-09-25 05:15 逛奔的蝸牛 閱讀(1080) 評論(1)  編輯 收藏 引用 所屬分類: OpenGL

            評論

            # re: OpenGL: Blend 2009-06-01 21:37 暗金裝備
            先繪制全部的場景之后再繪制透明物體, 并且透明物體要按照相反的次序來繪制, 即先繪制最遠(yuǎn)的物體.  回復(fù)  更多評論
              

            国产巨作麻豆欧美亚洲综合久久 | 国产精品无码久久综合 | 国产毛片欧美毛片久久久| 奇米影视7777久久精品人人爽| 久久久久国产精品嫩草影院| 国产精品久久久久9999高清| 久久高清一级毛片| 欧美午夜精品久久久久免费视 | 一日本道伊人久久综合影| 97热久久免费频精品99| 国产女人aaa级久久久级| 色狠狠久久AV五月综合| 久久精品国产精品亜洲毛片 | 亚洲国产日韩欧美综合久久| 成人综合伊人五月婷久久| 欧美精品一区二区久久| 精品久久久久久久| 一本色道久久88—综合亚洲精品| 国产成人精品综合久久久| 麻豆亚洲AV永久无码精品久久| 欧美精品福利视频一区二区三区久久久精品| 亚洲国产精品成人久久| 中文字幕久久精品| 久久99精品国产麻豆婷婷| 久久精品国产亚洲网站| 久久精品亚洲一区二区三区浴池| 久久无码人妻精品一区二区三区| 国产精品久久久久久久久鸭| 色欲久久久天天天综合网| 亚洲午夜久久久| 日本高清无卡码一区二区久久| 日本道色综合久久影院| 国产一级持黄大片99久久| 久久久一本精品99久久精品66| 久久精品青青草原伊人| 久久精品国产亚洲αv忘忧草| 久久午夜夜伦鲁鲁片免费无码影视 | 9久久9久久精品| 久久亚洲综合色一区二区三区| 久久久婷婷五月亚洲97号色| 久久久久99精品成人片欧美|