Пример #1
0
        /// <summary>
        /// Render
        /// </summary>
        public override void Render()
        {
            // reset the model view matrix.
            m_ModelViewMatrix = Matrix4.Identity;

            // apply a rotation to the model view.
            m_ModelViewMatrix = Matrix4.Mult(m_ModelViewMatrix, Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(angle)));

            // begin using the shader.
            m_Shader.Begin();

            // update the model and projection matrix
            m_Shader.UpdateProjectionMatrix(m_ProjectionMatrix);
            m_Shader.UpdateModelViewMatrix(m_ModelViewMatrix);

            // ensure vertex and color attrib arrays are enabled.
            GL.EnableVertexAttribArray(m_Shader.VertexAttribLocation);

            GL.BindBuffer(BufferTarget.ArrayBuffer, m_VertexBuffer);
            GL.VertexAttribPointer(m_Shader.VertexAttribLocation, 3, VertexAttribPointerType.Float, true, Vector3.SizeInBytes, 0);

            // now the texture coordinates
            GL.EnableVertexAttribArray(m_Shader.TextureCoordAttribLocation);

            GL.BindBuffer(BufferTarget.ArrayBuffer, m_TexCoordBuffer);
            GL.VertexAttribPointer(m_Shader.TextureCoordAttribLocation, 2, VertexAttribPointerType.Float, true, Vector2.SizeInBytes, 0);

            // bind our texture into slot 0. Try changing this so the shader looks at texture slot 5. You will notice
            // that the texture goes black. To fix it we then set the ActiveTexture to 5 and bind our texture data into
            // it..
            m_Shader.SetTextureSlot(3);
            GL.ActiveTexture(TextureUnit.Texture3);
            GL.BindTexture(TextureTarget.Texture2D, m_Texture1);


            // draw a quad (made up of two triangles)
            GL.DrawArrays(BeginMode.TriangleStrip, 0, 4);

            // finished with the shader.
            m_Shader.End();

            // this will clear the texture data from the slot were are using. If we don't do this our texture
            // data will be left in the slot and could interfere with other drawing we are doing elsewhere.
            GL.BindTexture(TextureTarget.Texture2D, 0);

            // increment our rotation
            angle += 1;
            if (angle > 360)
            {
                angle = 0f;
            }
            ;
        }