sharpGL中的extension例子关键代码解读

  private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs e)
        {
            //  Get OpenGL.
            var gl = openGLControl1.OpenGL;
       
            //  Clear and load identity.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();
            
             // Use gluLookAt to look at torus.
            gl.LookAt(0.0f,10.0f,10.0f,
              0.0f, 0.0f, 0.0f,
              0.0f, 1.0f, 0.0f);

            //  Rotate torus.
            angle += .5f;
            gl.Rotate(angle, 0.0f, 1.0f, 0.0f);

            //  Push all attribute bits.
            gl.PushAttrib(OpenGL.GL_ALL_ATTRIB_BITS);

            //  Get the inverse model matrix
            gl.PushMatrix();
            gl.LoadIdentity();
            gl.Rotate(-angle, 0.0f, 1.0f, 0.0f);
            var inverseModelMatrix = gl.GetModelViewMatrix();
            gl.PopMatrix();

            //  Get the object space light vector.
            Vertex objectLightPosition = inverseModelMatrix * worldLightPosition;

            //  Loop through vertices
            for(int i=0; i<torus.NumVertices; ++i)
            {
                Vertex lightVector = objectLightPosition - torus.Vertices[i].position;

                //Calculate tangent space light vector
                torus.Vertices[i].tangentSpaceLight.X =
                    torus.Vertices[i].sTangent.ScalarProduct(lightVector);
                torus.Vertices[i].tangentSpaceLight.Y =
                    torus.Vertices[i].tTangent.ScalarProduct(lightVector);
                torus.Vertices[i].tangentSpaceLight.Z =
                    torus.Vertices[i].normal.ScalarProduct(lightVector);
            }

            //  Draw bump pass
            if(drawBumps)
            {
                //  Bind normal map to texture unit 0
                normalMap.Bind(gl);
                gl.Enable(OpenGL.GL_TEXTURE_2D);

                //  Bind normalisation cube map to texture unit 1
                
                //  Extensions: We can use the Extension format, such as below. However in this
                //  case we'll get a warning saying that this particular extension is deprecated
                //  in OpenGL 3.0. However...
                gl.ActiveTextureARB(OpenGL.GL_TEXTURE1_ARB);
                gl.BindTexture(OpenGL.GL_TEXTURE_CUBE_MAP_EXT, normalisationCubeMap);
                gl.Enable(OpenGL.GL_TEXTURE_CUBE_MAP_EXT);
                //  Extensions: ...it's deprecated because it's actually core functionality
                //  in OpenGL 3.0.
                gl.ActiveTexture(OpenGL.GL_TEXTURE0_ARB);

     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值