• <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>

            Shuffy

            不斷的學習,不斷的思考,才能不斷的進步.Let's do better together!
            posts - 102, comments - 43, trackbacks - 0, articles - 19
            Blending and Transparency

            Blending in OpenGL provides pixel-level control of RGBA color storage in the color buffer. To enable blending we must first call glEnable(GL_BLEND). We have to set up the blending function glBlendFunc with two arguments: the source and the destination colors. By default these are GL_ONE and GL_ZERO respectively, which is equivalent to glDisable(GL_BLEND). The blend functions are applied to the source color set by glColor and destination color in the color buffer. The results of the blending functions are added together to generate the new color value which is put onscreen.

            Transparency is perhaps the most typical use of blending. In order to produce transparency we should set up the blending function as follows - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). This combination takes the source color, scales it based on the alpha component and then adds the destination pixel color scaled by 1 minus the alpha value. It basically takes a fraction of the current drawing color and overlays it on the pixel on the screen. The alpha component can be from 0 (completely transparent) to 1 (completely opaque).

            Anti-Aliasing

            You might have noticed in some of your OpenGL pictures that lines, especially nearly horizontal or nearly vertical ones, appear jagged. These jaggies appear because the ideal line is approximated by a series of pixels that must lie on the pixel grid. The jaggedness is called aliasing. Antialiasing can be enabled by calling the function - glEnable(GL_POLYGON_SMOOTH) for polygons.

            Fog

            An entire image can be made to appear more natural by adding fog, which makes objects fade into the distance. Fog is a general term that describes similar forms of atmospheric effects; it can be used to simulate haze, mist, smoke, or pollution. Fog is essential in visual-simulation applications, where limited visibility needs to be approximated.

            When fog is enabled, objects that are farther from the viewpoint begin to fade into the fog color. You can control the density of the fog, which determines the rate at which objects fade as the distance increases, as well as the fog's color. Since fog is applied after matrix transformations, lighting, and texturing are performed, it affects transformed, lit, and textured objects.

            Using fog is easy. Enable it by passing GL_FOG to glEnable(), and you choose the color and the equation that controls the density with glFog*().

            1,CCY457OpenGLView類中加入下列布爾變量,分別代表是否開啟混合,霧和反鋸齒效果。

            Code

            并在構造函數中對其初始化:

            CCY457OpenGLView::CCY457OpenGLView()
            {
                m_xRot 
            = 0.0f;
                m_yRot 
            = 0.0f;
                m_texWrap 
            = GL_CLAMP;
                m_texMode 
            = GL_DECAL;
                m_texFilter 
            = GL_NEAREST;
                m_blend 
            = FALSE;
                m_fog   
            = FALSE;
                m_antialias 
            = FALSE;
            }

            2,加入控制上述三種效果的菜單項及其事件處理函數

            void COpenGLView::OnEffectsBlending() 
            {
                
            // TODO: Add your command handler code here
                m_blend = !m_blend;
                
            if(m_blend)
                    glEnable(GL_BLEND);
                
            else
                    glDisable(GL_BLEND);
                InvalidateRect(NULL,FALSE);
            }
            void COpenGLView::OnUpdateEffectsBlending(CCmdUI* pCmdUI) 
            {
                
            // TODO: Add your command update UI handler code here
                pCmdUI->SetCheck(m_blend);
            }
            void COpenGLView::OnEffectsAntialiasing() 
            {
                
            // TODO: Add your command handler code here
                m_antialias = !m_antialias;
                
            if(m_antialias)
                    glEnable(GL_POLYGON_SMOOTH);
                
            else
                    glDisable(GL_POLYGON_SMOOTH);
                InvalidateRect(NULL,FALSE);
            }
            void COpenGLView::OnUpdateEffectsAntialiasing(CCmdUI* pCmdUI) 
            {
                
            // TODO: Add your command update UI handler code here
                pCmdUI->SetCheck(m_antialias);    
            }
            void COpenGLView::OnEffectsFog() 
            {
                
            // TODO: Add your command handler code here
                m_fog = !m_fog;
                
            if(m_fog)
                    glEnable(GL_FOG);
                
            else
                    glDisable(GL_FOG);
                InvalidateRect(NULL,FALSE);
            }
            void COpenGLView::OnUpdateEffectsFog(CCmdUI* pCmdUI) 
            {
                
            // TODO: Add your command update UI handler code here
                pCmdUI->SetCheck(m_fog);
            }

            3,在InitializeOpenGL函數中對霧效果進行設置。

            BOOL CCY457OpenGLView::InitializeOpenGL()
            {
                
            //Get a DC for the Client Area
                m_pDC = new CClientDC(this);
                
            //Failure to Get DC
                if(m_pDC == NULL)
                {
                    MessageBox(
            "Error Obtaining DC");
                    
            return FALSE;
                }
                
            //Failure to set the pixel format
                if(!SetupPixelFormat())
                {
                    
            return FALSE;
                }
                
            //Create Rendering Context
                m_hRC = ::wglCreateContext (m_pDC->GetSafeHdc ());
                
            //Failure to Create Rendering Context
                if(m_hRC == 0)
                {
                    MessageBox(
            "Error Creating RC");
                    
            return FALSE;
                }
                
            //Make the RC Current
                if(::wglMakeCurrent (m_pDC->GetSafeHdc (), m_hRC)==FALSE)
                {
                    MessageBox(
            "Error making RC Current");
                    
            return FALSE;
                }
                
            //Specify Black as the clear color
                ::glClearColor(0.0f,0.0f,0.0f,0.0f);
                
            //Specify the back of the buffer as clear depth
                ::glClearDepth(1.0f);
                
            //Enable Depth Testing
                ::glEnable(GL_DEPTH_TEST);
                ::glShadeModel(GL_SMOOTH);
                
            //設置霧
                ::glFogi(GL_FOG_MODE, GL_EXP);
                GLfloat fog_color[
            4= {0.2f,0.2f,0.2f,0.0f};
                ::glFogfv(GL_FOG_COLOR, fog_color);
                ::glFogf(GL_FOG_DENSITY, 
            0.25);
                
            //加載紋理
                LoadGLTextures();
                
            //設置燈光
                SetupLighting();
                ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                
            return TRUE;
            }

            作者:洞庭散人

            出處:http://phinecos.cnblogs.com/    

            本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。
            原文鏈接:http://www.cnblogs.com/phinecos/archive/2008/11/06/1327948.html
            人妻无码精品久久亚瑟影视| 国内精品伊人久久久久AV影院| 无码伊人66久久大杳蕉网站谷歌| 精品久久久中文字幕人妻| 午夜人妻久久久久久久久| 欧美一区二区三区久久综合| 狠狠色丁香久久婷婷综合五月| 久久亚洲国产精品一区二区| 欧美激情精品久久久久久久| 波多野结衣中文字幕久久| 国内精品久久久久久久影视麻豆| 97久久婷婷五月综合色d啪蜜芽 | 久久综合亚洲鲁鲁五月天| 伊人久久五月天| 久久国产V一级毛多内射| 久久精品视频一| 国产精品午夜久久| 99久久国产综合精品五月天喷水| 99久久777色| 久久午夜无码鲁丝片| 欧美国产成人久久精品| 久久久久亚洲AV无码专区体验| 欧美熟妇另类久久久久久不卡| 成人精品一区二区久久| 久久久久人妻精品一区二区三区 | 久久er国产精品免费观看2| 成人午夜精品无码区久久| 中文字幕一区二区三区久久网站| 亚洲va久久久噜噜噜久久狠狠| 久久AⅤ人妻少妇嫩草影院| 无码久久精品国产亚洲Av影片| 亚洲性久久久影院| 亚洲国产精品久久久久婷婷老年 | 久久99精品国产麻豆婷婷| 亚洲欧洲日产国码无码久久99| 久久久一本精品99久久精品88| 久久久久亚洲AV成人网人人网站 | 亚洲伊人久久成综合人影院 | 久久99久国产麻精品66| 久久精品国产乱子伦| 久久只这里是精品66|