예제 #1
0
        private void SetGlContext()
        {
            GL.ClearDepth(1.0);
            GL.Clear(ClearBufferMask.DepthBufferBit);                   // Clear the Depth Buffer

            GL.PushAttrib(AttribMask.ViewportBit);
            RectangleDouble screenRect = this.TransformToScreenSpace(LocalBounds);

            GL.Viewport((int)screenRect.Left, (int)screenRect.Bottom, (int)screenRect.Width, (int)screenRect.Height);

            GL.ShadeModel(ShadingModel.Smooth);

            GL.FrontFace(FrontFaceDirection.Ccw);
            GL.CullFace(CullFaceMode.Back);

            GL.DepthFunc(DepthFunction.Lequal);

            GL.Disable(EnableCap.DepthTest);
            ClearToGradient();

#if DO_LIGHTING
            GL.Light(LightName.Light0, LightParameter.Ambient, ambientLight);

            GL.Light(LightName.Light0, LightParameter.Diffuse, diffuseLight0);
            GL.Light(LightName.Light0, LightParameter.Specular, specularLight0);

            GL.Light(LightName.Light0, LightParameter.Ambient, new float[] { 0, 0, 0, 0 });
            GL.Light(LightName.Light1, LightParameter.Diffuse, diffuseLight1);
            GL.Light(LightName.Light1, LightParameter.Specular, specularLight1);

            GL.ColorMaterial(MaterialFace.FrontAndBack, ColorMaterialParameter.AmbientAndDiffuse);

            GL.Enable(EnableCap.Light0);
            GL.Enable(EnableCap.Light1);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.Normalize);
            GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.ColorMaterial);

            Vector3 lightDirectionVector = new Vector3(lightDirection0[0], lightDirection0[1], lightDirection0[2]);
            lightDirectionVector.Normalize();
            lightDirection0[0] = (float)lightDirectionVector.x;
            lightDirection0[1] = (float)lightDirectionVector.y;
            lightDirection0[2] = (float)lightDirectionVector.z;
            GL.Light(LightName.Light0, LightParameter.Position, lightDirection0);
            GL.Light(LightName.Light1, LightParameter.Position, lightDirection1);
#endif

            // set the projection matrix
            GL.MatrixMode(MatrixMode.Projection);
            GL.PushMatrix();
            GL.LoadMatrix(ProjectionMatrix.GetAsDoubleArray());

            // set the modelview matrix
            GL.MatrixMode(MatrixMode.Modelview);
            GL.PushMatrix();
            GL.LoadMatrix(ModelviewMatrix.GetAsDoubleArray());
        }
 /// <summary>
 /// Converts ModelviewMatrix to a float[].
 /// </summary>
 /// <returns>A float[] containing all the values from the initial matrix.</returns>
 public float[] ToArray()
 {
     return(ModelviewMatrix.to_array());
 }